Skip to content

Commit

Permalink
Re-enable some ref tests (#73)
Browse files Browse the repository at this point in the history
Enable part of the test suite on references. For now, we've simply
re-enable the tests that are passing with the current state of the
repository, which at least mean those won't regress in future update. It
would be better to see, for each failing test, if it's failing because
it's unsupported or because there's a bug in the current implementation
- this is left for a future commit.
  • Loading branch information
yannham authored Apr 12, 2024
1 parent 6043e48 commit c78c9fd
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions tests/json_schema_test_suite_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ use json_schema_test_suite::{json_schema_test_suite, TestCase};
use json_schema_to_nickel::{
definitions::Environment, predicates::AsPredicate, root_schema, wrap_contract,
};
use nickel_lang_core::{eval::cache::lazy::CBNCache, program::Program, term::RichTerm};
use nickel_lang_core::{
error::{Error, EvalError},
eval::cache::lazy::CBNCache,
program::Program,
term::RichTerm,
};
use stringreader::StringReader;

#[json_schema_test_suite("vendor/JSON-Schema-Test-Suite", "draft7", {
"optional_format_.*",
"definitions_.*",
"definitions_0_1.*", // contains an external reference (remote URI)
"id_.*",
"maxItems_1_.*", // schemars doesn't accept floats as the value of `maxItems`
"maxLength_1_.*", // schemars doesn't accept floats as the value of `maxLength`
Expand All @@ -23,7 +28,33 @@ use stringreader::StringReader;
"optional_cross_draft_.*",
"optional_ecmascript_regex_.*",
"refRemote_.*", // no.
"ref_.*", // TODO: make reference handling robust
// TODO: make reference handling robust
// The following are references that aren't yet handled by js2n (remote URIs, ref to something
// else than properties or definitions, etc.)
"ref_0_3.*", // reference to the whole schema `#` not yet supported
"ref_12_1.*", // reference to bare URI `node` (no fragment, no leading slash). Should fail
// because invalid, but js2n replace that by a `Dyn` contract
"ref_13_0.*", // schemars doesn't properly percent-decode URIs
"ref_14_1.*", // reference to an anchor "#foo" not yet supported
"ref_15_1.*", // anchor + remote URI
"ref_16_1.*", // external reference (remote URI)
"ref_18_2.*", // external reference (local file URI)
"ref_19_2.*", // external reference (local file URI),
"ref_20_1.*", // external reference (remote URI)
"ref_21_1.*", // urn:uuid URI scheme not supported
"ref_26_1.*", // urn:uuid URI scheme not supported
"ref_27_1.*", // urn:uuid URI scheme not supported,
"ref_28_0.*", // external reference (remote URI)
"ref_29_0.*", // external reference (remote URI)
"ref_2_1.*", // internal ref to an array element (#/items/0)
"ref_30_0.*", // external reference (remote URI)
"ref_31_1.*", // external reference (absolute path /absref/foobar.json)
"ref_34_1.*", // non top-level definition ("#/definitions//definitions/")
"ref_3_5.*", // schemars doesn't properly percent-decode URIs
"ref_5_1.*", // not related to external ref, but js2n doesn't properly ignore other components
// when the `ref` field is used
"ref_6_0.*", // reference to a local file (foo.json)
"ref_7_1.*", // external reference (remote URI)
"unknownKeyword_.*", // we don't handle `$id` at all, yet
})]
fn translation_typecheck_test(
Expand Down Expand Up @@ -54,5 +85,15 @@ fn translation_typecheck_test(
.unwrap()
.eval_full();

assert_eq!(test_case.is_valid, actual.is_ok(), "got: {:#?}", actual);
match (test_case.is_valid, actual) {
(true, Ok(_)) => {}
(true, Err(e)) => panic!("expected success, got evaluation error {e:#?}"),
// For now, experience shows that a contract failure can be one of those three errors:
// field missing, missing field def, or generic contract error (blame error)
(false, Err(Error::EvalError(EvalError::BlameError { .. })))
| (false, Err(Error::EvalError(EvalError::MissingFieldDef { .. })))
| (false, Err(Error::EvalError(EvalError::FieldMissing(..)))) => {}
(false, Ok(_)) => panic!("expected blame error, got success"),
(false, Err(e)) => panic!("expected blame error, got different error {e:#?}"),
}
}

0 comments on commit c78c9fd

Please sign in to comment.