Skip to content

Commit

Permalink
Add new nodes, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msepga committed Dec 23, 2023
1 parent 95c85ae commit 776b2f8
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ fs_extra = "1.2.0"

[dev-dependencies]
easy-parallel = "3.2.0"
pretty_assertions = "1.2.1"
pretty_assertions = "1.4.0"
regex = "1.6.0"
28 changes: 28 additions & 0 deletions src/node_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,20 @@ impl NodeEnum {
NodeEnum::MergeWhenClause(n) => NodeRef::MergeWhenClause(n),
NodeEnum::PublicationObjSpec(n) => NodeRef::PublicationObjSpec(n),
NodeEnum::PublicationTable(n) => NodeRef::PublicationTable(n),
NodeEnum::JsonFormat(n) => NodeRef::JsonFormat(n),
NodeEnum::JsonReturning(n) => NodeRef::JsonReturning(n),
NodeEnum::JsonValueExpr(n) => NodeRef::JsonValueExpr(n),
NodeEnum::JsonConstructorExpr(n) => NodeRef::JsonConstructorExpr(n),
NodeEnum::JsonIsPredicate(n) => NodeRef::JsonIsPredicate(n),
NodeEnum::JsonOutput(n) => NodeRef::JsonOutput(n),
NodeEnum::JsonKeyValue(n) => NodeRef::JsonKeyValue(n),
NodeEnum::JsonObjectConstructor(n) => NodeRef::JsonObjectConstructor(n),
NodeEnum::JsonArrayConstructor(n) => NodeRef::JsonArrayConstructor(n),
NodeEnum::JsonArrayQueryConstructor(n) => NodeRef::JsonArrayQueryConstructor(n),
NodeEnum::JsonAggConstructor(n) => NodeRef::JsonAggConstructor(n),
NodeEnum::JsonObjectAgg(n) => NodeRef::JsonObjectAgg(n),
NodeEnum::JsonArrayAgg(n) => NodeRef::JsonArrayAgg(n),
NodeEnum::RtepermissionInfo(n) => NodeRef::RtepermissionInfo(n),
}
}

Expand Down Expand Up @@ -1362,6 +1376,20 @@ impl NodeEnum {
NodeEnum::MergeWhenClause(n) => NodeMut::MergeWhenClause(&mut **n as *mut _),
NodeEnum::PublicationObjSpec(n) => NodeMut::PublicationObjSpec(&mut **n as *mut _),
NodeEnum::PublicationTable(n) => NodeMut::PublicationTable(&mut **n as *mut _),
NodeEnum::JsonFormat(n) => NodeMut::JsonFormat(&mut *n as *mut _),
NodeEnum::JsonReturning(n) => NodeMut::JsonReturning(&mut *n as *mut _),
NodeEnum::JsonValueExpr(n) => NodeMut::JsonValueExpr(&mut **n as *mut _),
NodeEnum::JsonConstructorExpr(n) => NodeMut::JsonConstructorExpr(&mut **n as *mut _),
NodeEnum::JsonIsPredicate(n) => NodeMut::JsonIsPredicate(&mut **n as *mut _),
NodeEnum::JsonOutput(n) => NodeMut::JsonOutput(&mut *n as *mut _),
NodeEnum::JsonKeyValue(n) => NodeMut::JsonKeyValue(&mut **n as *mut _),
NodeEnum::JsonObjectConstructor(n) => NodeMut::JsonObjectConstructor(&mut *n as *mut _),
NodeEnum::JsonArrayConstructor(n) => NodeMut::JsonArrayConstructor(&mut *n as *mut _),
NodeEnum::JsonArrayQueryConstructor(n) => NodeMut::JsonArrayQueryConstructor(&mut **n as *mut _),
NodeEnum::JsonAggConstructor(n) => NodeMut::JsonAggConstructor(&mut **n as *mut _),
NodeEnum::JsonObjectAgg(n) => NodeMut::JsonObjectAgg(&mut **n as *mut _),
NodeEnum::JsonArrayAgg(n) => NodeMut::JsonArrayAgg(&mut **n as *mut _),
NodeEnum::RtepermissionInfo(n) => NodeMut::RtepermissionInfo(&mut *n as *mut _),
}
}
}
28 changes: 28 additions & 0 deletions src/node_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,20 @@ pub enum NodeMut {
MergeWhenClause(*mut protobuf::MergeWhenClause),
PublicationObjSpec(*mut protobuf::PublicationObjSpec),
PublicationTable(*mut protobuf::PublicationTable),
JsonFormat(*mut protobuf::JsonFormat),
JsonReturning(*mut protobuf::JsonReturning),
JsonValueExpr(*mut protobuf::JsonValueExpr),
JsonConstructorExpr(*mut protobuf::JsonConstructorExpr),
JsonIsPredicate(*mut protobuf::JsonIsPredicate),
JsonOutput(*mut protobuf::JsonOutput),
JsonKeyValue(*mut protobuf::JsonKeyValue),
JsonObjectConstructor(*mut protobuf::JsonObjectConstructor),
JsonArrayConstructor(*mut protobuf::JsonArrayConstructor),
JsonArrayQueryConstructor(*mut protobuf::JsonArrayQueryConstructor),
JsonAggConstructor(*mut protobuf::JsonAggConstructor),
JsonObjectAgg(*mut protobuf::JsonObjectAgg),
JsonArrayAgg(*mut protobuf::JsonArrayAgg),
RtepermissionInfo(*mut protobuf::RtePermissionInfo),
}

impl NodeMut {
Expand Down Expand Up @@ -492,6 +506,20 @@ impl NodeMut {
NodeMut::MergeWhenClause(n) => Ok(NodeEnum::MergeWhenClause(Box::new(n.as_ref().ok_or(err)?.clone()))),
NodeMut::PublicationObjSpec(n) => Ok(NodeEnum::PublicationObjSpec(Box::new(n.as_ref().ok_or(err)?.clone()))),
NodeMut::PublicationTable(n) => Ok(NodeEnum::PublicationTable(Box::new(n.as_ref().ok_or(err)?.clone()))),
NodeMut::JsonFormat(n) => Ok(NodeEnum::JsonFormat(n.as_ref().ok_or(err)?.clone())),
NodeMut::JsonReturning(n) => Ok(NodeEnum::JsonReturning(n.as_ref().ok_or(err)?.clone())),
NodeMut::JsonValueExpr(n) => Ok(NodeEnum::JsonValueExpr(Box::new(n.as_ref().ok_or(err)?.clone()))),
NodeMut::JsonConstructorExpr(n) => Ok(NodeEnum::JsonConstructorExpr(Box::new(n.as_ref().ok_or(err)?.clone()))),
NodeMut::JsonIsPredicate(n) => Ok(NodeEnum::JsonIsPredicate(Box::new(n.as_ref().ok_or(err)?.clone()))),
NodeMut::JsonOutput(n) => Ok(NodeEnum::JsonOutput(n.as_ref().ok_or(err)?.clone())),
NodeMut::JsonKeyValue(n) => Ok(NodeEnum::JsonKeyValue(Box::new(n.as_ref().ok_or(err)?.clone()))),
NodeMut::JsonObjectConstructor(n) => Ok(NodeEnum::JsonObjectConstructor(n.as_ref().ok_or(err)?.clone())),
NodeMut::JsonArrayConstructor(n) => Ok(NodeEnum::JsonArrayConstructor(n.as_ref().ok_or(err)?.clone())),
NodeMut::JsonArrayQueryConstructor(n) => Ok(NodeEnum::JsonArrayQueryConstructor(Box::new(n.as_ref().ok_or(err)?.clone()))),
NodeMut::JsonAggConstructor(n) => Ok(NodeEnum::JsonAggConstructor(Box::new(n.as_ref().ok_or(err)?.clone()))),
NodeMut::JsonObjectAgg(n) => Ok(NodeEnum::JsonObjectAgg(Box::new(n.as_ref().ok_or(err)?.clone()))),
NodeMut::JsonArrayAgg(n) => Ok(NodeEnum::JsonArrayAgg(Box::new(n.as_ref().ok_or(err)?.clone()))),
NodeMut::RtepermissionInfo(n) => Ok(NodeEnum::RtepermissionInfo(n.as_ref().ok_or(err)?.clone())),
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions src/node_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,20 @@ pub enum NodeRef<'a> {
MergeWhenClause(&'a protobuf::MergeWhenClause),
PublicationObjSpec(&'a protobuf::PublicationObjSpec),
PublicationTable(&'a protobuf::PublicationTable),
JsonFormat(&'a protobuf::JsonFormat),
JsonReturning(&'a protobuf::JsonReturning),
JsonValueExpr(&'a protobuf::JsonValueExpr),
JsonConstructorExpr(&'a protobuf::JsonConstructorExpr),
JsonIsPredicate(&'a protobuf::JsonIsPredicate),
JsonOutput(&'a protobuf::JsonOutput),
JsonKeyValue(&'a protobuf::JsonKeyValue),
JsonObjectConstructor(&'a protobuf::JsonObjectConstructor),
JsonArrayConstructor(&'a protobuf::JsonArrayConstructor),
JsonArrayQueryConstructor(&'a protobuf::JsonArrayQueryConstructor),
JsonAggConstructor(&'a protobuf::JsonAggConstructor),
JsonObjectAgg(&'a protobuf::JsonObjectAgg),
JsonArrayAgg(&'a protobuf::JsonArrayAgg),
RtepermissionInfo(&'a protobuf::RtePermissionInfo),
}

impl<'a> NodeRef<'a> {
Expand Down Expand Up @@ -491,6 +505,20 @@ impl<'a> NodeRef<'a> {
NodeRef::MergeWhenClause(n) => NodeEnum::MergeWhenClause(Box::new((*n).clone())),
NodeRef::PublicationObjSpec(n) => NodeEnum::PublicationObjSpec(Box::new((*n).clone())),
NodeRef::PublicationTable(n) => NodeEnum::PublicationTable(Box::new((*n).clone())),
NodeRef::JsonFormat(n) => NodeEnum::JsonFormat((*n).clone()),
NodeRef::JsonReturning(n) => NodeEnum::JsonReturning((*n).clone()),
NodeRef::JsonValueExpr(n) => NodeEnum::JsonValueExpr(Box::new((*n).clone())),
NodeRef::JsonConstructorExpr(n) => NodeEnum::JsonConstructorExpr(Box::new((*n).clone())),
NodeRef::JsonIsPredicate(n) => NodeEnum::JsonIsPredicate(Box::new((*n).clone())),
NodeRef::JsonOutput(n) => NodeEnum::JsonOutput((*n).clone()),
NodeRef::JsonKeyValue(n) => NodeEnum::JsonKeyValue(Box::new((*n).clone())),
NodeRef::JsonObjectConstructor(n) => NodeEnum::JsonObjectConstructor((*n).clone()),
NodeRef::JsonArrayConstructor(n) => NodeEnum::JsonArrayConstructor((*n).clone()),
NodeRef::JsonArrayQueryConstructor(n) => NodeEnum::JsonArrayQueryConstructor(Box::new((*n).clone())),
NodeRef::JsonAggConstructor(n) => NodeEnum::JsonAggConstructor(Box::new((*n).clone())),
NodeRef::JsonObjectAgg(n) => NodeEnum::JsonObjectAgg(Box::new((*n).clone())),
NodeRef::JsonArrayAgg(n) => NodeEnum::JsonArrayAgg(Box::new((*n).clone())),
NodeRef::RtepermissionInfo(n) => NodeEnum::RtepermissionInfo((*n).clone()),
}
}
}
4 changes: 3 additions & 1 deletion tests/data/plpgsql_query.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lineno": 5,
"sqlstmt": {
"PLpgSQL_expr": {
"parseMode": 0,
"query": "SELECT details FROM t WHERE col = input"
}
},
Expand All @@ -31,6 +32,7 @@
"PLpgSQL_stmt_return": {
"expr": {
"PLpgSQL_expr": {
"parseMode": 2,
"query": "result"
}
},
Expand Down Expand Up @@ -88,4 +90,4 @@
]
}
}
]
]
5 changes: 4 additions & 1 deletion tests/data/plpgsql_simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"PLpgSQL_stmt_if": {
"cond": {
"PLpgSQL_expr": {
"parseMode": 2,
"query": "v_version IS NULL"
}
},
Expand All @@ -17,6 +18,7 @@
"PLpgSQL_stmt_return": {
"expr": {
"PLpgSQL_expr": {
"parseMode": 2,
"query": "v_name"
}
},
Expand All @@ -30,6 +32,7 @@
"PLpgSQL_stmt_return": {
"expr": {
"PLpgSQL_expr": {
"parseMode": 2,
"query": "v_name || '/' || v_version"
}
},
Expand Down Expand Up @@ -74,4 +77,4 @@
]
}
}
]
]
4 changes: 2 additions & 2 deletions tests/parse_plpgsql_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn it_can_parse_a_simple_function() {
let result = result.unwrap();
let expected = include_str!("data/plpgsql_simple.json");
let actual = serde_json::to_string_pretty(&result).unwrap();
assert_eq!(expected, &actual);
pretty_assertions::assert_eq!(expected.trim(), actual.trim());
}

#[test]
Expand All @@ -43,7 +43,7 @@ fn it_can_parse_a_query_function() {
let result = result.unwrap();
let expected = include_str!("data/plpgsql_query.json");
let actual = serde_json::to_string_pretty(&result).unwrap();
assert_eq!(expected, actual);
pretty_assertions::assert_eq!(expected.trim(), actual.trim());
}

#[test]
Expand Down
3 changes: 2 additions & 1 deletion tests/parse_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ fn it_parses_CREATE_TABLE() {
is_not_null: false,
is_from_type: false,
storage: "",
storage_name: "",
raw_default: None,
cooked_default: None,
identity: "",
Expand Down Expand Up @@ -942,7 +943,7 @@ fn it_parses_REVOKE() {
},
],
is_grant: false,
admin_opt: false,
opt: [],
grantor: None,
behavior: DropRestrict,
}"#
Expand Down

0 comments on commit 776b2f8

Please sign in to comment.