Skip to content

Commit bc8b37e

Browse files
authored
Exercise to_json() on the Evaluator test suite (#462)
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent fb7abeb commit bc8b37e

File tree

7 files changed

+91
-193
lines changed

7 files changed

+91
-193
lines changed

DEPENDENCIES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4
2-
core https://github.com/sourcemeta/core 2aab6820e4b4ff7062954c7ee4f55aea04112496
2+
core https://github.com/sourcemeta/core 44f603669e1e0219d251a647b97df8213ffb7e45
33
jsonschema-test-suite https://github.com/json-schema-org/JSON-Schema-Test-Suite 48461fc3568972801b40eaccc428a31bce338f6e

src/compiler/compile_json.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ template <typename T>
1313
auto to_json(const T &) -> JSON {
1414
return JSON{nullptr};
1515
}
16-
template <typename T>
17-
requires std::is_same_v<T, sourcemeta::blaze::ValueRegex>
18-
auto to_json(const T &value) -> JSON {
19-
return JSON{value.second};
20-
}
2116
} // namespace sourcemeta::core
2217

2318
namespace sourcemeta::blaze {

test/compiler/compiler_json_test.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,38 @@ TEST(Compiler_JSON, example_2) {
102102

103103
EXPECT_EQ(result, expected);
104104
}
105+
106+
TEST(Compiler_JSON, example_3) {
107+
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
108+
"$schema": "https://json-schema.org/draft/2020-12/schema",
109+
"pattern": "^f"
110+
})JSON")};
111+
112+
const auto schema_template{sourcemeta::blaze::compile(
113+
schema, sourcemeta::core::schema_official_walker,
114+
sourcemeta::core::schema_official_resolver,
115+
sourcemeta::blaze::default_schema_compiler)};
116+
117+
const auto result{sourcemeta::blaze::to_json(schema_template)};
118+
119+
const sourcemeta::core::JSON expected{sourcemeta::core::parse_json(R"JSON({
120+
"dynamic": false,
121+
"track": false,
122+
"instructions": [
123+
{
124+
"t": 19,
125+
"s": "/pattern",
126+
"i": "",
127+
"k": "#/pattern",
128+
"r": 0,
129+
"v": {
130+
"t": 9,
131+
"v": [ null, "^f" ]
132+
},
133+
"c": []
134+
}
135+
]
136+
})JSON")};
137+
138+
EXPECT_EQ(result, expected);
139+
}

test/evaluator/evaluator_utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ inline auto FIRST_PROPERTY_IS(const sourcemeta::core::JSON &document,
4646
sourcemeta::core::schema_official_resolver, \
4747
sourcemeta::blaze::default_schema_compiler, \
4848
sourcemeta::blaze::Mode::FastValidation)}; \
49+
EXPECT_TRUE(sourcemeta::blaze::to_json(compiled_schema).is_object()); \
4950
EVALUATE_WITH_TRACE(compiled_schema, instance, count) \
5051
EXPECT_TRUE(result);
5152

@@ -55,6 +56,7 @@ inline auto FIRST_PROPERTY_IS(const sourcemeta::core::JSON &document,
5556
sourcemeta::core::schema_official_resolver, \
5657
sourcemeta::blaze::default_schema_compiler, \
5758
sourcemeta::blaze::Mode::FastValidation)}; \
59+
EXPECT_TRUE(sourcemeta::blaze::to_json(compiled_schema).is_object()); \
5860
EVALUATE_WITH_TRACE(compiled_schema, instance, count) \
5961
EXPECT_FALSE(result);
6062

@@ -64,6 +66,7 @@ inline auto FIRST_PROPERTY_IS(const sourcemeta::core::JSON &document,
6466
sourcemeta::core::schema_official_resolver, \
6567
sourcemeta::blaze::default_schema_compiler, \
6668
sourcemeta::blaze::Mode::Exhaustive)}; \
69+
EXPECT_TRUE(sourcemeta::blaze::to_json(compiled_schema).is_object()); \
6770
EVALUATE_WITH_TRACE(compiled_schema, instance, count) \
6871
EXPECT_TRUE(result);
6972

@@ -73,6 +76,7 @@ inline auto FIRST_PROPERTY_IS(const sourcemeta::core::JSON &document,
7376
sourcemeta::core::schema_official_resolver, \
7477
sourcemeta::blaze::default_schema_compiler, \
7578
sourcemeta::blaze::Mode::Exhaustive)}; \
79+
EXPECT_TRUE(sourcemeta::blaze::to_json(compiled_schema).is_object()); \
7680
EVALUATE_WITH_TRACE(compiled_schema, instance, count) \
7781
EXPECT_FALSE(result);
7882

vendor/core/src/core/json/include/sourcemeta/core/json_auto.h

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/core/src/core/jsonschema/frame.cc

Lines changed: 39 additions & 174 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)