json: fix missing paren min/max bug

This commit is contained in:
ochafik 2024-05-01 02:23:18 +01:00
parent af63f4fb27
commit a381deb1b6
2 changed files with 41 additions and 1 deletions

View file

@ -214,6 +214,7 @@ static void _generate_min_max_int(int min_value, int max_value, std::stringstrea
more_digits(sub_len, sub_len);
} else {
out << "[" << from[i] << "] ";
out << "(";
uniform_range(from_sub, sub_nines);
if (from[i] < to[i] - 1) {
out << " | ";
@ -226,6 +227,7 @@ static void _generate_min_max_int(int min_value, int max_value, std::stringstrea
out << " ";
more_digits(sub_len, sub_len);
}
out << ")";
}
if (!to_reached) {
out << " | ";

View file

@ -233,7 +233,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
"maximum": 300
})""",
R"""(
root ::= ([1] [5-9] | [2-9] [0-9] | [1-2] [0-9]{2} | [3] "00") space
root ::= ([1] ([5-9] | [2-9] [0-9]) | [1-2] [0-9]{2} | [3] "00") space
space ::= " "?
)"""
});
@ -576,6 +576,44 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
)"""
});
test({
SUCCESS,
"min + max items with min + max values across zero",
R"""({
"items": {
"type": "integer",
"minimum": -122,
"maximum": 207
},
"minItems": 3,
"maxItems": 5
})""",
R"""(
item ::= ("-" ([0-9] | [1-8] [0-9] | [9] [0-9] | "1" [0-1] [0-9] | [2] [0-2]) | [0-9] | [1-8] [0-9] | [9] [0-9] | [1] [0-9]{2} | [2] "0" [0-7]) space
root ::= "[" space item ("," space item){2,4} "]" space
space ::= " "?
)"""
});
test({
SUCCESS,
"min + max items with min + max values",
R"""({
"items": {
"type": "integer",
"minimum": 122,
"maximum": 207
},
"minItems": 3,
"maxItems": 5
})""",
R"""(
item ::= ([1] ([2] ([2-9] | [3-9] [0-9])) | [2] "0" [0-7]) space
root ::= "[" space item ("," space item){2,4} "]" space
space ::= " "?
)"""
});
test({
SUCCESS,
"simple regexp",