Skip to content

Commit 8713e57

Browse files
committed
Fixing nits from ochafik. Removing escape slashes, adding additional failing cases, fixing some other strings.
1 parent bd3ebb6 commit 8713e57

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

tests/test-grammar-integration.cpp

+24-23
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static void test_grammar(const std::string & test_desc, const std::string & gram
102102
fclose(string_file);
103103
}
104104

105-
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");
105+
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");
106106
} else {
107107
fprintf(stdout, "✅︎\n");
108108
}
@@ -399,11 +399,15 @@ static void test_json_schema() {
399399
// Passing strings
400400
{
401401
"{}",
402-
"{\"foo\": \"bar\"}",
402+
R"""({"foo": "bar"})""",
403403
},
404404
// Failing strings
405405
{
406406
"",
407+
"[]",
408+
"null",
409+
"\"\"",
410+
"true",
407411
}
408412
);
409413

@@ -847,16 +851,16 @@ static void test_json_schema() {
847851
)),
848852
// Passing strings
849853
{
850-
"{\"b\": \"foo\", \"a\": \"bar\"}",
851-
"{\"b\":\"foo\",\"a\":\"bar\",\"d\":\"qux\"}",
852-
"{\"b\":\"foo\", \"a\":\"bar\", \"d\":\"qux\", \"c\":\"baz\"}",
854+
R"""({"b": "foo", "a": "bar"})""",
855+
R"""({"b":"foo","a":"bar","d":"qux"})""",
856+
R"""({"b":"foo", "a":"bar", "d":"qux", "c":"baz"})""",
853857
},
854858
// Failing strings
855859
{
856-
"{\"a\": \"foo\", \"b\": \"bar\"}",
857-
"{\"b\": \"bar\"}",
858-
"{\"a\": \"foo\", \"c\": \"baz\"}",
859-
"{\"a\":\"foo\", \"b\":\"bar\", \"c\":\"baz\", \"d\":\"qux\"}",
860+
R"""({"a": "foo", "b": "bar"})""",
861+
R"""({"b": "bar"})""",
862+
R"""({"a": "foo", "c": "baz"})""",
863+
R"""({"a":"foo", "b":"bar", "c":"baz", "d":"qux"})""",
860864
}
861865
);
862866

@@ -917,28 +921,25 @@ static void test_json_schema() {
917921
)),
918922
// Passing strings
919923
{
920-
"{\"productId\": 1, \"productName\": \"A green door\", \"price\": 12.50}",
921-
"{\"productId\": 1, \"productName\": \"A green door\", \"price\": 12.50, \"tags\": [\"home\", \"green\"]}",
922-
"{\"productId\": 1, \"productName\": \"A green door\", \"price\": 12.50, \"tags\": [\"home\", \"green\"], \"dimensions\": {\"length\": 785, \"width\": 250.5, \"height\": -0.359}}",
924+
R"""({"productId": 1, "productName": "A green door", "price": 12.50})""",
925+
R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green"]})""",
926+
R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green"], "dimensions": {"length": 785, "width": 250.5, "height": -0.359}})""",
923927
},
924928
// Failing strings
925929
{
926-
"{}", // Missing all required properties
927-
"{\"productName\": \"A green door\", \"price\": 12.50, \"productId\": 1}", // Out of order properties
930+
R"""({})""", // Missing all required properties
931+
R"""({"productName": "A green door", "price": 12.50, "productId": 1})""", // Out of order properties
928932
// TODO: The following line should fail, but currently it passes. `exclusiveMinimum` is not supported, as it would likely be too difficult to implement.
929933
// 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.
930-
// "{\"productId\": 1, \"productName\": \"A green door\", \"price\": -12.50}",
931-
"{\"productId\": 1, \"productName\": \"A green door\"}", // Missing required property (price)
932-
"{\"productName\": \"A green door\", \"price\": 12.50}", // Missing required property (productId)
933-
"{\"productId\": 1, \"productName\": \"A green door\", \"price\": 12.50, \"tags\": []}", // tags is empty, but minItems is 1
934-
"{\"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
934+
// R"""({"productId": 1, "productName": "A green door", "price": -12.50})""",
935+
R"""({"productId": 1, "productName": "A green door"})""", // Missing required property (price)
936+
R"""({"productName": "A green door", "price": 12.50})""", // Missing required property (productId)
937+
R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": []})""", // tags is empty, but minItems is 1
938+
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
935939
// TODO: The following line should fail, but currently it passes. `uniqueItems` is not supported, as it would likely be too difficult to implement.
936-
// "{\"productId\": 1, \"productName\": \"A green door\", \"price\": 12.50, \"tags\": [\"home\", \"green\", \"home\"]}",
937-
940+
// R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green", "home"]})""",
938941
}
939942
);
940-
941-
942943
}
943944

944945
int main() {

0 commit comments

Comments
 (0)