From 670d5a6195859739200b1a733fcd858e30dda3cb Mon Sep 17 00:00:00 2001 From: ochafik Date: Sat, 22 Jun 2024 21:11:42 +0100 Subject: [PATCH] json: add integration tests for min/max bounds --- tests/test-grammar-integration.cpp | 160 ++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/tests/test-grammar-integration.cpp b/tests/test-grammar-integration.cpp index 5d5fe8783..28b151366 100644 --- a/tests/test-grammar-integration.cpp +++ b/tests/test-grammar-integration.cpp @@ -922,7 +922,6 @@ static void test_json_schema() { } ); - test_schema( "min+max items", // Schema @@ -949,6 +948,165 @@ 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) test_schema( "object properties",