From c99ea5932d7ac545cd963b0125b8a450e4367215 Mon Sep 17 00:00:00 2001 From: Cedric Vangout Date: Wed, 13 Dec 2023 10:19:07 +0100 Subject: [PATCH 1/2] feat: support `CreateEnumStmt` --- crates/codegen/src/get_node_properties.rs | 6 +++++ crates/parser/src/codegen.rs | 22 +++++++++++++++---- .../tests/data/statements/valid/0037.sql | 1 + 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 crates/parser/tests/data/statements/valid/0037.sql diff --git a/crates/codegen/src/get_node_properties.rs b/crates/codegen/src/get_node_properties.rs index d7437b31..66f29d25 100644 --- a/crates/codegen/src/get_node_properties.rs +++ b/crates/codegen/src/get_node_properties.rs @@ -559,6 +559,12 @@ fn custom_handlers(node: &Node) -> TokenStream { tokens.push(TokenProperty::from(Token::Authorization)); } }, + "CreateEnumStmt" => quote! { + tokens.push(TokenProperty::from(Token::Create)); + tokens.push(TokenProperty::from(Token::TypeP)); + tokens.push(TokenProperty::from(Token::As)); + tokens.push(TokenProperty::from(Token::EnumP)); + }, _ => quote! {}, } } diff --git a/crates/parser/src/codegen.rs b/crates/parser/src/codegen.rs index cb2bde3b..14f236a8 100644 --- a/crates/parser/src/codegen.rs +++ b/crates/parser/src/codegen.rs @@ -66,10 +66,7 @@ mod tests { debug!("selected node: {:#?}", node_graph[node_index]); - assert!(node_graph[node_index] - .properties - .iter() - .all(|p| { expected.contains(p) })); + assert_eq!(node_graph[node_index].properties, expected); assert_eq!(node_graph[node_index].properties.len(), expected.len()); } @@ -140,4 +137,21 @@ mod tests { ], ) } + + #[test] + fn test_create_enum() { + test_get_node_properties( + "create type status as enum ('open', 'closed');", + SyntaxKind::CreateEnumStmt, + vec![ + TokenProperty::from(SyntaxKind::Create), + TokenProperty::from(SyntaxKind::TypeP), + TokenProperty::from(SyntaxKind::As), + TokenProperty::from(SyntaxKind::EnumP), + TokenProperty::from("status".to_string()), + TokenProperty::from("open".to_string()), + TokenProperty::from("closed".to_string()), + ], + ) + } } diff --git a/crates/parser/tests/data/statements/valid/0037.sql b/crates/parser/tests/data/statements/valid/0037.sql new file mode 100644 index 00000000..2995010d --- /dev/null +++ b/crates/parser/tests/data/statements/valid/0037.sql @@ -0,0 +1 @@ +CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed'); From 3a76a344c20989c1826cf85b5a6c5c5744737a69 Mon Sep 17 00:00:00 2001 From: Cedric Vangout Date: Wed, 13 Dec 2023 16:44:55 +0100 Subject: [PATCH 2/2] add comment explaining equality check --- crates/parser/src/codegen.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/parser/src/codegen.rs b/crates/parser/src/codegen.rs index 14f236a8..30c5a28c 100644 --- a/crates/parser/src/codegen.rs +++ b/crates/parser/src/codegen.rs @@ -66,6 +66,8 @@ mod tests { debug!("selected node: {:#?}", node_graph[node_index]); + // note: even though we test for strict equality of the two vectors the order + // of the properties does not have to match the order of the tokens in the string assert_eq!(node_graph[node_index].properties, expected); assert_eq!(node_graph[node_index].properties.len(), expected.len()); }