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_', '' )
# 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 )
# Delete the unwanted coverage files
FileList['*.gcov'].each { |f| File.delete(f) }
}
+ puts ""
end
else
{
Exception ex(line,column);
- ex << "Integer for floating point exponent";
+ ex << "Missing integer for floating point exponent";
throw ex;
}
}
tok = Token(MAP, line, column);
}
}
- else
+
+ if (tok.type() == EOF)
{
Exception ex(line,column);
ex << "Unexpected token";
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();
}
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)
{
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 );
+ }
}