@@ -53,21 +53,27 @@ static bool match_string(const std::string & input, llama_grammar* grammar) {
53
53
}
54
54
55
55
static void test_grammar (const std::string & grammar_str, const std::vector<std::string> & passing_strings, const std::vector<std::string> & failing_strings) {
56
- fprintf (stderr, " 🟢 Testing grammar: %s\n " , grammar_str.c_str ());
56
+ fprintf (stderr, " ⚪ Testing grammar: %s\n " , grammar_str.c_str ());
57
+ fflush (stderr);
57
58
58
59
auto grammar = build_grammar (grammar_str);
59
60
60
61
// Save the original grammar stacks so that we can reset after every new string we want to test
61
62
auto original_stacks = grammar->stacks ;
62
63
64
+ fprintf (stderr, " Checking valid strings:\n " );
65
+
63
66
// Passing strings
64
67
for (const auto & test_string : passing_strings) {
68
+ fprintf (stderr, " \" %s\" " , test_string.c_str ());
69
+ fflush (stderr);
70
+
65
71
bool matched = match_string (test_string, grammar);
66
72
67
73
if (!matched) {
68
- fprintf (stderr, " ❌ Failed to match string: \" %s \"\n " , test_string. c_str () );
74
+ fprintf (stderr, " ❌ (failed to match) \n " );
69
75
} else {
70
- fprintf (stdout, " ✅︎ Matched string: \" %s \"\n " , test_string. c_str () );
76
+ fprintf (stdout, " ✅︎ \n " );
71
77
}
72
78
73
79
assert (matched);
@@ -76,14 +82,19 @@ static void test_grammar(const std::string & grammar_str, const std::vector<std:
76
82
grammar->stacks = original_stacks;
77
83
}
78
84
85
+ fprintf (stderr, " Checking invalid strings:\n " );
86
+
79
87
// Failing strings
80
88
for (const auto & test_string : failing_strings) {
89
+ fprintf (stderr, " \" %s\" " , test_string.c_str ());
90
+ fflush (stderr);
91
+
81
92
bool matched = match_string (test_string, grammar);
82
93
83
94
if (matched) {
84
- fprintf (stderr, " ❌ Improperly matched string: \" %s \"\n " , test_string. c_str () );
95
+ fprintf (stderr, " ❌ (incorrectly matched) \n " );
85
96
} else {
86
- fprintf (stdout, " ✅︎ Correctly did not match string: \" %s \"\n " , test_string. c_str () );
97
+ fprintf (stdout, " ✅︎ \n " );
87
98
}
88
99
assert (!matched);
89
100
0 commit comments