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 @@ -987,7 +987,7 @@ tests/test-grammar-parser: tests/test-grammar-parser.cpp ggml.o llama.o grammar-
987
987
$(CXX ) $(CXXFLAGS ) -c $< -o $(call GET_OBJ_FILE, $< )
988
988
$(CXX ) $(CXXFLAGS ) $(filter-out % .h $< ,$^ ) $(call GET_OBJ_FILE, $< ) -o $@ $(LDFLAGS )
989
989
990
- tests/test-grammar-integration : tests/test-grammar-integration.cpp ggml.o llama.o grammar-parser.o $(OBJS )
990
+ tests/test-grammar-integration : tests/test-grammar-integration.cpp json-schema-to-grammar.o ggml.o llama.o grammar-parser.o $(OBJS )
991
991
$(CXX ) $(CXXFLAGS ) -c $< -o $(call GET_OBJ_FILE, $< )
992
992
$(CXX ) $(CXXFLAGS ) $(filter-out % .h $< ,$^ ) $(call GET_OBJ_FILE, $< ) -o $@ $(LDFLAGS )
993
993
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>
@@ -365,6 +366,31 @@ empty ::= "blah" | )""";
365
366
fprintf (stderr, " ✅︎ Passed\n " );
366
367
}
367
368
369
+ static void test_json_schema () {
370
+ // Note that this is similar to the regular grammar tests,
371
+ // but we convert each json schema to a grammar before parsing.
372
+ // Otherwise, this test structure is the same.
373
+
374
+ test_grammar (
375
+ " empty schema" ,
376
+ // Grammar
377
+ json_schema_to_grammar (nlohmann::ordered_json::parse (
378
+ R"""(
379
+ {}
380
+ )"""
381
+ )),
382
+ // Passing strings
383
+ {
384
+ " {}" ,
385
+ " {\" foo\" : \" bar\" }" ,
386
+ },
387
+ // Failing strings
388
+ {
389
+ " " ,
390
+ }
391
+ );
392
+ }
393
+
368
394
int main () {
369
395
fprintf (stdout, " Running grammar integration tests...\n " );
370
396
test_simple_grammar ();
@@ -373,6 +399,7 @@ int main() {
373
399
test_failure_missing_root ();
374
400
test_failure_missing_reference ();
375
401
test_failure_left_recursion ();
402
+ test_json_schema ();
376
403
fprintf (stdout, " All tests passed.\n " );
377
404
return 0 ;
378
405
}
You can’t perform that action at this time.
0 commit comments