json: fix negative min (w/ more than 1 digit)
This commit is contained in:
parent
931b543607
commit
4c1c29361e
3 changed files with 41 additions and 3 deletions
|
@ -276,9 +276,9 @@ static void _generate_min_max_int(int min_value, int max_value, std::stringstrea
|
|||
|
||||
if (has_min) {
|
||||
if (min_value < 0) {
|
||||
out << "\"-\" ";
|
||||
out << "\"-\" (";
|
||||
_generate_min_max_int(std::numeric_limits<int>::min(), -min_value, out, decimals_left, /* top_level= */ false);
|
||||
out << " | [0] | [1-9] ";
|
||||
out << ") | [0] | [1-9] ";
|
||||
more_digits(0, decimals_left - 1);
|
||||
} else if (min_value == 0) {
|
||||
if (top_level) {
|
||||
|
|
|
@ -199,6 +199,30 @@ static void test_simple_grammar() {
|
|||
"123",
|
||||
}
|
||||
);
|
||||
test_schema(
|
||||
"simple min -123",
|
||||
R"""({
|
||||
"type": "integer",
|
||||
"minimum": -123
|
||||
})""",
|
||||
// Passing strings
|
||||
{
|
||||
"-123",
|
||||
"-122",
|
||||
"-11",
|
||||
"-1",
|
||||
"0",
|
||||
"1",
|
||||
"123",
|
||||
"1234",
|
||||
"2345",
|
||||
},
|
||||
// Failing strings
|
||||
{
|
||||
"-1234",
|
||||
"-124",
|
||||
}
|
||||
);
|
||||
|
||||
// Test case for a simple grammar
|
||||
test_grammar(
|
||||
|
|
|
@ -179,7 +179,21 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
|
|||
"minimum": -5
|
||||
})""",
|
||||
R"""(
|
||||
root ::= ("-" [0-5] | [0] | [1-9] [0-9]{0,15}) space
|
||||
root ::= ("-" ([0-5]) | [0] | [1-9] [0-9]{0,15}) space
|
||||
space ::= " "?
|
||||
)"""
|
||||
});
|
||||
|
||||
test({
|
||||
SUCCESS,
|
||||
"min -123",
|
||||
R"""({
|
||||
"type": "integer",
|
||||
"minimum": -123
|
||||
})""",
|
||||
R"""(
|
||||
root ::= ("-" ([0-9] | ([1-8] [0-9] | [9] [0-9]) | "1" ([0-1] [0-9] | [2] [0-3])) | [0] | [1-9] [0-9]{0,15}) space
|
||||
space ::= " "?
|
||||
)"""
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue