reformat grammar integ tests w/ R"""()""" strings where there's escapes
This commit is contained in:
parent
f714d7f1a7
commit
3c64db18d7
1 changed files with 130 additions and 164 deletions
|
@ -508,7 +508,7 @@ static void test_json_schema() {
|
|||
)""",
|
||||
// Passing strings
|
||||
{
|
||||
"{}",
|
||||
R"""({})""",
|
||||
R"""({"foo": "bar"})""",
|
||||
},
|
||||
// Failing strings
|
||||
|
@ -516,7 +516,7 @@ static void test_json_schema() {
|
|||
"",
|
||||
"[]",
|
||||
"null",
|
||||
"\"\"",
|
||||
R"""("")""",
|
||||
"true",
|
||||
}
|
||||
);
|
||||
|
@ -524,16 +524,14 @@ static void test_json_schema() {
|
|||
test_schema(
|
||||
"exotic formats (list)",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"items": [
|
||||
{ "format": "date" },
|
||||
{ "format": "uuid" },
|
||||
{ "format": "time" },
|
||||
{ "format": "date-time" }
|
||||
]
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
// "{}", // NOTE: This string passes for this schema on https://www.jsonschemavalidator.net/ -- should it?
|
||||
|
@ -552,125 +550,113 @@ static void test_json_schema() {
|
|||
test_schema(
|
||||
"string",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"type": "string"
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"\"foo\"",
|
||||
"\"bar\"",
|
||||
"\"\"",
|
||||
R"""("foo")""",
|
||||
R"""("bar")""",
|
||||
R"""("")""",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"{}",
|
||||
"\"foo\": \"bar\"",
|
||||
R"""({})""",
|
||||
R"""("foo": "bar")""",
|
||||
}
|
||||
);
|
||||
|
||||
test_schema(
|
||||
"string w/ min length 1",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"\"foo\"",
|
||||
"\"bar\"",
|
||||
R"""("foo")""",
|
||||
R"""("bar")""",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"\"\"",
|
||||
"{}",
|
||||
"\"foo\": \"bar\"",
|
||||
R"""("")""",
|
||||
R"""({})""",
|
||||
R"""("foo": "bar")""",
|
||||
}
|
||||
);
|
||||
|
||||
test_schema(
|
||||
"string w/ min length 3",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"type": "string",
|
||||
"minLength": 3
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"\"foo\"",
|
||||
"\"bar\"",
|
||||
"\"foobar\"",
|
||||
R"""("foo")""",
|
||||
R"""("bar")""",
|
||||
R"""("foobar")""",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"\"\"",
|
||||
"\"f\"",
|
||||
"\"fo\"",
|
||||
R"""("")""",
|
||||
R"""("f")""",
|
||||
R"""("fo")""",
|
||||
}
|
||||
);
|
||||
|
||||
test_schema(
|
||||
"string w/ max length",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"type": "string",
|
||||
"maxLength": 3
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"\"foo\"",
|
||||
"\"bar\"",
|
||||
"\"\"",
|
||||
"\"f\"",
|
||||
"\"fo\"",
|
||||
R"""("foo")""",
|
||||
R"""("bar")""",
|
||||
R"""("")""",
|
||||
R"""("f")""",
|
||||
R"""("fo")""",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"\"foobar\"",
|
||||
R"""("foobar")""",
|
||||
}
|
||||
);
|
||||
|
||||
test_schema(
|
||||
"string w/ min & max length",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 4
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"\"foo\"",
|
||||
"\"bar\"",
|
||||
"\"f\"",
|
||||
"\"barf\"",
|
||||
R"""("foo")""",
|
||||
R"""("bar")""",
|
||||
R"""("f")""",
|
||||
R"""("barf")""",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"\"\"",
|
||||
"\"barfo\"",
|
||||
"\"foobar\"",
|
||||
R"""("")""",
|
||||
R"""("barfo")""",
|
||||
R"""("foobar")""",
|
||||
}
|
||||
);
|
||||
|
||||
test_schema(
|
||||
"boolean",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"type": "boolean"
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"true",
|
||||
|
@ -678,96 +664,88 @@ static void test_json_schema() {
|
|||
},
|
||||
// Failing strings
|
||||
{
|
||||
"\"\"",
|
||||
"\"true\"",
|
||||
"True",
|
||||
"FALSE",
|
||||
R"""("")""",
|
||||
R"""("true")""",
|
||||
R"""(True)""",
|
||||
R"""(FALSE)""",
|
||||
}
|
||||
);
|
||||
|
||||
test_schema(
|
||||
"integer",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"type": "integer"
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"0",
|
||||
"12345",
|
||||
"1234567890123456"
|
||||
R"""(0)""",
|
||||
R"""(12345)""",
|
||||
R"""(1234567890123456)""",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"",
|
||||
"01",
|
||||
"007",
|
||||
"12345678901234567"
|
||||
R"""()""",
|
||||
R"""(01)""",
|
||||
R"""(007)""",
|
||||
R"""(12345678901234567 )""",
|
||||
}
|
||||
);
|
||||
|
||||
test_schema(
|
||||
"string const",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"const": "foo"
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"\"foo\"",
|
||||
R"""("foo")""",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"foo",
|
||||
"\"bar\"",
|
||||
R"""(foo)""",
|
||||
R"""("bar")""",
|
||||
}
|
||||
);
|
||||
|
||||
test_schema(
|
||||
"non-string const",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"const": true
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"true",
|
||||
R"""(true)""",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"",
|
||||
"foo",
|
||||
"\"true\"",
|
||||
R"""()""",
|
||||
R"""(foo)""",
|
||||
R"""("true")""",
|
||||
}
|
||||
);
|
||||
|
||||
test_schema(
|
||||
"non-string const",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"enum": ["red", "amber", "green", null, 42, ["foo"]]
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"\"red\"",
|
||||
"null",
|
||||
"42",
|
||||
"[\"foo\"]",
|
||||
R"""("red")""",
|
||||
R"""(null)""",
|
||||
R"""(42)""",
|
||||
R"""(["foo"])""",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"",
|
||||
"420",
|
||||
"true",
|
||||
"foo",
|
||||
R"""()""",
|
||||
R"""(420)""",
|
||||
R"""(true)""",
|
||||
R"""(foo)""",
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -775,26 +753,24 @@ static void test_json_schema() {
|
|||
test_schema(
|
||||
"min+max items",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"items": {
|
||||
"type": ["number", "integer"]
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 5
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"[1, 2, 3]",
|
||||
"[1, 2, 3, 4]",
|
||||
"[1, 2, 3, 4, 5]",
|
||||
R"""([1, 2, 3])""",
|
||||
R"""([1, 2, 3, 4])""",
|
||||
R"""([1, 2, 3, 4, 5])""",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"[1, 2]",
|
||||
"[1, 2, 3, 4, 5, 6]",
|
||||
"1"
|
||||
R"""([1, 2])""",
|
||||
R"""([1, 2, 3, 4, 5, 6])""",
|
||||
R"""(1)""",
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -802,16 +778,14 @@ static void test_json_schema() {
|
|||
test_schema(
|
||||
"object properties",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"number": { "type": "number" },
|
||||
"street_name": { "type": "string" },
|
||||
"street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
|
||||
}
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type":"Avenue"})""",
|
||||
|
@ -846,16 +820,16 @@ static void test_json_schema() {
|
|||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"{\"a\": 42}",
|
||||
"{\"c\": \"\"}",
|
||||
"{\"a\": 42, \"c\": \"\"}",
|
||||
"{\"a_\": \"\"}",
|
||||
R"""({"a": 42})""",
|
||||
R"""({"c": ""})""",
|
||||
R"""({"a": 42, "c": ""})""",
|
||||
R"""({"a_": ""})""",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"",
|
||||
"{\"a\": \"\"}",
|
||||
"{\"a\": \"\", \"b\": \"\"}",
|
||||
R"""()""",
|
||||
R"""({"a": ""})""",
|
||||
R"""({"a": "", "b": ""})""",
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -863,8 +837,7 @@ static void test_json_schema() {
|
|||
test_schema(
|
||||
"object properties, additionalProperties: true",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"number": { "type": "number" },
|
||||
|
@ -872,8 +845,7 @@ static void test_json_schema() {
|
|||
"street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
|
||||
},
|
||||
"additionalProperties": true
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
// "By extension, even an empty object is valid"
|
||||
|
@ -899,8 +871,7 @@ static void test_json_schema() {
|
|||
test_schema(
|
||||
"required + optional props each in original order",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"number": { "type": "number" },
|
||||
|
@ -908,8 +879,7 @@ static void test_json_schema() {
|
|||
"street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
R"""({ "street_name": "Pennsylvania" })""",
|
||||
|
@ -931,8 +901,7 @@ static void test_json_schema() {
|
|||
test_schema(
|
||||
"required + optional props each in original order",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"properties": {
|
||||
"b": {"type": "string"},
|
||||
"a": {"type": "string"},
|
||||
|
@ -941,8 +910,7 @@ static void test_json_schema() {
|
|||
},
|
||||
"required": ["a", "b"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
R"""({"b": "foo", "a": "bar"})""",
|
||||
|
@ -962,8 +930,7 @@ static void test_json_schema() {
|
|||
test_schema(
|
||||
"required props",
|
||||
// Schema
|
||||
R"""(
|
||||
{
|
||||
R"""({
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://example.com/product.schema.json",
|
||||
"title": "Product",
|
||||
|
@ -1009,8 +976,7 @@ static void test_json_schema() {
|
|||
}
|
||||
},
|
||||
"required": [ "productId", "productName", "price" ]
|
||||
}
|
||||
)""",
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
R"""({"productId": 1, "productName": "A green door", "price": 12.50})""",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue