diff --git a/common/json-schema-to-grammar.cpp b/common/json-schema-to-grammar.cpp index 42faa8adb..d6346913a 100644 --- a/common/json-schema-to-grammar.cpp +++ b/common/json-schema-to-grammar.cpp @@ -202,6 +202,7 @@ static void _generate_min_max_int(int min_value, int max_value, std::stringstrea } auto sub_len = from.length() - i - 1; if (sub_len > 0) { + out << "("; auto from_sub = from.substr(i + 1); auto to_sub = to.substr(i + 1); auto sub_zeros = repeat("0", sub_len); @@ -235,6 +236,7 @@ static void _generate_min_max_int(int min_value, int max_value, std::stringstrea out << " "; uniform_range(sub_zeros, to_sub); } + out << ")"; } else { out << "[" << from[i] << "-" << to[i] << "]"; } diff --git a/tests/test-grammar-integration.cpp b/tests/test-grammar-integration.cpp index ca9b9c110..6aca32a39 100644 --- a/tests/test-grammar-integration.cpp +++ b/tests/test-grammar-integration.cpp @@ -150,6 +150,29 @@ static void test_simple_grammar() { "100000000000000000000000000000000", } ); + test_schema( + "simple min -1 max 1", + R"""({ + "type": "integer", + "minimum": -1, + "maximum": 1 + })""", + // Passing strings + { + "-1", + "0", + "1", + }, + // Failing strings + { + "-11", + "-10", + "-2", + "2", + "10", + "11", + } + ); test_schema( "simple min -123 max 42", R"""({ diff --git a/tests/test-json-schema-to-grammar.cpp b/tests/test-json-schema-to-grammar.cpp index e2a96d25c..ba6000ae0 100755 --- a/tests/test-json-schema-to-grammar.cpp +++ b/tests/test-json-schema-to-grammar.cpp @@ -166,7 +166,7 @@ static void test_all(const std::string & lang, std::function