reshuffle/merge min/max integ test cases

This commit is contained in:
ochafik 2024-06-24 21:28:58 +01:00
parent d7d957dbe9
commit 3a80d1e1b3

View file

@ -152,7 +152,7 @@ static void test_schema(const std::string & test_desc, const std::string & schem
static void test_simple_grammar() { static void test_simple_grammar() {
test_schema( test_schema(
"simple min 0", "min 0",
R"""({ R"""({
"type": "integer", "type": "integer",
"minimum": 0 "minimum": 0
@ -161,6 +161,7 @@ static void test_simple_grammar() {
{ {
"0", "0",
"10", "10",
"12",
"10000", "10000",
}, },
// Failing strings // Failing strings
@ -176,31 +177,36 @@ static void test_simple_grammar() {
} }
); );
test_schema( test_schema(
"simple min 3", "min 2",
// Schema
R"""({ R"""({
"type": "integer", "type": "integer",
"minimum": 3 "minimum": 2
})""", })""",
// Passing strings // Passing strings
{ {
"2",
"3", "3",
"4", "4",
"10", "10",
"20", "20",
"1234567890000000",
}, },
// Failing strings // Failing strings
{ {
"0",
"1",
"-1", "-1",
"-100", "-100",
"0", "0",
"1", "1",
"2",
"01", "01",
"02", "02",
"12345678900000000",
} }
); );
test_schema( test_schema(
"simple min 456", "min 456",
R"""({ R"""({
"type": "integer", "type": "integer",
"minimum": 456 "minimum": 456
@ -224,7 +230,94 @@ static void test_simple_grammar() {
} }
); );
test_schema( test_schema(
"simple min -1 max 1", "min -123",
R"""({
"type": "integer",
"minimum": -123
})""",
// Passing strings
{
"-123",
"-122",
"-11",
"-1",
"0",
"1",
"123",
"1234",
"2345",
},
// Failing strings
{
"-1234",
"-124",
}
);
test_schema(
"max 9999",
// Schema
R"""({
"type": "integer",
"maximum": 9999
})""",
// Passing strings
{
"-99999",
"0",
"9999",
},
// Failing strings
{
"10000",
"99991",
}
);
test_schema(
"max -9999",
// Schema
R"""({
"type": "integer",
"maximum": -9999
})""",
// Passing strings
{
"-10000",
"-9999",
},
// Failing strings
{
"-9998",
"0",
"9999",
}
);
test_schema(
"min 5 max 30",
// Schema
R"""({
"type": "integer",
"minimum": 5,
"maximum": 30
})""",
// Passing strings
{
"5",
"10",
"30",
},
// Failing strings
{
"05",
"4",
"-1",
"31",
"123",
"0123",
}
);
test_schema(
"min -1 max 1",
R"""({ R"""({
"type": "integer", "type": "integer",
"minimum": -1, "minimum": -1,
@ -247,7 +340,7 @@ static void test_simple_grammar() {
} }
); );
test_schema( test_schema(
"simple min -123 max 42", "min -123 max 42",
R"""({ R"""({
"type": "integer", "type": "integer",
"minimum": -123, "minimum": -123,
@ -257,43 +350,48 @@ static void test_simple_grammar() {
{ {
"-123", "-123",
"-122", "-122",
"-13",
"-11", "-11",
"-2",
"-1", "-1",
"0", "0",
"1", "1",
"5",
"10", "10",
"39", "39",
"40",
"42", "42",
}, },
// Failing strings // Failing strings
{ {
"-0123",
"-124", "-124",
"-1123",
"-200",
"43", "43",
"123", "123",
"0123",
} }
); );
test_schema( test_schema(
"simple min -123", "exclusive min / max",
// Schema
R"""({ R"""({
"type": "integer", "type": "integer",
"minimum": -123 "exclusiveMinimum": 0,
"exclusiveMaximum": 10000
})""", })""",
// Passing strings // Passing strings
{ {
"-123",
"-122",
"-11",
"-1",
"0",
"1", "1",
"123", "9999",
"1234",
"2345",
}, },
// Failing strings // Failing strings
{ {
"-1234", "0",
"-124", "01",
"10000",
"99999",
} }
); );
@ -948,165 +1046,6 @@ static void test_json_schema() {
} }
); );
test_schema(
"min -123 max 42",
// Schema
R"""({
"type": "integer",
"minimum": -123,
"maximum": 42
})""",
// Passing strings
{
"-123",
"-13",
"-12",
"-2",
"-1",
"0",
"1",
"5",
"40",
"42",
},
// Failing strings
{
"-0123",
"-124",
"-1123",
"-200",
"43",
"123",
"0123",
}
);
test_schema(
"min 5 max 30",
// Schema
R"""({
"type": "integer",
"minimum": 5,
"maximum": 30
})""",
// Passing strings
{
"5",
"10",
"30",
},
// Failing strings
{
"05",
"4",
"-1",
"31",
"123",
"0123",
}
);
test_schema(
"min 2",
// Schema
R"""({
"type": "integer",
"minimum": 2
})""",
// Passing strings
{
"2",
"1234567890000000",
},
// Failing strings
{
"0",
"1",
"12345678900000000",
}
);
test_schema(
"min 0",
// Schema
R"""({
"type": "integer",
"minimum": 0
})""",
// Passing strings
{
"0",
"12",
},
// Failing strings
{
"-1",
"01",
}
);
test_schema(
"max 9999",
// Schema
R"""({
"type": "integer",
"maximum": 9999
})""",
// Passing strings
{
"-99999",
"0",
"9999",
},
// Failing strings
{
"10000",
"99991",
}
);
test_schema(
"max -9999",
// Schema
R"""({
"type": "integer",
"maximum": -9999
})""",
// Passing strings
{
"-10000",
"-9999",
},
// Failing strings
{
"-9998",
"0",
"9999",
}
);
test_schema(
"exclusive min / max",
// Schema
R"""({
"type": "integer",
"exclusiveMinimum": 0,
"exclusiveMaximum": 10000
})""",
// Passing strings
{
"1",
"9999",
},
// Failing strings
{
"0",
"01",
"10000",
"99999",
}
);
// Properties (from: https://json-schema.org/understanding-json-schema/reference/object#properties) // Properties (from: https://json-schema.org/understanding-json-schema/reference/object#properties)
test_schema( test_schema(
"object properties", "object properties",