Update test-grammar-integration.cpp

This commit is contained in:
ochafik 2024-06-28 22:28:43 +01:00
parent 9c05bd26fb
commit 7f227d279d

View file

@ -1303,44 +1303,41 @@ static void test_json_schema() {
); );
test_schema( test_schema(
"refs", "nested refs + mix of properties and allOf",
// Schema // Schema
R"""({ R"""({
"type": "array",
"minItems": 1,
"maxItems": 15,
"items": { "$ref": "#/$defs/TALK" },
"$defs": {
"characters": { "enum": ["Biff", "Alice"] },
"emotes": { "enum": ["EXCLAMATION", "CONFUSION", "CHEERFUL", "LOVE", "ANGRY"] },
"TALK": {
"type": "object",
"required": [ "character", "emote", "dialog" ],
"properties": { "properties": {
"character": { "$ref": "#/$defs/characters" }, "common": {"$ref": "#/$defs/SomeVal"}
"emote": { "$ref": "#/$defs/emotes" },
"dialog": {
"type": "string",
"minLength": 1,
"maxLength": 200
}
}, },
"additionalProperties": false "allOf": [
{"$ref": "#/$defs/foo"},
{"$ref": "#/$defs/bar"},
{
"anyOf": [
{"$ref": "#/$defs/baz"},
{"$ref": "#/$defs/bam"}
]
} }
],
"required": ["common"],
"$defs": {
"SomeVal": {"type": "number"},
"foo": {"properties": {"a": {"$ref": "#/$defs/SomeVal"}}},
"bar": {"properties": {"b": {"$ref": "#/$defs/SomeVal"}}},
"bam": {"properties": {"c": {"$ref": "#/$defs/SomeVal"}}},
"baz": {"properties": {"d": {"$ref": "#/$defs/SomeVal"}}}
} }
})""", })""",
// Passing strings // Passing strings
{ {
R"""([{ R"""({"common": "", "a": "", "b": ""})""",
"character": "Alice", R"""({"common": "", "a": "", "b": "", "d": "", "c": ""})""",
"emote": "EXCLAMATION",
"dialog": "Hello, world!"
}])""",
}, },
// Failing strings // Failing strings
{ {
R"""({})""",
R"""({"a": "", "b": ""})""",
R"""({"common": "", "a": "", "b": "", "c": "", "d": ""})""",
} }
); );
} }