Skip to content

Commit

Permalink
fix tests and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
takaebato committed Dec 20, 2023
1 parent f2ad35e commit c5357bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4299,9 +4299,9 @@ impl fmt::Display for TransactionIsolationLevel {
}
}

/// Sqlite specific syntax
/// SQLite specific syntax
///
/// https://sqlite.org/lang_transaction.html
/// <https://sqlite.org/lang_transaction.html>
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
Expand Down
44 changes: 0 additions & 44 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,50 +212,6 @@ pub fn all_dialects() -> TestedDialects {
}
}

static ALL_DIALECT_NAMES: &[&str] = &[
"generic",
"mysql",
"postgresql",
"hive",
"sqlite",
"snowflake",
"redshift",
"mssql",
"clickhouse",
"bigquery",
"ansi",
"duckdb",
];

pub fn partition_all_dialects_by_inclusion(
dialect_names: Vec<&str>,
) -> (TestedDialects, TestedDialects) {
for dialect_name in &dialect_names {
assert!(
ALL_DIALECT_NAMES.contains(dialect_name),
"Unknown dialect: {}",
dialect_name
);
}

let (included_dialect_names, excluded_dialect_names) = ALL_DIALECT_NAMES
.iter()
.partition(|&dialect_name| dialect_names.contains(dialect_name));

let build_tested_dialects = |names: Vec<&str>| TestedDialects {
dialects: names
.iter()
.map(|&name| dialect_from_str(name).unwrap())
.collect(),
options: None,
};

(
build_tested_dialects(included_dialect_names),
build_tested_dialects(excluded_dialect_names),
)
}

pub fn assert_eq_vec<T: ToString>(expected: &[&str], actual: &[T]) {
assert_eq!(
expected,
Expand Down
25 changes: 15 additions & 10 deletions tests/sqlparser_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,21 @@ fn invalid_empty_list() {

#[test]
fn parse_start_transaction_with_modifier() {
let (supported_dialects, unsupported_dialects) =
partition_all_dialects_by_inclusion(vec!["generic", "sqlite"]);

supported_dialects.verified_stmt("BEGIN DEFERRED TRANSACTION");
supported_dialects.verified_stmt("BEGIN IMMEDIATE TRANSACTION");
supported_dialects.verified_stmt("BEGIN EXCLUSIVE TRANSACTION");
supported_dialects.one_statement_parses_to("BEGIN DEFERRED", "BEGIN DEFERRED TRANSACTION");
supported_dialects.one_statement_parses_to("BEGIN IMMEDIATE", "BEGIN IMMEDIATE TRANSACTION");
supported_dialects.one_statement_parses_to("BEGIN EXCLUSIVE", "BEGIN EXCLUSIVE TRANSACTION");

sqlite_and_generic().verified_stmt("BEGIN DEFERRED TRANSACTION");
sqlite_and_generic().verified_stmt("BEGIN IMMEDIATE TRANSACTION");
sqlite_and_generic().verified_stmt("BEGIN EXCLUSIVE TRANSACTION");
sqlite_and_generic().one_statement_parses_to("BEGIN DEFERRED", "BEGIN DEFERRED TRANSACTION");
sqlite_and_generic().one_statement_parses_to("BEGIN IMMEDIATE", "BEGIN IMMEDIATE TRANSACTION");
sqlite_and_generic().one_statement_parses_to("BEGIN EXCLUSIVE", "BEGIN EXCLUSIVE TRANSACTION");

let unsupported_dialects = TestedDialects {
dialects: all_dialects()
.dialects
.into_iter()
.filter(|x| !(x.is::<SQLiteDialect>() || x.is::<GenericDialect>()))
.collect(),
options: None,
};
let res = unsupported_dialects.parse_sql_statements("BEGIN DEFERRED");
assert_eq!(
ParserError::ParserError("Expected end of statement, found: DEFERRED".to_string()),
Expand Down

0 comments on commit c5357bf

Please sign in to comment.