Skip to content

Commit 515463f

Browse files
committed
Add some tests
1 parent 4c5021f commit 515463f

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

tests/sqlparser_common.rs

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,13 +2779,23 @@ fn parse_table_function() {
27792779

27802780
#[test]
27812781
fn parse_unnest() {
2782+
fn chk(alias: bool, with_offset: bool, dialects: &TestedDialects, want: Vec<TableWithJoins>) {
2783+
let sql = &format!(
2784+
"SELECT * FROM UNNEST(expr){}{}",
2785+
if alias { " AS numbers" } else { "" },
2786+
if with_offset { " WITH OFFSET" } else { "" },
2787+
);
2788+
let select = dialects.verified_only_select(sql);
2789+
assert_eq!(select.from, want);
2790+
}
27822791
let dialects = TestedDialects {
27832792
dialects: vec![Box::new(BigQueryDialect {}), Box::new(GenericDialect {})],
27842793
};
2785-
let sql = "SELECT * FROM UNNEST(expr) AS numbers WITH OFFSET";
2786-
let select = dialects.verified_only_select(sql);
2787-
assert_eq!(
2788-
select.from,
2794+
// 1. both Alias and WITH OFFSET clauses.
2795+
chk(
2796+
true,
2797+
true,
2798+
&dialects,
27892799
vec![TableWithJoins {
27902800
relation: TableFactor::UNNEST {
27912801
alias: Some(TableAlias {
@@ -2796,7 +2806,52 @@ fn parse_unnest() {
27962806
with_offset: true,
27972807
},
27982808
joins: vec![],
2799-
}]
2809+
}],
2810+
);
2811+
// 2. neither Alias nor WITH OFFSET clause.
2812+
chk(
2813+
false,
2814+
false,
2815+
&dialects,
2816+
vec![TableWithJoins {
2817+
relation: TableFactor::UNNEST {
2818+
alias: None,
2819+
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
2820+
with_offset: false,
2821+
},
2822+
joins: vec![],
2823+
}],
2824+
);
2825+
// 3. Alias but no WITH OFFSET clause.
2826+
chk(
2827+
false,
2828+
true,
2829+
&dialects,
2830+
vec![TableWithJoins {
2831+
relation: TableFactor::UNNEST {
2832+
alias: None,
2833+
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
2834+
with_offset: true,
2835+
},
2836+
joins: vec![],
2837+
}],
2838+
);
2839+
// 4. WITH OFFSET but no Alias.
2840+
chk(
2841+
true,
2842+
false,
2843+
&dialects,
2844+
vec![TableWithJoins {
2845+
relation: TableFactor::UNNEST {
2846+
alias: Some(TableAlias {
2847+
name: Ident::new("numbers"),
2848+
columns: vec![],
2849+
}),
2850+
array_expr: Box::new(Expr::Identifier(Ident::new("expr"))),
2851+
with_offset: false,
2852+
},
2853+
joins: vec![],
2854+
}],
28002855
);
28012856
}
28022857

0 commit comments

Comments
 (0)