Support minimum display width for integer data types (#337)

* Support minimum display width for integers

* make fmt happy, updated docstrings
This commit is contained in:
Alex Vasilev 2021-08-29 14:13:10 +03:00 committed by GitHub
parent 9a5716d94b
commit 77d90d3b85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 36 deletions

View file

@ -16,6 +16,7 @@
#[macro_use]
mod test_utils;
use test_utils::*;
use sqlparser::ast::*;
@ -130,19 +131,19 @@ fn parse_create_table_auto_increment() {
assert_eq!(
vec![ColumnDef {
name: Ident::new("bar"),
data_type: DataType::Int,
data_type: DataType::Int(None),
collation: None,
options: vec![
ColumnOptionDef {
name: None,
option: ColumnOption::Unique { is_primary: true }
option: ColumnOption::Unique { is_primary: true },
},
ColumnOptionDef {
name: None,
option: ColumnOption::DialectSpecific(vec![Token::make_keyword(
"AUTO_INCREMENT"
)])
}
)]),
},
],
}],
columns
@ -161,11 +162,11 @@ fn parse_quote_identifiers() {
assert_eq!(
vec![ColumnDef {
name: Ident::with_quote('`', "BEGIN"),
data_type: DataType::Int,
data_type: DataType::Int(None),
collation: None,
options: vec![ColumnOptionDef {
name: None,
option: ColumnOption::Unique { is_primary: true }
option: ColumnOption::Unique { is_primary: true },
}],
}],
columns
@ -175,6 +176,46 @@ fn parse_quote_identifiers() {
}
}
#[test]
fn parse_create_table_with_minimum_display_width() {
let sql = "CREATE TABLE foo (bar_tinyint TINYINT(3), bar_smallint SMALLINT(5), bar_int INT(11), bar_bigint BIGINT(20))";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![
ColumnDef {
name: Ident::new("bar_tinyint"),
data_type: DataType::TinyInt(Some(3)),
collation: None,
options: vec![],
},
ColumnDef {
name: Ident::new("bar_smallint"),
data_type: DataType::SmallInt(Some(5)),
collation: None,
options: vec![],
},
ColumnDef {
name: Ident::new("bar_int"),
data_type: DataType::Int(Some(11)),
collation: None,
options: vec![],
},
ColumnDef {
name: Ident::new("bar_bigint"),
data_type: DataType::BigInt(Some(20)),
collation: None,
options: vec![],
}
],
columns
);
}
_ => unreachable!(),
}
}
fn mysql() -> TestedDialects {
TestedDialects {
dialects: vec![Box::new(MySqlDialect {})],