File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -1029,7 +1029,7 @@ tests/test-grammar-parser: tests/test-grammar-parser.cpp ggml.o llama.o grammar-
1029
1029
$(CXX ) $(CXXFLAGS ) -c $< -o $(call GET_OBJ_FILE, $< )
1030
1030
$(CXX ) $(CXXFLAGS ) $(filter-out % .h $< ,$^ ) $(call GET_OBJ_FILE, $< ) -o $@ $(LDFLAGS )
1031
1031
1032
- tests/test-grammar-integration : tests/test-grammar-integration.cpp ggml.o llama.o grammar-parser.o $(OBJS )
1032
+ tests/test-grammar-integration : tests/test-grammar-integration.cpp json-schema-to-grammar.o ggml.o llama.o grammar-parser.o $(OBJS )
1033
1033
$(CXX ) $(CXXFLAGS ) -c $< -o $(call GET_OBJ_FILE, $< )
1034
1034
$(CXX ) $(CXXFLAGS ) $(filter-out % .h $< ,$^ ) $(call GET_OBJ_FILE, $< ) -o $@ $(LDFLAGS )
1035
1035
Original file line number Diff line number Diff line change 7
7
#include " ggml.h"
8
8
#include " llama.h"
9
9
#include " grammar-parser.h"
10
+ #include " json-schema-to-grammar.h"
10
11
#include " unicode.h"
11
12
#include < cassert>
12
13
#include < string>
@@ -468,6 +469,31 @@ empty ::= "blah" | )""";
468
469
fprintf (stderr, " ✅︎ Passed\n " );
469
470
}
470
471
472
+ static void test_json_schema () {
473
+ // Note that this is similar to the regular grammar tests,
474
+ // but we convert each json schema to a grammar before parsing.
475
+ // Otherwise, this test structure is the same.
476
+
477
+ test_grammar (
478
+ " empty schema" ,
479
+ // Grammar
480
+ json_schema_to_grammar (nlohmann::ordered_json::parse (
481
+ R"""(
482
+ {}
483
+ )"""
484
+ )),
485
+ // Passing strings
486
+ {
487
+ " {}" ,
488
+ " {\" foo\" : \" bar\" }" ,
489
+ },
490
+ // Failing strings
491
+ {
492
+ " " ,
493
+ }
494
+ );
495
+ }
496
+
471
497
int main () {
472
498
fprintf (stdout, " Running grammar integration tests...\n " );
473
499
test_simple_grammar ();
@@ -477,6 +503,7 @@ int main() {
477
503
test_failure_missing_root ();
478
504
test_failure_missing_reference ();
479
505
test_failure_left_recursion ();
506
+ test_json_schema ();
480
507
fprintf (stdout, " All tests passed.\n " );
481
508
return 0 ;
482
509
}
You can’t perform that action at this time.
0 commit comments