Skip to content

Commit 3bdf7c3

Browse files
committed
Fixing nits from ochafik. Removing escape slashes, adding additional failing cases, fixing some other strings.
1 parent 939b58a commit 3bdf7c3

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

tests/test-grammar-integration.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static void test(const std::string & test_desc, const std::string & grammar_str,
106106
fclose(string_file);
107107
}
108108

109-
fprintf(stderr, "\n NOTE: Debug grammar file generated. To analyze this failure in detail, run the following command: ./gbnf-validator test-grammar-integration.grammar.gbnf test-grammar-integration.string.txt\n\n");
109+
fprintf(stderr, "\n NOTE: Debug grammar file generated. To analyze this failure in detail, run the following command: ./llama-gbnf-validator test-grammar-integration.grammar.gbnf test-grammar-integration.string.txt\n\n");
110110
} else {
111111
fprintf(stdout, "✅︎\n");
112112
}
@@ -510,11 +510,15 @@ static void test_json_schema() {
510510
// Passing strings
511511
{
512512
"{}",
513-
"{\"foo\": \"bar\"}",
513+
R"""({"foo": "bar"})""",
514514
},
515515
// Failing strings
516516
{
517517
"",
518+
"[]",
519+
"null",
520+
"\"\"",
521+
"true",
518522
}
519523
);
520524

@@ -932,16 +936,16 @@ static void test_json_schema() {
932936
)""",
933937
// Passing strings
934938
{
935-
"{\"b\": \"foo\", \"a\": \"bar\"}",
936-
"{\"b\":\"foo\",\"a\":\"bar\",\"d\":\"qux\"}",
937-
"{\"b\":\"foo\", \"a\":\"bar\", \"d\":\"qux\", \"c\":\"baz\"}",
939+
R"""({"b": "foo", "a": "bar"})""",
940+
R"""({"b":"foo","a":"bar","d":"qux"})""",
941+
R"""({"b":"foo", "a":"bar", "d":"qux", "c":"baz"})""",
938942
},
939943
// Failing strings
940944
{
941-
"{\"a\": \"foo\", \"b\": \"bar\"}",
942-
"{\"b\": \"bar\"}",
943-
"{\"a\": \"foo\", \"c\": \"baz\"}",
944-
"{\"a\":\"foo\", \"b\":\"bar\", \"c\":\"baz\", \"d\":\"qux\"}",
945+
R"""({"a": "foo", "b": "bar"})""",
946+
R"""({"b": "bar"})""",
947+
R"""({"a": "foo", "c": "baz"})""",
948+
R"""({"a":"foo", "b":"bar", "c":"baz", "d":"qux"})""",
945949
}
946950
);
947951

@@ -1000,24 +1004,23 @@ static void test_json_schema() {
10001004
)""",
10011005
// Passing strings
10021006
{
1003-
"{\"productId\": 1, \"productName\": \"A green door\", \"price\": 12.50}",
1004-
"{\"productId\": 1, \"productName\": \"A green door\", \"price\": 12.50, \"tags\": [\"home\", \"green\"]}",
1005-
"{\"productId\": 1, \"productName\": \"A green door\", \"price\": 12.50, \"tags\": [\"home\", \"green\"], \"dimensions\": {\"length\": 785, \"width\": 250.5, \"height\": -0.359}}",
1007+
R"""({"productId": 1, "productName": "A green door", "price": 12.50})""",
1008+
R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green"]})""",
1009+
R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green"], "dimensions": {"length": 785, "width": 250.5, "height": -0.359}})""",
10061010
},
10071011
// Failing strings
10081012
{
1009-
"{}", // Missing all required properties
1010-
"{\"productName\": \"A green door\", \"price\": 12.50, \"productId\": 1}", // Out of order properties
1013+
R"""({})""", // Missing all required properties
1014+
R"""({"productName": "A green door", "price": 12.50, "productId": 1})""", // Out of order properties
10111015
// TODO: The following line should fail, but currently it passes. `exclusiveMinimum` is not supported, as it would likely be too difficult to implement.
10121016
// Perhaps special checks for minimum and maximum values of 0 could be added (since that's relatively easy to do with grammars), but anything else would likely be too complex.
1013-
// "{\"productId\": 1, \"productName\": \"A green door\", \"price\": -12.50}",
1014-
"{\"productId\": 1, \"productName\": \"A green door\"}", // Missing required property (price)
1015-
"{\"productName\": \"A green door\", \"price\": 12.50}", // Missing required property (productId)
1016-
"{\"productId\": 1, \"productName\": \"A green door\", \"price\": 12.50, \"tags\": []}", // tags is empty, but minItems is 1
1017-
"{\"productId\": 1, \"productName\": \"A green door\", \"price\": 12.50, \"dimensions\": {\"length\": 785, \"width\": 250.5, \"height\": -0.359}, \"tags\": [\"home\", \"green\"]}", // Tags and dimensions are out of order
1017+
// R"""({"productId": 1, "productName": "A green door", "price": -12.50})""",
1018+
R"""({"productId": 1, "productName": "A green door"})""", // Missing required property (price)
1019+
R"""({"productName": "A green door", "price": 12.50})""", // Missing required property (productId)
1020+
R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": []})""", // tags is empty, but minItems is 1
1021+
R"""({"productId": 1, "productName": "A green door", "price": 12.50, "dimensions": {"length": 785, "width": 250.5, "height": -0.359}, "tags": ["home", "green"]})""", // Tags and dimensions are out of order
10181022
// TODO: The following line should fail, but currently it passes. `uniqueItems` is not supported, as it would likely be too difficult to implement.
1019-
// "{\"productId\": 1, \"productName\": \"A green door\", \"price\": 12.50, \"tags\": [\"home\", \"green\", \"home\"]}",
1020-
1023+
// R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green", "home"]})""",
10211024
}
10221025
);
10231026
}

0 commit comments

Comments
 (0)