]> git.mdlowis.com Git - archive/dlang.git/commitdiff
Added unit tests for symbols, numbers, and operators
authorMike D. Lowis <mike@mdlowis.com>
Tue, 3 Apr 2012 20:57:40 +0000 (16:57 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Tue, 3 Apr 2012 20:57:40 +0000 (16:57 -0400)
tests/test_dllexer.cpp

index b67d739827f3d46d2960ef8dad316a6da9b4e957..1c92c8dd4ed7f9a1473ea97af06f1c1045be7dca 100644 (file)
@@ -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 );
     }
 
 }