Skip to content

Commit 7c0c274

Browse files
authored
Update git submodule following conformance refactor; refactor schema objects + generation (#150)
1 parent e71fa13 commit 7c0c274

File tree

4 files changed

+62
-85
lines changed

4 files changed

+62
-85
lines changed

partiql-conformance-test-generator/src/generator.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::schema::TestCaseKind::{NotYetImplemented, Parse};
2-
use crate::schema::{Namespace, ParseAssertions, ParseTestCase, TestCase, TestDocument};
1+
use crate::schema::{Assertion, Namespace, TestCase, TestDocument};
32
use codegen::{Function, Module, Scope};
43

54
/// Defines a test code generation object
@@ -42,24 +41,23 @@ fn namespace_to_module(namespace: &Namespace) -> Module {
4241
fn test_case_to_function(test_case: &TestCase) -> Function {
4342
let mut test_fn: Function = Function::new(&test_case.test_name);
4443
test_fn.attr("test");
45-
match &test_case.test_kind {
46-
Parse(ParseTestCase { parse_assertions }) => {
47-
test_fn.line(format!("let query = r#\"{}\"#;", &test_case.statement));
48-
test_fn.line("let res = partiql_parser::Parser::default().parse(query);");
49-
match parse_assertions {
50-
ParseAssertions::ParsePass => test_fn
51-
.line(r#"assert!(res.is_ok(), "For `{}`, expected `Ok(_)`, but was `{:#?}`", query, res);"#),
52-
ParseAssertions::ParseFail => test_fn
53-
.line(r#"assert!(res.is_err(), "For `{}`, expected `Err(_)`, but was `{:#?}`", query, res);"#),
54-
};
44+
test_fn.line(format!("let statement = r#\"{}\"#;", &test_case.statement));
45+
for assertion in &test_case.assertions {
46+
match assertion {
47+
Assertion::SyntaxSuccess => {
48+
test_fn.line("let res = partiql_parser::Parser::default().parse(statement);");
49+
test_fn.line(r#"assert!(res.is_ok(), "For `{}`, expected `Ok(_)`, but was `{:#?}`", statement, res);"#);
50+
}
51+
Assertion::SyntaxFail => {
52+
test_fn.line("let res = partiql_parser::Parser::default().parse(statement);");
53+
test_fn.line(r#"assert!(res.is_err(), "For `{}`, expected `Err(_)`, but was `{:#?}`", statement, res);"#);
54+
}
55+
Assertion::NotYetImplemented => {
56+
// for `NotYetImplemented` assertions, add the 'ignore' annotation to the test case
57+
test_fn.attr("ignore = \"not yet implemented\"");
58+
}
5559
}
56-
NotYetImplemented => {
57-
// for `NotYetImplemented` test cases, just output the statement and add the 'ignore'
58-
// annotation
59-
test_fn.attr("ignore");
60-
test_fn.line(format!("let _statement = r#\"{}\"#;", &test_case.statement));
61-
}
62-
};
60+
}
6361
test_fn
6462
}
6563

partiql-conformance-test-generator/src/lib.rs

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ pub mod generator;
22
mod schema;
33
pub mod util;
44

5-
use crate::schema::TestCaseKind::{NotYetImplemented, Parse};
65
use crate::schema::{
7-
Namespace, Namespaces, ParseAssertions, ParseTestCase, TestCase, TestCases, TestDocument,
6+
Assertion, Assertions, Namespace, Namespaces, TestCase, TestCases, TestDocument,
87
};
98
use crate::util::StringExt;
109
use ion_rs::value::owned::OwnedElement;
@@ -108,14 +107,12 @@ pub fn test_namespace(element: &OwnedElement) -> Namespace {
108107
}
109108
}
110109

111-
/// Parses the given IonStruct to a `TestCase`. Requires for there to be an annotation indicating
112-
/// the test case category (currently limited to just 'parse'). The IonStruct requires two string
113-
/// fields with the 'name' and 'statement'.
110+
/// Parses the given IonStruct to a `TestCase`. The IonStruct requires two string fields with the
111+
/// 'name' and 'statement' in addition to an 'assert' field containing one or more `Assertions`.
114112
///
115-
/// For test case categories that are not supported, will create a `NotYetImplemented` test case.
113+
/// For test assertions that are not supported (e.g. StaticAnalysisFail), the assertion of
114+
/// `NotYetImplemented` will be used.
116115
fn test_case(element: &OwnedElement) -> TestCase {
117-
let annot: Vec<_> = element.annotations().map(|a| a.text().expect("")).collect();
118-
119116
let test_struct = element.as_struct().expect("struct");
120117
let test_name = test_struct
121118
.get("name")
@@ -131,61 +128,47 @@ fn test_case(element: &OwnedElement) -> TestCase {
131128
.expect("as_str()")
132129
.to_string();
133130

134-
if annot.contains(&"parse") {
135-
TestCase {
136-
test_name,
137-
statement,
138-
test_kind: Parse(parse_test_case(element)),
139-
}
140-
} else {
141-
TestCase {
142-
test_name,
143-
statement,
144-
test_kind: NotYetImplemented,
145-
}
146-
}
147-
}
148-
149-
/// Converts the IonStruct into a `ParseTestCase`. Requires the 'assert' field to be present in the
150-
/// struct and for it to be an IonStruct or IonList.
151-
fn parse_test_case(element: &OwnedElement) -> ParseTestCase {
152-
let parse_struct = element.as_struct().expect("struct");
153-
let assert_field = parse_struct.get("assert").expect("assert");
154-
let assertions: Vec<_> = match assert_field.ion_type() {
131+
let assert_field = test_struct.get("assert").expect("assert field missing");
132+
let assertions_vec: Vec<_> = match assert_field.ion_type() {
155133
IonType::Struct => vec![assert_field],
156134
IonType::List => assert_field
157135
.as_sequence()
158136
.expect("as_sequence")
159137
.iter()
160138
.collect(),
161-
_ => panic!("Invalid IonType for the parse test case assertions"),
139+
_ => panic!("Invalid IonType for the test case assertions"),
162140
};
163-
164-
ParseTestCase {
165-
parse_assertions: parse_assertions(&assertions),
141+
let assertions = assertions(&assertions_vec);
142+
TestCase {
143+
test_name,
144+
statement,
145+
assertions,
166146
}
167147
}
168148

169-
/// Converts the vector of Ion values into `ParseAssertions`. Checks that a result field is provided
170-
/// in the vector and has the symbol 'ParseOk' or 'ParserError', which correspond to
171-
/// `ParseAssertions::ParsePass` and `ParseAssertions::ParseFail` respectively.
172-
fn parse_assertions(assertions: &Vec<&OwnedElement>) -> ParseAssertions {
149+
/// Converts the vector of Ion values into `Assertions`. Checks that a result field is provided
150+
/// in the vector and has the symbol 'SyntaxSuccess' or 'SyntaxFail', which correspond to
151+
/// `Assertion::SyntaxSuccess` and `Assertion::SyntaxFail` respectively. Other assertion symbols
152+
/// will default to `Assertion::NotYetImplemented`
153+
fn assertions(assertions: &Vec<&OwnedElement>) -> Assertions {
154+
let mut test_case_assertions: Assertions = Vec::new();
173155
for assertion in assertions {
174156
let assertion_struct = assertion.as_struct().expect("as_struct()");
175157
let parse_result = assertion_struct.get("result");
176158
match parse_result {
177159
Some(r) => {
178160
let r_as_str = r.as_str().expect("as_str()");
179-
return match r_as_str {
180-
"ParseOk" => ParseAssertions::ParsePass,
181-
"ParseError" => ParseAssertions::ParseFail,
182-
_ => panic!("Unexpected parse result {}", r_as_str),
161+
let assertion = match r_as_str {
162+
"SyntaxSuccess" => Assertion::SyntaxSuccess,
163+
"SyntaxFail" => Assertion::SyntaxFail,
164+
_ => Assertion::NotYetImplemented,
183165
};
166+
test_case_assertions.push(assertion);
184167
}
185168
None => (),
186169
}
187170
}
188-
panic!("Expected a parse result field");
171+
test_case_assertions
189172
}
190173

191174
#[cfg(test)]
Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/// Conformance test document containing namespaces and/or tests
2-
/// TODO: once test ISL is defined in `partiql-tests` (https://github.com/partiql/partiql-tests/issues/3),
3-
/// add link to ISL. Also, when `ion-schema-rust` supports schema code generation based on .isl,
4-
/// replace these objects.
2+
///
3+
/// Follows the `partiql-tests-data` specified in https://github.com/partiql/partiql-tests/blob/main/partiql-tests-data/partiql-tests-schema.isl.
4+
///
5+
/// TODO: when `ion-schema-rust` supports schema code generation based on .isl, replace these
6+
/// objects.
57
pub struct TestDocument {
68
pub(crate) namespaces: Namespaces,
79
pub(crate) test_cases: TestCases,
@@ -16,32 +18,26 @@ pub struct Namespace {
1618
}
1719
pub type TestCases = Vec<TestCase>;
1820

19-
/// Test cases have a `test_name` and a PartiQL `statement` along with additional test fields stored
20-
/// depending on the `test_kind`.
21+
/// Test cases have a `test_name` and a PartiQL `statement` along with the `assertions` to check for
22+
/// expected behavior(s). In the future, additional fields will be added the `TestCase` struct for
23+
/// additional testing configurations.
2124
pub struct TestCase {
2225
pub(crate) test_name: String,
2326
pub(crate) statement: String,
24-
pub(crate) test_kind: TestCaseKind,
27+
pub(crate) assertions: Assertions,
2528
}
29+
pub type Assertions = Vec<Assertion>;
2630

27-
/// Test case kind
31+
/// Assertion specifies expected behaviors to be checked in the given test case.
2832
///
29-
/// Currently, just supports `Parse` test cases. In the future, other test case variants will be
30-
/// added (e.g. evaluation, type-checking). For now, the other test case variants will be
33+
/// Currently just supports 'Syntax'-related assertions. In the future, other assertion variants
34+
/// will be added (e.g. static analysis, evaluation). For now, the other assertions will be
3135
/// `NotYetImplemented`.
32-
pub enum TestCaseKind {
33-
Parse(ParseTestCase),
36+
pub enum Assertion {
37+
/// Asserts statement is syntactically correct
38+
SyntaxSuccess,
39+
/// Asserts statement has at least one syntax error
40+
SyntaxFail,
41+
/// Assertion that has yet to be implemented
3442
NotYetImplemented,
3543
}
36-
37-
/// Test case to test the parsing behavior of a PartiQL statement
38-
pub struct ParseTestCase {
39-
pub(crate) parse_assertions: ParseAssertions,
40-
}
41-
42-
/// Indicates whether a parsing test passes (`ParsePass`) without errors or fails (`ParseFail`) with
43-
/// a parsing-related error
44-
pub enum ParseAssertions {
45-
ParsePass,
46-
ParseFail,
47-
}
Submodule partiql-tests updated 80 files

0 commit comments

Comments
 (0)