Skip to content

Commit e5aa255

Browse files
committed
recursion test + related
1 parent 17bf0a1 commit e5aa255

14 files changed

+345
-476
lines changed

src/parser/mod.rs

+14-28
Original file line numberDiff line numberDiff line change
@@ -12266,10 +12266,8 @@ mod tests {
1226612266
#[test]
1226712267
fn test_ansii_character_string_types() {
1226812268
// Character string types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#character-string-type>
12269-
let dialect = TestedDialects {
12270-
dialects: vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})],
12271-
options: None,
12272-
};
12269+
let dialect =
12270+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})]);
1227312271

1227412272
test_parse_data_type!(dialect, "CHARACTER", DataType::Character(None));
1227512273

@@ -12396,10 +12394,8 @@ mod tests {
1239612394
#[test]
1239712395
fn test_ansii_character_large_object_types() {
1239812396
// Character large object types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#character-large-object-length>
12399-
let dialect = TestedDialects {
12400-
dialects: vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})],
12401-
options: None,
12402-
};
12397+
let dialect =
12398+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})]);
1240312399

1240412400
test_parse_data_type!(
1240512401
dialect,
@@ -12429,10 +12425,9 @@ mod tests {
1242912425

1243012426
#[test]
1243112427
fn test_parse_custom_types() {
12432-
let dialect = TestedDialects {
12433-
dialects: vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})],
12434-
options: None,
12435-
};
12428+
let dialect =
12429+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})]);
12430+
1243612431
test_parse_data_type!(
1243712432
dialect,
1243812433
"GEOMETRY",
@@ -12461,10 +12456,8 @@ mod tests {
1246112456
#[test]
1246212457
fn test_ansii_exact_numeric_types() {
1246312458
// Exact numeric types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#exact-numeric-type>
12464-
let dialect = TestedDialects {
12465-
dialects: vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})],
12466-
options: None,
12467-
};
12459+
let dialect =
12460+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})]);
1246812461

1246912462
test_parse_data_type!(dialect, "NUMERIC", DataType::Numeric(ExactNumberInfo::None));
1247012463

@@ -12512,10 +12505,8 @@ mod tests {
1251212505
#[test]
1251312506
fn test_ansii_date_type() {
1251412507
// Datetime types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#datetime-type>
12515-
let dialect = TestedDialects {
12516-
dialects: vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})],
12517-
options: None,
12518-
};
12508+
let dialect =
12509+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})]);
1251912510

1252012511
test_parse_data_type!(dialect, "DATE", DataType::Date);
1252112512

@@ -12624,10 +12615,8 @@ mod tests {
1262412615
}};
1262512616
}
1262612617

12627-
let dialect = TestedDialects {
12628-
dialects: vec![Box::new(GenericDialect {}), Box::new(MySqlDialect {})],
12629-
options: None,
12630-
};
12618+
let dialect =
12619+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(MySqlDialect {})]);
1263112620

1263212621
test_parse_table_constraint!(
1263312622
dialect,
@@ -12746,10 +12735,7 @@ mod tests {
1274612735

1274712736
#[test]
1274812737
fn test_parse_multipart_identifier_positive() {
12749-
let dialect = TestedDialects {
12750-
dialects: vec![Box::new(GenericDialect {})],
12751-
options: None,
12752-
};
12738+
let dialect = TestedDialects::new(vec![Box::new(GenericDialect {})]);
1275312739

1275412740
// parse multipart with quotes
1275512741
let expected = vec![

src/test_utils.rs

+25-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use pretty_assertions::assert_eq;
4444
pub struct TestedDialects {
4545
pub dialects: Vec<Box<dyn Dialect>>,
4646
pub options: Option<ParserOptions>,
47+
pub recursion_limit: Option<usize>,
4748
}
4849

4950
impl TestedDialects {
@@ -52,16 +53,38 @@ impl TestedDialects {
5253
Self {
5354
dialects,
5455
options: None,
56+
recursion_limit: None,
5557
}
5658
}
5759

60+
pub fn new_with_options(dialects: Vec<Box<dyn Dialect>>, options: ParserOptions) -> Self {
61+
Self {
62+
dialects,
63+
options: Some(options),
64+
recursion_limit: None,
65+
}
66+
}
67+
68+
pub fn with_recursion_limit(mut self, recursion_limit: usize) -> Self {
69+
self.recursion_limit = Some(recursion_limit);
70+
self
71+
}
72+
5873
fn new_parser<'a>(&self, dialect: &'a dyn Dialect) -> Parser<'a> {
5974
let parser = Parser::new(dialect);
60-
if let Some(options) = &self.options {
75+
let parser = if let Some(options) = &self.options {
6176
parser.with_options(options.clone())
6277
} else {
6378
parser
64-
}
79+
};
80+
81+
let parser = if let Some(recursion_limit) = &self.recursion_limit {
82+
parser.with_recursion_limit(recursion_limit.clone())
83+
} else {
84+
parser
85+
};
86+
87+
parser
6588
}
6689

6790
/// Run the given function for all of `self.dialects`, assert that they

tests/sqlparser_bigquery.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ fn parse_literal_string() {
4040
r#""""triple-double\"escaped""", "#,
4141
r#""""triple-double"unescaped""""#,
4242
);
43-
let dialect = TestedDialects {
44-
dialects: vec![Box::new(BigQueryDialect {})],
45-
options: Some(ParserOptions::new().with_unescape(false)),
46-
};
43+
let dialect = TestedDialects::new_with_options(
44+
vec![Box::new(BigQueryDialect {})],
45+
ParserOptions::new().with_unescape(false),
46+
);
4747
let select = dialect.verified_only_select(sql);
4848
assert_eq!(10, select.projection.len());
4949
assert_eq!(
@@ -1936,17 +1936,14 @@ fn parse_big_query_declare() {
19361936
}
19371937

19381938
fn bigquery() -> TestedDialects {
1939-
TestedDialects {
1940-
dialects: vec![Box::new(BigQueryDialect {})],
1941-
options: None,
1942-
}
1939+
TestedDialects::new(vec![Box::new(BigQueryDialect {})])
19431940
}
19441941

19451942
fn bigquery_and_generic() -> TestedDialects {
1946-
TestedDialects {
1947-
dialects: vec![Box::new(BigQueryDialect {}), Box::new(GenericDialect {})],
1948-
options: None,
1949-
}
1943+
TestedDialects::new(vec![
1944+
Box::new(BigQueryDialect {}),
1945+
Box::new(GenericDialect {}),
1946+
])
19501947
}
19511948

19521949
#[test]

tests/sqlparser_clickhouse.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1613,15 +1613,12 @@ fn parse_explain_table() {
16131613
}
16141614

16151615
fn clickhouse() -> TestedDialects {
1616-
TestedDialects {
1617-
dialects: vec![Box::new(ClickHouseDialect {})],
1618-
options: None,
1619-
}
1616+
TestedDialects::new(vec![Box::new(ClickHouseDialect {})])
16201617
}
16211618

16221619
fn clickhouse_and_generic() -> TestedDialects {
1623-
TestedDialects {
1624-
dialects: vec![Box::new(ClickHouseDialect {}), Box::new(GenericDialect {})],
1625-
options: None,
1626-
}
1620+
TestedDialects::new(vec![
1621+
Box::new(ClickHouseDialect {}),
1622+
Box::new(GenericDialect {}),
1623+
])
16271624
}

0 commit comments

Comments
 (0)