Skip to content

Commit

Permalink
Merge pull request #67 from cvng/create-type
Browse files Browse the repository at this point in the history
  • Loading branch information
psteinroe authored Dec 13, 2023
2 parents b0196f2 + 3a76a34 commit f0fca97
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions crates/codegen/src/get_node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {},
}
}
Expand Down
24 changes: 20 additions & 4 deletions crates/parser/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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()),
],
)
}
}
1 change: 1 addition & 0 deletions crates/parser/tests/data/statements/valid/0037.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed');

0 comments on commit f0fca97

Please sign in to comment.