Skip to content

Commit e474fd2

Browse files
committed
recursion test + ability to configure recursion limit for tests
1 parent 94d5466 commit e474fd2

14 files changed

+346
-480
lines changed

src/parser/mod.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12279,10 +12279,8 @@ mod tests {
1227912279
#[test]
1228012280
fn test_ansii_character_string_types() {
1228112281
// Character string types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#character-string-type>
12282-
let dialect = TestedDialects {
12283-
dialects: vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})],
12284-
options: None,
12285-
};
12282+
let dialect =
12283+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})]);
1228612284

1228712285
test_parse_data_type!(dialect, "CHARACTER", DataType::Character(None));
1228812286

@@ -12409,10 +12407,8 @@ mod tests {
1240912407
#[test]
1241012408
fn test_ansii_character_large_object_types() {
1241112409
// Character large object types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#character-large-object-length>
12412-
let dialect = TestedDialects {
12413-
dialects: vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})],
12414-
options: None,
12415-
};
12410+
let dialect =
12411+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})]);
1241612412

1241712413
test_parse_data_type!(
1241812414
dialect,
@@ -12442,10 +12438,9 @@ mod tests {
1244212438

1244312439
#[test]
1244412440
fn test_parse_custom_types() {
12445-
let dialect = TestedDialects {
12446-
dialects: vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})],
12447-
options: None,
12448-
};
12441+
let dialect =
12442+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})]);
12443+
1244912444
test_parse_data_type!(
1245012445
dialect,
1245112446
"GEOMETRY",
@@ -12474,10 +12469,8 @@ mod tests {
1247412469
#[test]
1247512470
fn test_ansii_exact_numeric_types() {
1247612471
// Exact numeric types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#exact-numeric-type>
12477-
let dialect = TestedDialects {
12478-
dialects: vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})],
12479-
options: None,
12480-
};
12472+
let dialect =
12473+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})]);
1248112474

1248212475
test_parse_data_type!(dialect, "NUMERIC", DataType::Numeric(ExactNumberInfo::None));
1248312476

@@ -12525,10 +12518,8 @@ mod tests {
1252512518
#[test]
1252612519
fn test_ansii_date_type() {
1252712520
// Datetime types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#datetime-type>
12528-
let dialect = TestedDialects {
12529-
dialects: vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})],
12530-
options: None,
12531-
};
12521+
let dialect =
12522+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})]);
1253212523

1253312524
test_parse_data_type!(dialect, "DATE", DataType::Date);
1253412525

@@ -12637,10 +12628,8 @@ mod tests {
1263712628
}};
1263812629
}
1263912630

12640-
let dialect = TestedDialects {
12641-
dialects: vec![Box::new(GenericDialect {}), Box::new(MySqlDialect {})],
12642-
options: None,
12643-
};
12631+
let dialect =
12632+
TestedDialects::new(vec![Box::new(GenericDialect {}), Box::new(MySqlDialect {})]);
1264412633

1264512634
test_parse_table_constraint!(
1264612635
dialect,
@@ -12759,10 +12748,7 @@ mod tests {
1275912748

1276012749
#[test]
1276112750
fn test_parse_multipart_identifier_positive() {
12762-
let dialect = TestedDialects {
12763-
dialects: vec![Box::new(GenericDialect {})],
12764-
options: None,
12765-
};
12751+
let dialect = TestedDialects::new(vec![Box::new(GenericDialect {})]);
1276612752

1276712753
// parse multipart with quotes
1276812754
let expected = vec![

src/test_utils.rs

Lines changed: 25 additions & 2 deletions
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

Lines changed: 9 additions & 12 deletions
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

Lines changed: 5 additions & 8 deletions
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)