]> git.mdlowis.com Git - archive/dlang.git/commitdiff
100% coverage of dllexer
authorMike D. Lowis <mike@mdlowis.com>
Wed, 4 Apr 2012 18:15:25 +0000 (14:15 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Wed, 4 Apr 2012 18:15:25 +0000 (14:15 -0400)
rakefile.rb
source/dllexer/dllexer.cpp
tests/test_dllexer.cpp

index cb67e439f84c5908c5800310213b544ddeceb656..2eec6057b9f123055cbb2a074851947db63216f6 100644 (file)
@@ -132,6 +132,7 @@ task :coverage do #=> [ :test ] do
     end
 
     # For each test file
+    puts ""
     tests.each { |test|
         # Find the source file basename, object file location, and gcov output
         source = File.basename( test ).gsub( 'test_', '' )
@@ -140,7 +141,8 @@ task :coverage do #=> [ :test ] do
 
         # Generate the coverage info and display only the summary for our
         # source file
-        sh "gcov -o build/test/obj #{obj} | grep -A1 #{source}"
+        puts "----"
+        sh "gcov -b -o build/test/obj #{obj} | grep -A 4 \"#{source}'\""
 
         # Move the coverage to our output folder
         FileUtils.mv( gcov, out_dir )
@@ -148,4 +150,5 @@ task :coverage do #=> [ :test ] do
         # Delete the unwanted coverage files
         FileList['*.gcov'].each { |f| File.delete(f) }
     }
+    puts ""
 end
index 4d9efe1e118e739eecdafd26e711ab574ae8d694..0ff7ad96138900cee5d2c1846c7263bb07fbd434 100644 (file)
@@ -184,7 +184,7 @@ void DLLexer::Number(Token& tok, bool isNegative)
         else
         {
             Exception ex(line,column);
-            ex << "Integer for floating point exponent";
+            ex << "Missing integer for floating point exponent";
             throw ex;
         }
     }
@@ -404,7 +404,8 @@ void DLLexer::MultiCharOp(Token& tok)
             tok = Token(MAP, line, column);
         }
     }
-    else
+
+    if (tok.type() == EOF)
     {
         Exception ex(line,column);
         ex << "Unexpected token";
@@ -415,36 +416,12 @@ void DLLexer::MultiCharOp(Token& tok)
 std::string DLLexer::EscapeSequence()
 {
     ostringstream oss;
-
+    // consume backslash
+    oss << lookahead(1);
+    consume();
+    // consume escaped char
     oss << lookahead(1);
     consume();
-
-    if ( lookahead(1) == 'x' )
-    {
-        oss << lookahead(1);
-        consume();
-        for(int i = 0; i < 2; i++)
-        {
-            if ( ((lookahead(1) >= '0') || (lookahead(1) <= '9')) ||
-                 ((lookahead(1) >= 'a') || (lookahead(1) <= 'f')) ||
-                 ((lookahead(1) >= 'A') || (lookahead(1) <= 'F')))
-            {
-                oss << lookahead(1);
-                consume();
-            }
-            else
-            {
-                Exception ex(line,column);
-                ex << "Invalid hexadecimal escape sequence.";
-                throw ex;
-            }
-        }
-    }
-    else
-    {
-        oss << lookahead(1);
-        consume();
-    }
     return oss.str();
 }
 
index 1fcb957b669253dba742ad2c796a40c968ea9dfe..ed1b86f5c80efa7c238798ec82739bbe5a9d7981 100644 (file)
@@ -120,12 +120,28 @@ namespace {
 
     TEST(Recognize_Valid_Characters)
     {
-        CHECK(false);
+        std::string input(
+            // Make Sure we recognize characters and escaped characters
+            "'a' '\\a'"
+        );
+        eTokenTypes expected[] = {
+            CHAR, CHAR, (eTokenTypes)EOF
+        };
+        TestLexerWithInput( input, expected );
     }
 
     TEST(Recognize_Valid_Strings)
     {
-        CHECK(false);
+        std::string input(
+            // Make Sure we recognize all valid characters for a symbol
+            "\"\" \n"
+            "\"a\" \n"
+            "\"\\a\" \n"
+        );
+        eTokenTypes expected[] = {
+            STRING, STRING, STRING, (eTokenTypes)EOF
+        };
+        TestLexerWithInput( input, expected );
     }
 
     TEST(Recognize_Valid_Symbols)
@@ -149,17 +165,40 @@ namespace {
     {
         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,
+            MEMB, MACRO, SUB, ASSIGN, EQ, NOT, NE, LT, LTE, GT, GTE, PIPE, OR,
+            AND, SEP, DEFN, MAP, IMPORT,
             (eTokenTypes)EOF
         };
         TestLexerWithInput( input, expected );
     }
 
+    TEST(Throw_Exceptions_For_Exceptional_Cases)
+    {
+        // Make sure invalud number literals throw exceptions where appropriate
+        std::string num_exception1("1.0e-");
+        TestLexerThrowsException( num_exception1 );
+
+        std::string num_exception2("1.0e-a");
+        TestLexerThrowsException( num_exception2 );
+
+        std::string num_exception3("1.0e-");
+        TestLexerThrowsException( num_exception3 );
+
+        std::string num_exception4("1.a");
+        TestLexerThrowsException( num_exception4 );
+
+        // Make sure we throw an exception for an invalid operator
+        std::string op_exception1("^");
+        TestLexerThrowsException( op_exception1 );
+
+        // Make sure we throw an exception for an invalid operator
+        std::string multi_op_exception1("&");
+        TestLexerThrowsException( multi_op_exception1 );
+    }
 }