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..30c5a28c 100644 --- a/crates/parser/src/codegen.rs +++ b/crates/parser/src/codegen.rs @@ -66,10 +66,9 @@ mod tests { debug!("selected node: {:#?}", node_graph[node_index]); - assert!(node_graph[node_index] - .properties - .iter() - .all(|p| { expected.contains(p) })); + // 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()); } @@ -140,4 +139,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');