Skip to content

Commit 12be3df

Browse files
Place regression tests beside related syntax cases
1 parent 5ffd8dc commit 12be3df

2 files changed

Lines changed: 79 additions & 79 deletions

File tree

‎tests/sqlparser_common.rs‎

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,66 @@ fn parse_between_with_expr() {
28792879
)
28802880
}
28812881

2882+
#[test]
2883+
fn parse_comparison_in_between_low_bound() {
2884+
let dialects = all_dialects_where(|d| d.supports_comparison_in_between_low_bound());
2885+
for (sql, expected) in [
2886+
("a BETWEEN b > 1 AND c", BinaryOperator::Gt),
2887+
("a BETWEEN b <> 1 AND c", BinaryOperator::NotEq),
2888+
("a BETWEEN b + 1 >= 2 AND c", BinaryOperator::GtEq),
2889+
] {
2890+
match dialects.verified_expr(sql) {
2891+
Expr::Between { low, .. } => assert!(
2892+
matches!(&*low, Expr::BinaryOp { op, .. } if *op == expected),
2893+
"{sql}: {low:?}"
2894+
),
2895+
other => panic!("{sql}: expected BETWEEN, got {other:?}"),
2896+
}
2897+
}
2898+
for (sql, error) in [
2899+
(
2900+
"SELECT a BETWEEN b = 1 = true AND c",
2901+
"Expected: AND, found: =",
2902+
),
2903+
(
2904+
"SELECT a BETWEEN b LIKE 'x' AND c",
2905+
"Expected: AND, found: LIKE",
2906+
),
2907+
(
2908+
"SELECT a BETWEEN b IS NULL AND c",
2909+
"Expected: AND, found: IS",
2910+
),
2911+
(
2912+
"SELECT a BETWEEN b BETWEEN 1 AND 2 AND c",
2913+
"Expected: AND, found: BETWEEN",
2914+
),
2915+
(
2916+
"SELECT a BETWEEN (1 AND 2 FROM t",
2917+
"Expected: ), found: FROM",
2918+
),
2919+
(
2920+
"SELECT a BETWEEN b = (1, 2 FROM t",
2921+
"Expected: ), found: FROM",
2922+
),
2923+
] {
2924+
assert_eq!(
2925+
dialects.parse_sql_statements(sql),
2926+
Err(ParserError::ParserError(error.to_string())),
2927+
"{sql}"
2928+
);
2929+
}
2930+
2931+
assert_eq!(
2932+
all_dialects_except(|d| {
2933+
d.supports_comparison_in_between_low_bound() || d.is::<SQLiteDialect>()
2934+
})
2935+
.parse_sql_statements("SELECT a BETWEEN b > 1 AND c"),
2936+
Err(ParserError::ParserError(
2937+
"Expected: AND, found: >".to_string()
2938+
))
2939+
);
2940+
}
2941+
28822942
#[test]
28832943
fn parse_tuples() {
28842944
let sql = "SELECT (1, 2), (1), ('foo', 3, baz)";
@@ -21358,63 +21418,3 @@ fn parse_qualified_literal_prefix_requires_adjacent_period() {
2135821418
dialects.tokenizes_to(sql, vec![token]);
2135921419
}
2136021420
}
21361-
21362-
#[test]
21363-
fn parse_comparison_in_between_low_bound() {
21364-
let dialects = all_dialects_where(|d| d.supports_comparison_in_between_low_bound());
21365-
for (sql, expected) in [
21366-
("a BETWEEN b > 1 AND c", BinaryOperator::Gt),
21367-
("a BETWEEN b <> 1 AND c", BinaryOperator::NotEq),
21368-
("a BETWEEN b + 1 >= 2 AND c", BinaryOperator::GtEq),
21369-
] {
21370-
match dialects.verified_expr(sql) {
21371-
Expr::Between { low, .. } => assert!(
21372-
matches!(&*low, Expr::BinaryOp { op, .. } if *op == expected),
21373-
"{sql}: {low:?}"
21374-
),
21375-
other => panic!("{sql}: expected BETWEEN, got {other:?}"),
21376-
}
21377-
}
21378-
for (sql, error) in [
21379-
(
21380-
"SELECT a BETWEEN b = 1 = true AND c",
21381-
"Expected: AND, found: =",
21382-
),
21383-
(
21384-
"SELECT a BETWEEN b LIKE 'x' AND c",
21385-
"Expected: AND, found: LIKE",
21386-
),
21387-
(
21388-
"SELECT a BETWEEN b IS NULL AND c",
21389-
"Expected: AND, found: IS",
21390-
),
21391-
(
21392-
"SELECT a BETWEEN b BETWEEN 1 AND 2 AND c",
21393-
"Expected: AND, found: BETWEEN",
21394-
),
21395-
(
21396-
"SELECT a BETWEEN (1 AND 2 FROM t",
21397-
"Expected: ), found: FROM",
21398-
),
21399-
(
21400-
"SELECT a BETWEEN b = (1, 2 FROM t",
21401-
"Expected: ), found: FROM",
21402-
),
21403-
] {
21404-
assert_eq!(
21405-
dialects.parse_sql_statements(sql),
21406-
Err(ParserError::ParserError(error.to_string())),
21407-
"{sql}"
21408-
);
21409-
}
21410-
21411-
assert_eq!(
21412-
all_dialects_except(|d| {
21413-
d.supports_comparison_in_between_low_bound() || d.is::<SQLiteDialect>()
21414-
})
21415-
.parse_sql_statements("SELECT a BETWEEN b > 1 AND c"),
21416-
Err(ParserError::ParserError(
21417-
"Expected: AND, found: >".to_string()
21418-
))
21419-
);
21420-
}

‎tests/sqlparser_spark.rs‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,25 @@ fn test_div_precedence() {
201201
);
202202
}
203203

204+
// Spark is not part of all_dialects, so the between low bound comparison is pinned here.
205+
206+
#[test]
207+
fn parse_comparison_in_between_low_bound() {
208+
match spark().verified_expr("a BETWEEN b > 1 AND c") {
209+
Expr::Between { low, .. } => assert!(
210+
matches!(
211+
&*low,
212+
Expr::BinaryOp {
213+
op: BinaryOperator::Gt,
214+
..
215+
}
216+
),
217+
"{low:?}"
218+
),
219+
other => panic!("expected BETWEEN, got {other:?}"),
220+
}
221+
}
222+
204223
// --------------------------------
205224
// Struct support
206225
// --------------------------------
@@ -362,22 +381,3 @@ fn test_substring() {
362381
fn test_pipe_operator() {
363382
spark().verified_stmt("SELECT * FROM t |> WHERE x > 1 |> SELECT x AS y |> ORDER BY y");
364383
}
365-
366-
// Spark is not part of all_dialects, so the between low bound comparison is pinned here.
367-
368-
#[test]
369-
fn parse_comparison_in_between_low_bound() {
370-
match spark().verified_expr("a BETWEEN b > 1 AND c") {
371-
Expr::Between { low, .. } => assert!(
372-
matches!(
373-
&*low,
374-
Expr::BinaryOp {
375-
op: BinaryOperator::Gt,
376-
..
377-
}
378-
),
379-
"{low:?}"
380-
),
381-
other => panic!("expected BETWEEN, got {other:?}"),
382-
}
383-
}

0 commit comments

Comments
 (0)