From 3da7a50a123b0bc8cabedc27a135f6953984116c Mon Sep 17 00:00:00 2001 From: Cedric Vangout Date: Tue, 19 Dec 2023 02:12:34 +0100 Subject: [PATCH] add snapshots --- crates/codegen/src/get_node_properties.rs | 5 + crates/parser/src/codegen.rs | 3 + .../tests/data/statements/valid/0049.sql | 2 +- .../snapshots/statements/valid/0049@1.snap | 28 +++++ .../snapshots/statements/valid/0049@2.snap | 118 ++++++++++++++++++ 5 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 crates/parser/tests/snapshots/statements/valid/0049@1.snap create mode 100644 crates/parser/tests/snapshots/statements/valid/0049@2.snap diff --git a/crates/codegen/src/get_node_properties.rs b/crates/codegen/src/get_node_properties.rs index 60353b69..ecd2ec29 100644 --- a/crates/codegen/src/get_node_properties.rs +++ b/crates/codegen/src/get_node_properties.rs @@ -703,6 +703,11 @@ fn custom_handlers(node: &Node) -> TokenStream { "CreateExtensionStmt" => quote! { tokens.push(TokenProperty::from(Token::Create)); tokens.push(TokenProperty::from(Token::Extension)); + if n.if_not_exists { + tokens.push(TokenProperty::from(Token::IfP)); + tokens.push(TokenProperty::from(Token::Not)); + tokens.push(TokenProperty::from(Token::Exists)); + } }, _ => quote! {}, } diff --git a/crates/parser/src/codegen.rs b/crates/parser/src/codegen.rs index 4876e981..c4488bef 100644 --- a/crates/parser/src/codegen.rs +++ b/crates/parser/src/codegen.rs @@ -290,6 +290,9 @@ mod tests { vec![ TokenProperty::from(SyntaxKind::Create), TokenProperty::from(SyntaxKind::Extension), + TokenProperty::from(SyntaxKind::IfP), + TokenProperty::from(SyntaxKind::Not), + TokenProperty::from(SyntaxKind::Exists), TokenProperty::from("x".to_string()), ], ) diff --git a/crates/parser/tests/data/statements/valid/0049.sql b/crates/parser/tests/data/statements/valid/0049.sql index ee41a225..f6fb52c3 100644 --- a/crates/parser/tests/data/statements/valid/0049.sql +++ b/crates/parser/tests/data/statements/valid/0049.sql @@ -1,2 +1,2 @@ CREATE EXTENSION x; -CREATE EXTENSION IF NOT EXISTS x CASCADE VERSION \"1.2\" SCHEMA a; +CREATE EXTENSION IF NOT EXISTS x CASCADE VERSION "1.2" SCHEMA a; diff --git a/crates/parser/tests/snapshots/statements/valid/0049@1.snap b/crates/parser/tests/snapshots/statements/valid/0049@1.snap new file mode 100644 index 00000000..79c95b41 --- /dev/null +++ b/crates/parser/tests/snapshots/statements/valid/0049@1.snap @@ -0,0 +1,28 @@ +--- +source: crates/parser/tests/statement_parser_test.rs +description: CREATE EXTENSION x; +--- +Parse { + cst: SourceFile@0..19 + CreateExtensionStmt@0..19 + Create@0..6 "CREATE" + Whitespace@6..7 " " + Extension@7..16 "EXTENSION" + Whitespace@16..17 " " + Ident@17..18 "x" + Ascii59@18..19 ";" + , + errors: [], + stmts: [ + RawStmt { + stmt: CreateExtensionStmt( + CreateExtensionStmt { + extname: "x", + if_not_exists: false, + options: [], + }, + ), + range: 0..18, + }, + ], +} diff --git a/crates/parser/tests/snapshots/statements/valid/0049@2.snap b/crates/parser/tests/snapshots/statements/valid/0049@2.snap new file mode 100644 index 00000000..fbe1867e --- /dev/null +++ b/crates/parser/tests/snapshots/statements/valid/0049@2.snap @@ -0,0 +1,118 @@ +--- +source: crates/parser/tests/statement_parser_test.rs +description: "\nCREATE EXTENSION IF NOT EXISTS x CASCADE VERSION \"1.2\" SCHEMA a;" +--- +Parse { + cst: SourceFile@0..65 + Newline@0..1 "\n" + CreateExtensionStmt@1..65 + Create@1..7 "CREATE" + Whitespace@7..8 " " + Extension@8..17 "EXTENSION" + Whitespace@17..18 " " + IfP@18..20 "IF" + Whitespace@20..21 " " + Not@21..24 "NOT" + Whitespace@24..25 " " + Exists@25..31 "EXISTS" + Whitespace@31..32 " " + Ident@32..33 "x" + Whitespace@33..34 " " + DefElem@34..41 + Cascade@34..41 "CASCADE" + Whitespace@41..42 " " + DefElem@42..55 + VersionP@42..49 "VERSION" + Whitespace@49..50 " " + Ident@50..55 "\"1.2\"" + Whitespace@55..56 " " + DefElem@56..64 + Schema@56..62 "SCHEMA" + Whitespace@62..63 " " + Ident@63..64 "a" + Ascii59@64..65 ";" + , + errors: [], + stmts: [ + RawStmt { + stmt: CreateExtensionStmt( + CreateExtensionStmt { + extname: "x", + if_not_exists: true, + options: [ + Node { + node: Some( + DefElem( + DefElem { + defnamespace: "", + defname: "cascade", + arg: Some( + Node { + node: Some( + Boolean( + Boolean { + boolval: true, + }, + ), + ), + }, + ), + defaction: DefelemUnspec, + location: 33, + }, + ), + ), + }, + Node { + node: Some( + DefElem( + DefElem { + defnamespace: "", + defname: "new_version", + arg: Some( + Node { + node: Some( + String( + String { + sval: "1.2", + }, + ), + ), + }, + ), + defaction: DefelemUnspec, + location: 41, + }, + ), + ), + }, + Node { + node: Some( + DefElem( + DefElem { + defnamespace: "", + defname: "schema", + arg: Some( + Node { + node: Some( + String( + String { + sval: "a", + }, + ), + ), + }, + ), + defaction: DefelemUnspec, + location: 55, + }, + ), + ), + }, + ], + }, + ), + range: 0..64, + }, + ], +}