From d24dabc99feaa8d61bb1dd894dd803fa5f5a7ec2 Mon Sep 17 00:00:00 2001 From: Clint Herron Date: Thu, 4 Apr 2024 09:55:28 -0400 Subject: [PATCH] Reorganizing tests for readability. --- tests/test-grammar-integration.cpp | 66 +++++++++++++++--------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/test-grammar-integration.cpp b/tests/test-grammar-integration.cpp index c321fea49..dd1c7901c 100644 --- a/tests/test-grammar-integration.cpp +++ b/tests/test-grammar-integration.cpp @@ -11,39 +11,6 @@ #include #include -static void test_failure_missing_root() { - // Test case for a grammar that is missing a root rule - const std::string grammar_str = R"""(rot ::= expr -expr ::= term ("+" term)* -term ::= number -number ::= [0-9]+)"""; - - grammar_parser::parse_state parsed_grammar = grammar_parser::parse(grammar_str.c_str()); - - // Ensure we parsed correctly - assert(!parsed_grammar.rules.empty()); - - // Ensure we do NOT have a root node - assert(parsed_grammar.symbol_ids.find("root") == parsed_grammar.symbol_ids.end()); -} - -static void test_failure_missing_reference() { - // Test case for a grammar that is missing a referenced rule - const std::string grammar_str = R"""(root ::= expr -expr ::= term ("+" term)* -term ::= numero -number ::= [0-9]+)"""; - - fprintf(stderr, "NOTE: Error message (\"parse: error parsing grammar: Undefined rule identifier 'numero'\") expected on following line during successful test:\n"); - - grammar_parser::parse_state parsed_grammar = grammar_parser::parse(grammar_str.c_str()); - - // Ensure we did NOT parsed correctly - assert(parsed_grammar.rules.empty()); - - fprintf(stderr, "End of expected error message. Test successful.\n"); -} - static void test_simple_grammar() { // Test case for a simple grammar const std::string grammar_str = R"""(root ::= expr @@ -234,6 +201,39 @@ ws ::= [ \t\n\r]?)"""; llama_grammar_free(grammar); } +static void test_failure_missing_root() { + // Test case for a grammar that is missing a root rule + const std::string grammar_str = R"""(rot ::= expr +expr ::= term ("+" term)* +term ::= number +number ::= [0-9]+)"""; + + grammar_parser::parse_state parsed_grammar = grammar_parser::parse(grammar_str.c_str()); + + // Ensure we parsed correctly + assert(!parsed_grammar.rules.empty()); + + // Ensure we do NOT have a root node + assert(parsed_grammar.symbol_ids.find("root") == parsed_grammar.symbol_ids.end()); +} + +static void test_failure_missing_reference() { + // Test case for a grammar that is missing a referenced rule + const std::string grammar_str = R"""(root ::= expr +expr ::= term ("+" term)* +term ::= numero +number ::= [0-9]+)"""; + + fprintf(stderr, "NOTE: Error message (\"parse: error parsing grammar: Undefined rule identifier 'numero'\") expected on following line during successful test:\n"); + + grammar_parser::parse_state parsed_grammar = grammar_parser::parse(grammar_str.c_str()); + + // Ensure we did NOT parsed correctly + assert(parsed_grammar.rules.empty()); + + fprintf(stderr, "End of expected error message. Test successful.\n"); +} + int main() { test_simple_grammar(); test_complex_grammar();