From: Mike D. Lowis Date: Tue, 3 Apr 2012 20:57:40 +0000 (-0400) Subject: Added unit tests for symbols, numbers, and operators X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=461c91b59787559c3a9324708d400b980024b22f;p=archive%2Fdlang.git Added unit tests for symbols, numbers, and operators --- 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 ); } }