Skip to content

Commit b0613a4

Browse files
committed
add empty spans outside macros
1 parent 3605b4f commit b0613a4

File tree

6 files changed

+32
-38
lines changed

6 files changed

+32
-38
lines changed

tests/sqlparser_bigquery.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,25 +1968,19 @@ fn parse_big_query_declare() {
19681968
"DECLARE x INT64 DEFAULT 42",
19691969
vec![Ident::new("x")],
19701970
Some(DataType::Int64),
1971-
Some(DeclareAssignment::Default(Box::new(Expr::Value(
1972-
number("42").with_empty_span(),
1973-
)))),
1971+
Some(DeclareAssignment::Default(Box::new(Expr::Value(number("42").with_empty_span().with_empty_span())))),
19741972
),
19751973
(
19761974
"DECLARE x, y, z INT64 DEFAULT 42",
19771975
vec![Ident::new("x"), Ident::new("y"), Ident::new("z")],
19781976
Some(DataType::Int64),
1979-
Some(DeclareAssignment::Default(Box::new(Expr::Value(
1980-
number("42").with_empty_span(),
1981-
)))),
1977+
Some(DeclareAssignment::Default(Box::new(Expr::Value(number("42").with_empty_span().with_empty_span())))),
19821978
),
19831979
(
19841980
"DECLARE x DEFAULT 42",
19851981
vec![Ident::new("x")],
19861982
None,
1987-
Some(DeclareAssignment::Default(Box::new(Expr::Value(
1988-
number("42").with_empty_span(),
1989-
)))),
1983+
Some(DeclareAssignment::Default(Box::new(Expr::Value(number("42").with_empty_span().with_empty_span())))),
19901984
),
19911985
] {
19921986
match bigquery().verified_stmt(sql) {

tests/sqlparser_clickhouse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ fn parse_freeze_and_unfreeze_partition() {
13931393

13941394
let expected_partition = Partition::Expr(Expr::Value(Value::SingleQuotedString(
13951395
"2024-08-14".to_string(),
1396-
)));
1396+
).with_empty_span()));
13971397
match clickhouse_and_generic().verified_stmt(&sql) {
13981398
Statement::AlterTable { operations, .. } => {
13991399
assert_eq!(operations.len(), 1);
@@ -1423,7 +1423,7 @@ fn parse_freeze_and_unfreeze_partition() {
14231423
assert_eq!(operations.len(), 1);
14241424
let expected_partition = Partition::Expr(Expr::Value(Value::SingleQuotedString(
14251425
"2024-08-14".to_string(),
1426-
)));
1426+
).with_empty_span()));
14271427
let expected_operation = if operation_name == &"FREEZE" {
14281428
AlterTableOperation::FreezePartition {
14291429
partition: expected_partition,

tests/sqlparser_common.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6078,7 +6078,7 @@ fn parse_interval_and_or_xor() {
60786078

60796079
#[test]
60806080
fn parse_at_timezone() {
6081-
let zero = Expr::Value(number("0"));
6081+
let zero = Expr::Value(number("0").with_empty_span());
60826082
let sql = "SELECT FROM_UNIXTIME(0) AT TIME ZONE 'UTC-06:00' FROM t";
60836083
let select = verified_only_select(sql);
60846084
assert_eq!(
@@ -7907,7 +7907,7 @@ fn parse_offset() {
79077907
all_dialects_where(|d| !d.is_column_alias(&Keyword::OFFSET, &mut Parser::new(d)));
79087908

79097909
let expect = Some(Offset {
7910-
value: Expr::Value(number("2")),
7910+
value: Expr::Value(number("2").with_empty_span()),
79117911
rows: OffsetRows::Rows,
79127912
});
79137913
let ast = dialects.verified_query("SELECT foo FROM bar OFFSET 2 ROWS");
@@ -7962,7 +7962,7 @@ fn parse_fetch() {
79627962
let fetch_first_two_rows_only = Some(Fetch {
79637963
with_ties: false,
79647964
percent: false,
7965-
quantity: Some(Expr::Value(number("2"))),
7965+
quantity: Some(Expr::Value(number("2").with_empty_span())),
79667966
});
79677967
let ast = verified_query("SELECT foo FROM bar FETCH FIRST 2 ROWS ONLY");
79687968
assert_eq!(ast.fetch, fetch_first_two_rows_only);
@@ -9478,7 +9478,7 @@ fn verified_expr(query: &str) -> Expr {
94789478
fn parse_offset_and_limit() {
94799479
let sql = "SELECT foo FROM bar LIMIT 1 OFFSET 2";
94809480
let expect = Some(Offset {
9481-
value: Expr::Value(number("2")),
9481+
value: Expr::Value(number("2").with_empty_span()),
94829482
rows: OffsetRows::None,
94839483
});
94849484
let ast = verified_query(sql);
@@ -11101,7 +11101,7 @@ fn parse_connect_by() {
1110111101
op: BinaryOperator::Eq,
1110211102
right: Box::new(Expr::Value(Value::SingleQuotedString(
1110311103
"president".to_owned(),
11104-
))),
11104+
).with_empty_span())),
1110511105
},
1110611106
relationships: vec![Expr::BinaryOp {
1110711107
left: Box::new(Expr::Identifier(Ident::new("manager_id"))),
@@ -11807,7 +11807,7 @@ fn test_map_syntax() {
1180711807
);
1180811808

1180911809
fn number_expr(s: &str) -> Expr {
11810-
Expr::Value(number(s))
11810+
Expr::Value(number(s).with_empty_span())
1181111811
}
1181211812

1181311813
check(
@@ -13184,7 +13184,7 @@ fn parse_bang_not() {
1318413184
Box::new(Expr::Nested(Box::new(Expr::BinaryOp {
1318513185
left: Box::new(Expr::Identifier(Ident::new("b"))),
1318613186
op: BinaryOperator::Gt,
13187-
right: Box::new(Expr::Value(Value::Number("3".parse().unwrap(), false))),
13187+
right: Box::new(Expr::Value(Value::Number("3".parse().unwrap(), false).with_empty_span())),
1318813188
}))),
1318913189
]
1319013190
.into_iter()

tests/sqlparser_custom_dialect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn custom_prefix_parser() -> Result<(), ParserError> {
4141

4242
fn parse_prefix(&self, parser: &mut Parser) -> Option<Result<Expr, ParserError>> {
4343
if parser.consume_token(&Token::Number("1".to_string(), false)) {
44-
Some(Ok(Expr::Value(Value::Null)))
44+
Some(Ok(Expr::Value(Value::Null.with_empty_span())))
4545
} else {
4646
None
4747
}

tests/sqlparser_postgres.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ fn parse_alter_table_alter_column() {
768768
) {
769769
AlterTableOperation::AlterColumn { column_name, op } => {
770770
assert_eq!("is_active", column_name.to_string());
771-
let using_expr = Expr::Value(Value::SingleQuotedString("text".to_string()));
771+
let using_expr = Expr::Value(Value::SingleQuotedString("text".to_string()).with_empty_span());
772772
assert_eq!(
773773
op,
774774
AlterColumnOperation::SetDataType {
@@ -2201,7 +2201,7 @@ fn parse_pg_like_match_ops() {
22012201
#[test]
22022202
fn parse_array_index_expr() {
22032203
let num: Vec<Expr> = (0..=10)
2204-
.map(|s| Expr::Value(number(&s.to_string())))
2204+
.map(|s| Expr::Value(number(&s.to_string()).with_empty_span()))
22052205
.collect();
22062206

22072207
let sql = "SELECT foo[0] FROM foos";
@@ -2312,7 +2312,7 @@ fn parse_array_subscript() {
23122312
(
23132313
"(ARRAY[1, 2, 3, 4, 5, 6])[2]",
23142314
Subscript::Index {
2315-
index: Expr::Value(number("2")),
2315+
index: Expr::Value(number("2").with_empty_span()),
23162316
},
23172317
),
23182318
(
@@ -2324,17 +2324,17 @@ fn parse_array_subscript() {
23242324
(
23252325
"(ARRAY[1, 2, 3, 4, 5, 6])[2:5]",
23262326
Subscript::Slice {
2327-
lower_bound: Some(Expr::Value(number("2"))),
2328-
upper_bound: Some(Expr::Value(number("5"))),
2327+
lower_bound: Some(Expr::Value(number("2").with_empty_span())),
2328+
upper_bound: Some(Expr::Value(number("5").with_empty_span())),
23292329
stride: None,
23302330
},
23312331
),
23322332
(
23332333
"(ARRAY[1, 2, 3, 4, 5, 6])[2:5:3]",
23342334
Subscript::Slice {
2335-
lower_bound: Some(Expr::Value(number("2"))),
2336-
upper_bound: Some(Expr::Value(number("5"))),
2337-
stride: Some(Expr::Value(number("3"))),
2335+
lower_bound: Some(Expr::Value(number("2").with_empty_span())),
2336+
upper_bound: Some(Expr::Value(number("5").with_empty_span())),
2337+
stride: Some(Expr::Value(number("3").with_empty_span())),
23382338
},
23392339
),
23402340
(
@@ -2343,12 +2343,12 @@ fn parse_array_subscript() {
23432343
lower_bound: Some(Expr::BinaryOp {
23442344
left: Box::new(call("array_length", [Expr::Identifier(Ident::new("arr"))])),
23452345
op: BinaryOperator::Minus,
2346-
right: Box::new(Expr::Value(number("3"))),
2346+
right: Box::new(Expr::Value(number("3").with_empty_span())),
23472347
}),
23482348
upper_bound: Some(Expr::BinaryOp {
23492349
left: Box::new(call("array_length", [Expr::Identifier(Ident::new("arr"))])),
23502350
op: BinaryOperator::Minus,
2351-
right: Box::new(Expr::Value(number("1"))),
2351+
right: Box::new(Expr::Value(number("1").with_empty_span())),
23522352
}),
23532353
stride: None,
23542354
},
@@ -2357,14 +2357,14 @@ fn parse_array_subscript() {
23572357
"(ARRAY[1, 2, 3, 4, 5, 6])[:5]",
23582358
Subscript::Slice {
23592359
lower_bound: None,
2360-
upper_bound: Some(Expr::Value(number("5"))),
2360+
upper_bound: Some(Expr::Value(number("5").with_empty_span())),
23612361
stride: None,
23622362
},
23632363
),
23642364
(
23652365
"(ARRAY[1, 2, 3, 4, 5, 6])[2:]",
23662366
Subscript::Slice {
2367-
lower_bound: Some(Expr::Value(number("2"))),
2367+
lower_bound: Some(Expr::Value(number("2").with_empty_span())),
23682368
upper_bound: None,
23692369
stride: None,
23702370
},
@@ -4652,7 +4652,7 @@ fn parse_at_time_zone() {
46524652
kind: CastKind::DoubleColon,
46534653
expr: Box::new(Expr::Value(Value::SingleQuotedString(
46544654
"America/Los_Angeles".to_owned(),
4655-
))),
4655+
).with_empty_span())),
46564656
data_type: DataType::Text,
46574657
format: None,
46584658
}),
@@ -4661,7 +4661,7 @@ fn parse_at_time_zone() {
46614661
right: Box::new(Expr::Interval(Interval {
46624662
value: Box::new(Expr::Value(Value::SingleQuotedString(
46634663
"23 hours".to_owned(),
4664-
))),
4664+
).with_empty_span())),
46654665
leading_field: None,
46664666
leading_precision: None,
46674667
last_field: None,
@@ -4790,7 +4790,7 @@ fn parse_create_after_update_trigger_with_condition() {
47904790
Ident::new("balance"),
47914791
])),
47924792
op: BinaryOperator::Gt,
4793-
right: Box::new(Expr::Value(number("10000"))),
4793+
right: Box::new(Expr::Value(number("10000").with_empty_span())),
47944794
}))),
47954795
exec_body: TriggerExecBody {
47964796
exec_type: TriggerExecBodyType::Function,

tests/sqlparser_snowflake.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,13 +1661,13 @@ fn parse_snowflake_declare_result_set() {
16611661
(
16621662
"DECLARE res RESULTSET DEFAULT 42",
16631663
"res",
1664-
Some(DeclareAssignment::Default(Expr::Value(number("42")).into())),
1664+
Some(DeclareAssignment::Default(Expr::Value(number("42").with_empty_span()).into())),
16651665
),
16661666
(
16671667
"DECLARE res RESULTSET := 42",
16681668
"res",
16691669
Some(DeclareAssignment::DuckAssignment(
1670-
Expr::Value(number("42")).into(),
1670+
Expr::Value(number("42").with_empty_span()).into(),
16711671
)),
16721672
),
16731673
("DECLARE res RESULTSET", "res", None),
@@ -1754,13 +1754,13 @@ fn parse_snowflake_declare_variable() {
17541754
"DECLARE profit TEXT DEFAULT 42",
17551755
"profit",
17561756
Some(DataType::Text),
1757-
Some(DeclareAssignment::Default(Expr::Value(number("42")).into())),
1757+
Some(DeclareAssignment::Default(Expr::Value(number("42").with_empty_span()).into())),
17581758
),
17591759
(
17601760
"DECLARE profit DEFAULT 42",
17611761
"profit",
17621762
None,
1763-
Some(DeclareAssignment::Default(Expr::Value(number("42")).into())),
1763+
Some(DeclareAssignment::Default(Expr::Value(number("42").with_empty_span()).into())),
17641764
),
17651765
("DECLARE profit TEXT", "profit", Some(DataType::Text), None),
17661766
("DECLARE profit", "profit", None, None),

0 commit comments

Comments
 (0)