Debian Codegraph @

tests/wasm.rs

raw symbols SCIP
1 #![cfg(all(target_arch = "wasm32", target_os = "unknown"))]
2
3 use jsonschemarust-analyzer cargo jsonschema 0.37.4 crate/::{selfrust-analyzer cargo jsonschema 0.37.4 crate/, Draftrust-analyzer cargo referencing 0.37.4 specification/Draft#};
4 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::jsonrust-analyzer cargo serde_json 1.0.145 macros/json!;
5 use wasm_bindgen_test::wasm_bindgen_test;
6
7 #[wasm_bindgen_test]
8 fn validates_simple_object_instances() {
9 let schema = json!({
10 "type": "object",
11 "properties": {
12 "name": { "type": "string" },
13 "age": { "type": "integer", "minimum": 0 }
14 },
15 "required": ["name"]
16 });
17
18 let validator = jsonschemarust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&schema).expect("valid schema");
19
20 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_valid(&json!({"name": "Ferris", "age": 7})));
21 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!validator.is_valid(&json!({"name": 9, "age": 7})));
22 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!validator.is_valid(&json!({"age": 7})));
23 }
24
25 #[wasm_bindgen_test]
26 fn validates_formats_with_options() {
27 let options = jsonschemarust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options/()
28 .with_draft(Draft::Draft202012)
29 .should_validate_formats(true);
30 let validator = options
31 .build(&json!({"type": "string", "format": "email"}))
32 .expect("schema builds");
33
34 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_valid(&json!("[email protected]")));
35 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!validator.is_valid(&json!("definitely not an email")));
36 }
37
38 #[wasm_bindgen_test]
39 fn validates_uuid_format() {
40 let options = jsonschemarust-analyzer cargo jsonschema 0.37.4 crate/::optionsrust-analyzer cargo jsonschema 0.37.4 options/()
41 .with_draft(Draft::Draft202012)
42 .should_validate_formats(true);
43 let validator = options
44 .build(&json!({"type": "string", "format": "uuid"}))
45 .expect("schema builds");
46
47 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validator.is_valid(&json!("67e55044-10b1-426f-9247-bb680e5fe0c8")));
48 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!validator.is_valid(&json!("67e5504410b1426f9247bb680e5fe0c8"))); // missing hyphens
49 }