1 parent fea0e96 commit c94dfa3Copy full SHA for c94dfa3
1 file changed
tests/test_llama_grammar.py
@@ -1,5 +1,6 @@
1
import llama_cpp
2
import json
3
+import pytest
4
5
tree = """
6
leaf ::= "."
@@ -76,3 +77,23 @@ def test_grammar_anyof():
76
77
grammar = llama_cpp.LlamaGrammar.from_json_schema(json.dumps(sch))
78
79
# assert grammar.grammar is not None
80
+
81
82
+@pytest.mark.parametrize(
83
+ ("definition_name", "reference_token"),
84
+ [
85
+ ("a/b", "a~1b"),
86
+ ("a~b", "a~0b"),
87
+ ("a~1b", "a~01b"),
88
+ ("a~/b", "a~0~1b"),
89
+ ],
90
+)
91
+def test_grammar_json_pointer_escapes(definition_name, reference_token):
92
+ schema = {
93
+ "$defs": {definition_name: {"const": 42}},
94
+ "$ref": f"#/$defs/{reference_token}",
95
+ }
96
97
+ grammar = llama_cpp.LlamaGrammar.from_json_schema(json.dumps(schema))
98
99
+ assert '::= "42"' in grammar._grammar
0 commit comments