-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Makes IonSchemaElement use borrowed Elements #222
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,18 +321,15 @@ fn generate_preamble(root_dir_path: &Path) -> TokenStream { | |
|
||
/// Asserts that a value is or is not valid for a given ISL type. | ||
fn __assert_value_validity_for_type(value_ion: &str, schema_id: &str, type_id: &str, expect_valid: bool) -> Result<(), String> { | ||
let schema = __new_schema_system().load_schema(schema_id).unwrap(); | ||
let isl_type = schema.get_type(type_id).unwrap(); | ||
let value: ion_rs::Element = ion_rs::Element::read_one(value_ion.as_bytes()).unwrap(); | ||
let schema = __new_schema_system().load_schema(schema_id).expect(&format!("Expected to load schema: {}", schema_id)); | ||
let isl_type = schema.get_type(type_id).expect(&format!("Expected to get type: {}", type_id)); | ||
let value: ion_rs::Element = ion_rs::Element::read_one(value_ion.as_bytes()).expect(&format!("Expected to be able to read value: {}", value_ion)); | ||
Comment on lines
+324
to
+326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗺️ Drive-by improvement to get better failure messages in the test runner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not very familiar with this part of the code--it looks like this is a method that only gets run in testing, so performance may not matter. If so, you can disregard. These https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_or_else There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's only in testing. |
||
let prepared_value: ion_schema::IonSchemaElement = if value.annotations().contains("document") && value.ion_type() == ion_rs::IonType::SExp { | ||
let element_vec = value.as_sequence() | ||
.unwrap_or_else(|| unreachable!("We already confirmed that this is a s-expression.")) | ||
.elements() | ||
.map(|it| it.to_owned()) | ||
.collect::<Vec<_>>(); | ||
ion_schema::IonSchemaElement::Document(element_vec) | ||
let values = value.as_sequence() | ||
.expect("We already confirmed that this is a s-expression."); | ||
ion_schema::IonSchemaElement::from(ion_schema::AsDocumentHint::as_document(values)) | ||
} else { | ||
ion_schema::IonSchemaElement::SingleElement(value) | ||
ion_schema::IonSchemaElement::from(&value) | ||
}; | ||
let validation_result = isl_type.validate(prepared_value); | ||
if validation_result.is_ok() == expect_valid { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,11 @@ use ion_schema_tests_runner::ion_schema_tests; | |
|
||
ion_schema_tests!( | ||
root = "ion-schema-tests/ion_schema_2_0/", | ||
// Support for ISL 2.0 is not completely implemented yet, so some tests are ignored. | ||
ignored( | ||
// Not fully implemented yet. | ||
"imports", | ||
"constraints::ordered_elements", | ||
"constraints::precision", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗺️ It turns out that we don't need to skip the tests for |
||
"constraints::regex::value_should_be_invalid_for_type_regex_unescaped_newline__2_", // https://github.com/amazon-ion/ion-rust/issues/399 | ||
// Failing because of https://github.com/amazon-ion/ion-rust/issues/399 | ||
"constraints::regex::value_should_be_invalid_for_type_regex_unescaped_newline__2_", | ||
) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you happen to know why we're using a
__
prefix rather than, say, making a new submodule to house these functions?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to make sure that we didn't have any name conflicts with a generated test case, so I added a
__
prefix. I could have added a new submodule, but that probably also would have needed something to reduce the likelihood of a name conflict with a generated test function.