From 461c91b59787559c3a9324708d400b980024b22f Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Tue, 3 Apr 2012 16:57:40 -0400 Subject: [PATCH] Added unit tests for symbols, numbers, and operators --- tests/test_dllexer.cpp | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/tests/test_dllexer.cpp b/tests/test_dllexer.cpp index b67d739..1c92c8d 100644 --- a/tests/test_dllexer.cpp +++ b/tests/test_dllexer.cpp @@ -101,17 +101,23 @@ namespace { // Recognize combinations of digits "10 11 12 13 14 15 16 17 18 19\n" // Recognize floating point numbers (with and without exponents) - "1.0 -1.0 0.1e1 10.0e-1" + "1.0 -1.0 0.1e1 10.0e-1 1e0 10e-1" ); eTokenTypes expected[] = { NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, - NUM, NUM, NUM, NUM, + NUM, NUM, NUM, NUM, NUM, NUM, (eTokenTypes)EOF }; TestLexerWithInput( input, expected ); } + TEST(Recognize_Invalid_Numbers) + { + std::string missing_exp("1.0e-"); + TestLexerThrowsException( missing_exp ); + } + TEST(Recognize_Valid_Characters) { CHECK(false); @@ -124,12 +130,36 @@ namespace { TEST(Recognize_Valid_Symbols) { - CHECK(false); + std::string input( + // Make Sure we recognize all valid characters for an ID + "$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\n" + "$ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_\n" + "$a_123\n" + "$a123\n" + "$a_\n" + "$a_a\n" + ); + eTokenTypes expected[] = { + SYMBOL, SYMBOL, SYMBOL, SYMBOL, SYMBOL, SYMBOL, (eTokenTypes)EOF + }; + TestLexerWithInput( input, expected ); } TEST(Recognize_Valid_Operators) { - CHECK(false); + std::string input( + // Recognize single character operators + "[ ] ( ) { } , + * / . %" + // Recognize multi character operators and similar single char ones + "= == ! != < <= > >= | || && : := @ @=" + ); + eTokenTypes expected[] = { + LBRACK, RBRACK, LPAR, RPAR, LBRACE, RBRACE, COMMA, ADD, MUL, DIV, + MEMB, MACRO, ASSIGN, EQ, NOT, NE, LT, LTE, GT, GTE, PIPE, OR, AND, + SEP, DEFN, MAP, IMPORT, + (eTokenTypes)EOF + }; + TestLexerWithInput( input, expected ); } } -- 2.52.0