Software /
code /
prosody
Annotate
spec/util_jsonschema_spec.lua @ 12984:f08125a8be34
util.format: Restore "freeze" serialization behavior in logging
This was implied with the "debug" preset and does nice things like turn
util.set objects into "set{a,b,c}" instead of the quite verbose thing
you get otherwise.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 26 Mar 2023 00:33:20 +0100 |
parent | 12944:05ec70a9f755 |
child | 12988:8592770be63a |
rev | line source |
---|---|
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local js = require "util.jsonschema"; |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local json = require "util.json"; |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local lfs = require "lfs"; |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
12944
05ec70a9f755
util.jsonschema: Disable some further new failing tests
Kim Alvefur <zash@zash.se>
parents:
12943
diff
changeset
|
5 -- https://github.com/json-schema-org/JSON-Schema-Test-Suite.git 2.0.0-724-g19947ea |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local test_suite_dir = "spec/JSON-Schema-Test-Suite/tests/draft2020-12" |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 if lfs.attributes(test_suite_dir, "mode") ~= "directory" then return end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 -- Tests to skip and short reason why (NYI = not yet implemented) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local skip = { |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 ["additionalProperties.json:0:2"] = "distinguishing objects from arrays", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 ["additionalProperties.json:0:5"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 ["additionalProperties.json:1:0"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 ["anchor.json"] = "$anchor NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 ["const.json:1"] = "deepcompare", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 ["const.json:13:2"] = "IEEE 754 equality", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 ["const.json:2"] = "deepcompare", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 ["const.json:8"] = "deepcompare", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 ["const.json:9"] = "deepcompare", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 ["contains.json:0:5"] = "distinguishing objects from arrays", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 ["defs.json"] = "need built-in meta-schema", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 ["dependentRequired.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 ["dependentSchemas.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 ["dynamicRef.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 ["enum.json:1:3"] = "deepcompare", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 ["id.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 ["maxContains.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 ["maxLength.json:0:4"] = "UTF-16", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 ["maxProperties.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 ["minContains.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 ["minLength.json:0:4"] = "UTF-16", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 ["minProperties.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 ["multipleOf.json:1"] = "multiples of IEEE 754 fractions", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 ["multipleOf.json:2"] = "multiples of IEEE 754 fractions", |
12944
05ec70a9f755
util.jsonschema: Disable some further new failing tests
Kim Alvefur <zash@zash.se>
parents:
12943
diff
changeset
|
35 ["multipleOf.json:4"] = "multiples of IEEE 754 fractions", |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 ["pattern.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 ["patternProperties.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 ["properties.json:1:2"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 ["properties.json:1:3"] = "NYI", |
12756
cd7da871ce10
util.jsonschema: Sort test cases to skip
Kim Alvefur <zash@zash.se>
parents:
12579
diff
changeset
|
40 ["ref.json:0:3"] = "NYI additionalProperties", |
cd7da871ce10
util.jsonschema: Sort test cases to skip
Kim Alvefur <zash@zash.se>
parents:
12579
diff
changeset
|
41 ["ref.json:11"] = "NYI", |
cd7da871ce10
util.jsonschema: Sort test cases to skip
Kim Alvefur <zash@zash.se>
parents:
12579
diff
changeset
|
42 ["ref.json:12:1"] = "FIXME", |
cd7da871ce10
util.jsonschema: Sort test cases to skip
Kim Alvefur <zash@zash.se>
parents:
12579
diff
changeset
|
43 ["ref.json:13"] = "NYI", |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 ["ref.json:14"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 ["ref.json:15"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 ["ref.json:16"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 ["ref.json:17"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 ["ref.json:18"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 ["ref.json:19"] = "NYI", |
12757
edbc888b1e05
util.jsonschema: Ignore some further test cases for URI references
Kim Alvefur <zash@zash.se>
parents:
12756
diff
changeset
|
50 ["ref.json:26"] = "NYI", |
edbc888b1e05
util.jsonschema: Ignore some further test cases for URI references
Kim Alvefur <zash@zash.se>
parents:
12756
diff
changeset
|
51 ["ref.json:27"] = "NYI", |
edbc888b1e05
util.jsonschema: Ignore some further test cases for URI references
Kim Alvefur <zash@zash.se>
parents:
12756
diff
changeset
|
52 ["ref.json:28"] = "NYI", |
12756
cd7da871ce10
util.jsonschema: Sort test cases to skip
Kim Alvefur <zash@zash.se>
parents:
12579
diff
changeset
|
53 ["ref.json:3:2"] = "FIXME investigate, util.jsonpath issue?", |
12758
7929c0ffbe14
util.jsonschema: Ignore test case for JavaScript specific detail
Kim Alvefur <zash@zash.se>
parents:
12757
diff
changeset
|
54 ["required.json:4"] = "JavaScript specific and distinguishing objects from arrays", |
12756
cd7da871ce10
util.jsonschema: Sort test cases to skip
Kim Alvefur <zash@zash.se>
parents:
12579
diff
changeset
|
55 ["ref.json:6:1"] = "NYI", |
12757
edbc888b1e05
util.jsonschema: Ignore some further test cases for URI references
Kim Alvefur <zash@zash.se>
parents:
12756
diff
changeset
|
56 ["ref.json:20"] = "NYI", |
edbc888b1e05
util.jsonschema: Ignore some further test cases for URI references
Kim Alvefur <zash@zash.se>
parents:
12756
diff
changeset
|
57 ["ref.json:25"] = "NYI", |
12943
297b4cfcc3d9
util.jsonschema: Ignore some new tests in test suite
Kim Alvefur <zash@zash.se>
parents:
12758
diff
changeset
|
58 ["ref.json:29"] = "NYI", |
297b4cfcc3d9
util.jsonschema: Ignore some new tests in test suite
Kim Alvefur <zash@zash.se>
parents:
12758
diff
changeset
|
59 ["ref.json:30"] = "NYI", |
297b4cfcc3d9
util.jsonschema: Ignore some new tests in test suite
Kim Alvefur <zash@zash.se>
parents:
12758
diff
changeset
|
60 ["ref.json:31"] = "NYI", |
12944
05ec70a9f755
util.jsonschema: Disable some further new failing tests
Kim Alvefur <zash@zash.se>
parents:
12943
diff
changeset
|
61 ["ref.json:32"] = "NYI", |
05ec70a9f755
util.jsonschema: Disable some further new failing tests
Kim Alvefur <zash@zash.se>
parents:
12943
diff
changeset
|
62 ["not.json:6"] = "NYI", |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 ["refRemote.json"] = "DEFINITELY NYI", |
12756
cd7da871ce10
util.jsonschema: Sort test cases to skip
Kim Alvefur <zash@zash.se>
parents:
12579
diff
changeset
|
64 ["required.json:0:2"] = "distinguishing objects from arrays", |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 ["type.json:3:4"] = "distinguishing objects from arrays", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 ["type.json:3:6"] = "null is weird", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 ["type.json:4:3"] = "distinguishing objects from arrays", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 ["type.json:4:6"] = "null is weird", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 ["type.json:9:4"] = "null is weird", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 ["type.json:9:6"] = "null is weird", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 ["unevaluatedItems.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 ["unevaluatedProperties.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 ["uniqueItems.json:0:11"] = "deepcompare", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 ["uniqueItems.json:0:13"] = "deepcompare", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 ["uniqueItems.json:0:14"] = "deepcompare", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 ["uniqueItems.json:0:22"] = "deepcompare", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 ["uniqueItems.json:0:24"] = "deepcompare", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 ["uniqueItems.json:0:9"] = "deepcompare", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 ["unknownKeyword.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 ["vocabulary.json"] = "NYI", |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 }; |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 local function label(s, i) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 return string.format("%s:%d", s, i-1); |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 describe("util.jsonschema.validate", function() |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 for test_case_file in lfs.dir(test_suite_dir) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 -- print(skip[test_case_file] and "do " or "skip", test_case_file) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 if test_case_file:sub(-5) == ".json" and not skip[test_case_file] then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 describe(test_case_file, function() |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 local test_cases; |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 setup(function() |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 local f = assert(io.open(test_suite_dir .. "/" .. test_case_file)); |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 local rawdata = assert(f:read("*a"), "failed to read " .. test_case_file) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 test_cases = assert(json.decode(rawdata), "failed to parse " .. test_case_file) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 end) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 describe("tests", function() |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 for i, schema_test in ipairs(test_cases) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 local generic_label = label(test_case_file, i); |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 describe(schema_test.description or generic_label, function() |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 for j, test in ipairs(schema_test.tests) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 local specific_label = label(generic_label, j); |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 ((skip[generic_label] or skip[specific_label]) and pending or it)(test.description, function() |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 assert.equal(test.valid, js.validate(schema_test.schema, test.data), specific_label .. " " .. test.description); |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 end) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 end) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 end) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 end) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 end); |