]> git.mdlowis.com Git - archive/dlang.git/commitdiff
Added unit tests for operators and macros
authorMike D. Lowis <mike@mdlowis.com>
Sat, 7 Apr 2012 13:59:19 +0000 (09:59 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Sat, 7 Apr 2012 13:59:19 +0000 (09:59 -0400)
tests/test_dlparser.cpp

index 8785bc58d5a0eeb7b7c2cec7b8a6c27de8aa0c30..5f8a6d922850b6de8ab1d368482c6b76aff135a2 100644 (file)
@@ -382,9 +382,288 @@ namespace {
 
     // Function Application
     //---------------------
+    TEST(Parse_A_Simple_Function_Application)
+    {
+        std::string input("foo()");
+        eTokenTypes expected[] = {
+            ID, LIST, FN_CALL,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
 
     // Collection Access
     //------------------
+    TEST(Parse_An_Array_Indexing_Expression)
+    {
+        std::string input("foo[1]");
+        eTokenTypes expected[] = {
+            ID, NUM, ARRY_IDX,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    // Logical Operators
+    //------------------
+    TEST(Parse_A_Logical_And_Operation)
+    {
+        std::string input("foo && bar");
+        eTokenTypes expected[] = {
+            ID, ID, AND,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Logical_Or_Operation)
+    {
+        std::string input("foo || bar");
+        eTokenTypes expected[] = {
+            ID, ID, OR,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Logical_Not_Operation)
+    {
+        std::string input("! foo");
+        eTokenTypes expected[] = {
+            ID, NOT,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    // Arithmetic Operators
+    //---------------------
+    TEST(Parse_An_Addition_Operation)
+    {
+        std::string input("foo + bar");
+        eTokenTypes expected[] = {
+            ID, ID, ADD,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Subtraction_Operation)
+    {
+        std::string input("foo - bar");
+        eTokenTypes expected[] = {
+            ID, ID, SUB,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Multiplication_Operation)
+    {
+        std::string input("foo * bar");
+        eTokenTypes expected[] = {
+            ID, ID, MUL,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Division_Operation)
+    {
+        std::string input("foo / bar");
+        eTokenTypes expected[] = {
+            ID, ID, DIV,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    // Comparison Operators
+    //---------------------
+    TEST(Parse_An_Equal_Operation)
+    {
+        std::string input("foo == bar");
+        eTokenTypes expected[] = {
+            ID, ID, EQ,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Not_Equal_Operation)
+    {
+        std::string input("foo != bar");
+        eTokenTypes expected[] = {
+            ID, ID, NE,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Less_Than_Operation)
+    {
+        std::string input("foo < bar");
+        eTokenTypes expected[] = {
+            ID, ID, LT,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Greater_Than_Operation)
+    {
+        std::string input("foo > bar");
+        eTokenTypes expected[] = {
+            ID, ID, GT,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Less_Than_Or_Equal_Operation)
+    {
+        std::string input("foo <= bar");
+        eTokenTypes expected[] = {
+            ID, ID, LTE,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Greater_Than_Or_Equal_Operation)
+    {
+        std::string input("foo >= bar");
+        eTokenTypes expected[] = {
+            ID, ID, GTE,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    // Definition and Assignment
+    //--------------------------
+    TEST(Parse_A_Definition_Operation)
+    {
+        std::string input("foo := 1");
+        eTokenTypes expected[] = {
+            ID, NUM, DEFN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_An_Assignment_Operation)
+    {
+        std::string input("foo = bar");
+        eTokenTypes expected[] = {
+            ID, ID, ASSIGN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    //-------------------------------------------------------------------------
+    // Test Macro Definition and Expansion
+    //-------------------------------------------------------------------------
+    TEST(Parse_A_Macro_Taking_One_Map)
+    {
+        std::string input("\% foo [ (M) : $1 ]");
+        eTokenTypes expected[] = {
+            ID, ID, ASSIGN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Macro_Taking_One_Vector)
+    {
+        std::string input("\% foo [ (V) : $1 ]");
+        eTokenTypes expected[] = {
+            ID, ID, ASSIGN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Macro_Taking_One_List)
+    {
+        std::string input("\% foo [ (L) : $1 ]");
+        eTokenTypes expected[] = {
+            ID, ID, ASSIGN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Macro_Taking_One_Block)
+    {
+        std::string input("\% foo [ (B) : $1 ]");
+        eTokenTypes expected[] = {
+            ID, ID, ASSIGN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Macro_taking_One_Id)
+    {
+        std::string input("\% foo [ (I) : $1 ]");
+        eTokenTypes expected[] = {
+            ID, ID, ASSIGN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Macro_Taking_One_Number)
+    {
+        std::string input("\% foo [ (N) : $1 ]");
+        eTokenTypes expected[] = {
+            ID, ID, ASSIGN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Macro_Taking_One_Character)
+    {
+        std::string input("\% foo [ (C) : $1 ]");
+        eTokenTypes expected[] = {
+            ID, ID, ASSIGN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Macro_Taking_One_String)
+    {
+        std::string input("\% foo [ (St) : $1 ]");
+        eTokenTypes expected[] = {
+            ID, ID, ASSIGN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Macro_Taking_One_Symbol)
+    {
+        std::string input("\% foo [ (Sy) : $1 ]");
+        eTokenTypes expected[] = {
+            ID, ID, ASSIGN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
+
+    TEST(Parse_A_Macro_Taking_One_Expression)
+    {
+        std::string input("\% foo [ (E) : $1 ]");
+        eTokenTypes expected[] = {
+            ID, ID, ASSIGN,
+            PROGRAM
+        };
+        TestParserWithInput( input, expected );
+    }
 
     //-------------------------------------------------------------------------
     // Test General Corner Cases