@@ -53,21 +53,27 @@ static bool match_string(const std::string & input, llama_grammar* grammar) {
5353}
5454
5555static 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);
5758
5859 auto grammar = build_grammar (grammar_str);
5960
6061 // Save the original grammar stacks so that we can reset after every new string we want to test
6162 auto original_stacks = grammar->stacks ;
6263
64+ fprintf (stderr, " Checking valid strings:\n " );
65+
6366 // Passing strings
6467 for (const auto & test_string : passing_strings) {
68+ fprintf (stderr, " \" %s\" " , test_string.c_str ());
69+ fflush (stderr);
70+
6571 bool matched = match_string (test_string, grammar);
6672
6773 if (!matched) {
68- fprintf (stderr, " ❌ Failed to match string: \" %s \"\n " , test_string. c_str () );
74+ fprintf (stderr, " ❌ (failed to match) \n " );
6975 } else {
70- fprintf (stdout, " ✅︎ Matched string: \" %s \"\n " , test_string. c_str () );
76+ fprintf (stdout, " ✅︎ \n " );
7177 }
7278
7379 assert (matched);
@@ -76,14 +82,19 @@ static void test_grammar(const std::string & grammar_str, const std::vector<std:
7682 grammar->stacks = original_stacks;
7783 }
7884
85+ fprintf (stderr, " Checking invalid strings:\n " );
86+
7987 // Failing strings
8088 for (const auto & test_string : failing_strings) {
89+ fprintf (stderr, " \" %s\" " , test_string.c_str ());
90+ fflush (stderr);
91+
8192 bool matched = match_string (test_string, grammar);
8293
8394 if (matched) {
84- fprintf (stderr, " ❌ Improperly matched string: \" %s \"\n " , test_string. c_str () );
95+ fprintf (stderr, " ❌ (incorrectly matched) \n " );
8596 } else {
86- fprintf (stdout, " ✅︎ Correctly did not match string: \" %s \"\n " , test_string. c_str () );
97+ fprintf (stdout, " ✅︎ \n " );
8798 }
8899 assert (!matched);
89100
0 commit comments