Commit c745adb0 by alokp@chromium.org

Added PreprocessorTest::preprocess that preprocesses the input string and…

Added PreprocessorTest::preprocess that preprocesses the input string and compares the output with that of the expected string. Renamed other *Test::preprocess methods to something different and clearer. git-svn-id: https://angleproject.googlecode.com/svn/trunk@1126 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 19d7aa60
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
'preprocessor_tests/number_test.cpp', 'preprocessor_tests/number_test.cpp',
'preprocessor_tests/operator_test.cpp', 'preprocessor_tests/operator_test.cpp',
'preprocessor_tests/pragma_test.cpp', 'preprocessor_tests/pragma_test.cpp',
'preprocessor_tests/PreprocessorTest.cpp',
'preprocessor_tests/PreprocessorTest.h', 'preprocessor_tests/PreprocessorTest.h',
'preprocessor_tests/space_test.cpp', 'preprocessor_tests/space_test.cpp',
'preprocessor_tests/token_test.cpp', 'preprocessor_tests/token_test.cpp',
......
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "PreprocessorTest.h"
#include "Token.h"
void PreprocessorTest::preprocess(const char* input, const char* expected)
{
ASSERT_TRUE(mPreprocessor.init(1, &input, NULL));
int line = 1;
pp::Token token;
std::stringstream stream;
do
{
mPreprocessor.lex(&token);
for (; line < token.location.line; ++line)
{
stream << "\n";
}
stream << token;
} while (token.type != pp::Token::LAST);
std::string actual = stream.str();
EXPECT_STREQ(expected, actual.c_str());
}
...@@ -18,6 +18,10 @@ class PreprocessorTest : public testing::Test ...@@ -18,6 +18,10 @@ class PreprocessorTest : public testing::Test
protected: protected:
PreprocessorTest() : mPreprocessor(&mDiagnostics, &mDirectiveHandler) { } PreprocessorTest() : mPreprocessor(&mDiagnostics, &mDirectiveHandler) { }
// Preprocesses the input string and verifies that it matches
// expected output.
void preprocess(const char* input, const char* expected);
MockDiagnostics mDiagnostics; MockDiagnostics mDiagnostics;
MockDirectiveHandler mDirectiveHandler; MockDirectiveHandler mDirectiveHandler;
pp::Preprocessor mPreprocessor; pp::Preprocessor mPreprocessor;
......
...@@ -9,33 +9,25 @@ ...@@ -9,33 +9,25 @@
class ErrorTest : public PreprocessorTest class ErrorTest : public PreprocessorTest
{ {
protected:
void preprocess(const char* str)
{
ASSERT_TRUE(mPreprocessor.init(1, &str, NULL));
pp::Token token;
mPreprocessor.lex(&token);
EXPECT_EQ(pp::Token::LAST, token.type);
EXPECT_EQ("", token.value);
}
}; };
TEST_F(ErrorTest, Empty) TEST_F(ErrorTest, Empty)
{ {
const char* str = "#error\n"; const char* str = "#error\n";
const char* expected = "\n";
using testing::_; using testing::_;
EXPECT_CALL(mDirectiveHandler, handleError(pp::SourceLocation(0, 1), "")); EXPECT_CALL(mDirectiveHandler, handleError(pp::SourceLocation(0, 1), ""));
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(ErrorTest, OneTokenMessage) TEST_F(ErrorTest, OneTokenMessage)
{ {
const char* str = "#error foo\n"; const char* str = "#error foo\n";
const char* expected = "\n";
using testing::_; using testing::_;
EXPECT_CALL(mDirectiveHandler, EXPECT_CALL(mDirectiveHandler,
...@@ -43,12 +35,13 @@ TEST_F(ErrorTest, OneTokenMessage) ...@@ -43,12 +35,13 @@ TEST_F(ErrorTest, OneTokenMessage)
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(ErrorTest, TwoTokenMessage) TEST_F(ErrorTest, TwoTokenMessage)
{ {
const char* str = "#error foo bar\n"; const char* str = "#error foo bar\n";
const char* expected = "\n";
using testing::_; using testing::_;
EXPECT_CALL(mDirectiveHandler, EXPECT_CALL(mDirectiveHandler,
...@@ -56,7 +49,7 @@ TEST_F(ErrorTest, TwoTokenMessage) ...@@ -56,7 +49,7 @@ TEST_F(ErrorTest, TwoTokenMessage)
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(ErrorTest, Comments) TEST_F(ErrorTest, Comments)
...@@ -72,6 +65,7 @@ TEST_F(ErrorTest, Comments) ...@@ -72,6 +65,7 @@ TEST_F(ErrorTest, Comments)
"/*foo*/" "/*foo*/"
"//foo" "//foo"
"\n"; "\n";
const char* expected = "\n";
using testing::_; using testing::_;
EXPECT_CALL(mDirectiveHandler, EXPECT_CALL(mDirectiveHandler,
...@@ -79,12 +73,13 @@ TEST_F(ErrorTest, Comments) ...@@ -79,12 +73,13 @@ TEST_F(ErrorTest, Comments)
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(ErrorTest, MissingNewline) TEST_F(ErrorTest, MissingNewline)
{ {
const char* str = "#error foo"; const char* str = "#error foo";
const char* expected = "";
using testing::_; using testing::_;
// Directive successfully parsed. // Directive successfully parsed.
...@@ -93,5 +88,5 @@ TEST_F(ErrorTest, MissingNewline) ...@@ -93,5 +88,5 @@ TEST_F(ErrorTest, MissingNewline)
// Error reported about EOF. // Error reported about EOF.
EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::EOF_IN_DIRECTIVE, _, _)); EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::EOF_IN_DIRECTIVE, _, _));
preprocess(str); preprocess(str, expected);
} }
...@@ -9,21 +9,12 @@ ...@@ -9,21 +9,12 @@
class ExtensionTest : public PreprocessorTest class ExtensionTest : public PreprocessorTest
{ {
protected:
void preprocess(const char* str)
{
ASSERT_TRUE(mPreprocessor.init(1, &str, NULL));
pp::Token token;
mPreprocessor.lex(&token);
EXPECT_EQ(pp::Token::LAST, token.type);
EXPECT_EQ("", token.value);
}
}; };
TEST_F(ExtensionTest, Valid) TEST_F(ExtensionTest, Valid)
{ {
const char* str = "#extension foo : bar\n"; const char* str = "#extension foo : bar\n";
const char* expected = "\n";
using testing::_; using testing::_;
EXPECT_CALL(mDirectiveHandler, EXPECT_CALL(mDirectiveHandler,
...@@ -31,7 +22,7 @@ TEST_F(ExtensionTest, Valid) ...@@ -31,7 +22,7 @@ TEST_F(ExtensionTest, Valid)
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(ExtensionTest, Comments) TEST_F(ExtensionTest, Comments)
...@@ -49,6 +40,7 @@ TEST_F(ExtensionTest, Comments) ...@@ -49,6 +40,7 @@ TEST_F(ExtensionTest, Comments)
"/*foo*/" "/*foo*/"
"//foo" "//foo"
"\n"; "\n";
const char* expected = "\n";
using testing::_; using testing::_;
EXPECT_CALL(mDirectiveHandler, EXPECT_CALL(mDirectiveHandler,
...@@ -56,12 +48,13 @@ TEST_F(ExtensionTest, Comments) ...@@ -56,12 +48,13 @@ TEST_F(ExtensionTest, Comments)
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(ExtensionTest, MissingNewline) TEST_F(ExtensionTest, MissingNewline)
{ {
const char* str = "#extension foo : bar"; const char* str = "#extension foo : bar";
const char* expected = "";
using testing::_; using testing::_;
// Directive successfully parsed. // Directive successfully parsed.
...@@ -70,7 +63,7 @@ TEST_F(ExtensionTest, MissingNewline) ...@@ -70,7 +63,7 @@ TEST_F(ExtensionTest, MissingNewline)
// Error reported about EOF. // Error reported about EOF.
EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::EOF_IN_DIRECTIVE, _, _)); EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::EOF_IN_DIRECTIVE, _, _));
preprocess(str); preprocess(str, expected);
} }
struct ExtensionTestParam struct ExtensionTestParam
...@@ -88,6 +81,7 @@ class InvalidExtensionTest : public ExtensionTest, ...@@ -88,6 +81,7 @@ class InvalidExtensionTest : public ExtensionTest,
TEST_P(InvalidExtensionTest, Identified) TEST_P(InvalidExtensionTest, Identified)
{ {
ExtensionTestParam param = GetParam(); ExtensionTestParam param = GetParam();
const char* expected = "\n";
using testing::_; using testing::_;
// No handleExtension call. // No handleExtension call.
...@@ -95,7 +89,7 @@ TEST_P(InvalidExtensionTest, Identified) ...@@ -95,7 +89,7 @@ TEST_P(InvalidExtensionTest, Identified)
// Invalid extension directive call. // Invalid extension directive call.
EXPECT_CALL(mDiagnostics, print(param.id, pp::SourceLocation(0, 1), _)); EXPECT_CALL(mDiagnostics, print(param.id, pp::SourceLocation(0, 1), _));
preprocess(param.str); preprocess(param.str, expected);
} }
static const ExtensionTestParam kParams[] = { static const ExtensionTestParam kParams[] = {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
class IdentifierTest : public PreprocessorTest class IdentifierTest : public PreprocessorTest
{ {
protected: protected:
void preprocess(const std::string& str) void expectIdentifier(const std::string& str)
{ {
const char* cstr = str.c_str(); const char* cstr = str.c_str();
ASSERT_TRUE(mPreprocessor.init(1, &cstr, 0)); ASSERT_TRUE(mPreprocessor.init(1, &cstr, 0));
...@@ -33,7 +33,7 @@ class SingleLetterIdentifierTest : public IdentifierTest, ...@@ -33,7 +33,7 @@ class SingleLetterIdentifierTest : public IdentifierTest,
TEST_P(SingleLetterIdentifierTest, Identified) TEST_P(SingleLetterIdentifierTest, Identified)
{ {
std::string str(1, GetParam()); std::string str(1, GetParam());
preprocess(str); expectIdentifier(str);
} }
// Test string: '_' // Test string: '_'
...@@ -65,7 +65,7 @@ TEST_P(DoubleLetterIdentifierTest, Identified) ...@@ -65,7 +65,7 @@ TEST_P(DoubleLetterIdentifierTest, Identified)
str.push_back(std::tr1::get<0>(GetParam())); str.push_back(std::tr1::get<0>(GetParam()));
str.push_back(std::tr1::get<1>(GetParam())); str.push_back(std::tr1::get<1>(GetParam()));
preprocess(str); expectIdentifier(str);
} }
// Test string: "__" // Test string: "__"
...@@ -158,5 +158,5 @@ TEST_F(IdentifierTest, AllLetters) ...@@ -158,5 +158,5 @@ TEST_F(IdentifierTest, AllLetters)
for (int c = '0'; c <= '9'; ++c) for (int c = '0'; c <= '9'; ++c)
str.push_back(c); str.push_back(c);
preprocess(str); expectIdentifier(str);
} }
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
class LocationTest : public PreprocessorTest class LocationTest : public PreprocessorTest
{ {
protected: protected:
void preprocess(int count, void expectLocation(int count,
const char* const string[], const char* const string[],
const int length[], const int length[],
const pp::SourceLocation& location) const pp::SourceLocation& location)
{ {
ASSERT_TRUE(mPreprocessor.init(count, string, length)); ASSERT_TRUE(mPreprocessor.init(count, string, length));
...@@ -35,7 +35,7 @@ TEST_F(LocationTest, String0_Line1) ...@@ -35,7 +35,7 @@ TEST_F(LocationTest, String0_Line1)
loc.line = 1; loc.line = 1;
SCOPED_TRACE("String0_Line1"); SCOPED_TRACE("String0_Line1");
preprocess(1, &str, NULL, loc); expectLocation(1, &str, NULL, loc);
} }
TEST_F(LocationTest, String0_Line2) TEST_F(LocationTest, String0_Line2)
...@@ -46,7 +46,7 @@ TEST_F(LocationTest, String0_Line2) ...@@ -46,7 +46,7 @@ TEST_F(LocationTest, String0_Line2)
loc.line = 2; loc.line = 2;
SCOPED_TRACE("String0_Line2"); SCOPED_TRACE("String0_Line2");
preprocess(1, &str, NULL, loc); expectLocation(1, &str, NULL, loc);
} }
TEST_F(LocationTest, String1_Line1) TEST_F(LocationTest, String1_Line1)
...@@ -57,7 +57,7 @@ TEST_F(LocationTest, String1_Line1) ...@@ -57,7 +57,7 @@ TEST_F(LocationTest, String1_Line1)
loc.line = 1; loc.line = 1;
SCOPED_TRACE("String1_Line1"); SCOPED_TRACE("String1_Line1");
preprocess(2, str, NULL, loc); expectLocation(2, str, NULL, loc);
} }
TEST_F(LocationTest, String1_Line2) TEST_F(LocationTest, String1_Line2)
...@@ -68,7 +68,7 @@ TEST_F(LocationTest, String1_Line2) ...@@ -68,7 +68,7 @@ TEST_F(LocationTest, String1_Line2)
loc.line = 2; loc.line = 2;
SCOPED_TRACE("String1_Line2"); SCOPED_TRACE("String1_Line2");
preprocess(2, str, NULL, loc); expectLocation(2, str, NULL, loc);
} }
TEST_F(LocationTest, NewlineInsideCommentCounted) TEST_F(LocationTest, NewlineInsideCommentCounted)
...@@ -79,7 +79,7 @@ TEST_F(LocationTest, NewlineInsideCommentCounted) ...@@ -79,7 +79,7 @@ TEST_F(LocationTest, NewlineInsideCommentCounted)
loc.line = 3; loc.line = 3;
SCOPED_TRACE("NewlineInsideCommentCounted"); SCOPED_TRACE("NewlineInsideCommentCounted");
preprocess(1, &str, NULL, loc); expectLocation(1, &str, NULL, loc);
} }
TEST_F(LocationTest, ErrorLocationAfterComment) TEST_F(LocationTest, ErrorLocationAfterComment)
...@@ -106,7 +106,7 @@ TEST_F(LocationTest, TokenStraddlingTwoStrings) ...@@ -106,7 +106,7 @@ TEST_F(LocationTest, TokenStraddlingTwoStrings)
loc.line = 1; loc.line = 1;
SCOPED_TRACE("TokenStraddlingTwoStrings"); SCOPED_TRACE("TokenStraddlingTwoStrings");
preprocess(2, str, NULL, loc); expectLocation(2, str, NULL, loc);
} }
TEST_F(LocationTest, TokenStraddlingThreeStrings) TEST_F(LocationTest, TokenStraddlingThreeStrings)
...@@ -117,7 +117,7 @@ TEST_F(LocationTest, TokenStraddlingThreeStrings) ...@@ -117,7 +117,7 @@ TEST_F(LocationTest, TokenStraddlingThreeStrings)
loc.line = 1; loc.line = 1;
SCOPED_TRACE("TokenStraddlingThreeStrings"); SCOPED_TRACE("TokenStraddlingThreeStrings");
preprocess(3, str, NULL, loc); expectLocation(3, str, NULL, loc);
} }
TEST_F(LocationTest, EndOfFileWithoutNewline) TEST_F(LocationTest, EndOfFileWithoutNewline)
......
...@@ -81,7 +81,7 @@ INSTANTIATE_TEST_CASE_P(HexadecimalInteger_A_F, ...@@ -81,7 +81,7 @@ INSTANTIATE_TEST_CASE_P(HexadecimalInteger_A_F,
class FloatTest : public PreprocessorTest class FloatTest : public PreprocessorTest
{ {
protected: protected:
void preprocess(const std::string& str) void expectFloat(const std::string& str)
{ {
const char* cstr = str.c_str(); const char* cstr = str.c_str();
ASSERT_TRUE(mPreprocessor.init(1, &cstr, 0)); ASSERT_TRUE(mPreprocessor.init(1, &cstr, 0));
...@@ -110,7 +110,7 @@ TEST_P(FloatScientificTest, FloatIdentified) ...@@ -110,7 +110,7 @@ TEST_P(FloatScientificTest, FloatIdentified)
str.push_back(std::tr1::get<3>(GetParam())); // exponent [0-9]. str.push_back(std::tr1::get<3>(GetParam())); // exponent [0-9].
SCOPED_TRACE("FloatScientificTest"); SCOPED_TRACE("FloatScientificTest");
preprocess(str); expectFloat(str);
} }
INSTANTIATE_TEST_CASE_P(FloatScientific, INSTANTIATE_TEST_CASE_P(FloatScientific,
...@@ -143,7 +143,7 @@ TEST_P(FloatFractionTest, FloatIdentified) ...@@ -143,7 +143,7 @@ TEST_P(FloatFractionTest, FloatIdentified)
str.push_back(fraction); str.push_back(fraction);
SCOPED_TRACE("FloatFractionTest"); SCOPED_TRACE("FloatFractionTest");
preprocess(str); expectFloat(str);
} }
INSTANTIATE_TEST_CASE_P(FloatFraction_X_X, INSTANTIATE_TEST_CASE_P(FloatFraction_X_X,
...@@ -166,5 +166,5 @@ INSTANTIATE_TEST_CASE_P(FloatFraction_X_0, ...@@ -166,5 +166,5 @@ INSTANTIATE_TEST_CASE_P(FloatFraction_X_0,
TEST_F(FloatTest, FractionScientific) TEST_F(FloatTest, FractionScientific)
{ {
SCOPED_TRACE("FractionScientific"); SCOPED_TRACE("FractionScientific");
preprocess("0.1e+2"); expectFloat("0.1e+2");
} }
...@@ -9,21 +9,12 @@ ...@@ -9,21 +9,12 @@
class PragmaTest : public PreprocessorTest class PragmaTest : public PreprocessorTest
{ {
protected:
void preprocess(const char* str)
{
ASSERT_TRUE(mPreprocessor.init(1, &str, NULL));
pp::Token token;
mPreprocessor.lex(&token);
EXPECT_EQ(pp::Token::LAST, token.type);
EXPECT_EQ("", token.value);
}
}; };
TEST_F(PragmaTest, EmptyName) TEST_F(PragmaTest, EmptyName)
{ {
const char* str = "#pragma\n"; const char* str = "#pragma\n";
const char* expected = "\n";
using testing::_; using testing::_;
// No handlePragma calls. // No handlePragma calls.
...@@ -31,12 +22,13 @@ TEST_F(PragmaTest, EmptyName) ...@@ -31,12 +22,13 @@ TEST_F(PragmaTest, EmptyName)
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(PragmaTest, EmptyValue) TEST_F(PragmaTest, EmptyValue)
{ {
const char* str = "#pragma foo\n"; const char* str = "#pragma foo\n";
const char* expected = "\n";
using testing::_; using testing::_;
EXPECT_CALL(mDirectiveHandler, EXPECT_CALL(mDirectiveHandler,
...@@ -44,12 +36,13 @@ TEST_F(PragmaTest, EmptyValue) ...@@ -44,12 +36,13 @@ TEST_F(PragmaTest, EmptyValue)
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(PragmaTest, NameValue) TEST_F(PragmaTest, NameValue)
{ {
const char* str = "#pragma foo(bar)\n"; const char* str = "#pragma foo(bar)\n";
const char* expected = "\n";
using testing::_; using testing::_;
EXPECT_CALL(mDirectiveHandler, EXPECT_CALL(mDirectiveHandler,
...@@ -57,7 +50,7 @@ TEST_F(PragmaTest, NameValue) ...@@ -57,7 +50,7 @@ TEST_F(PragmaTest, NameValue)
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(PragmaTest, Comments) TEST_F(PragmaTest, Comments)
...@@ -77,6 +70,7 @@ TEST_F(PragmaTest, Comments) ...@@ -77,6 +70,7 @@ TEST_F(PragmaTest, Comments)
"/*foo*/" "/*foo*/"
"//foo" "//foo"
"\n"; "\n";
const char* expected = "\n";
using testing::_; using testing::_;
EXPECT_CALL(mDirectiveHandler, EXPECT_CALL(mDirectiveHandler,
...@@ -84,12 +78,13 @@ TEST_F(PragmaTest, Comments) ...@@ -84,12 +78,13 @@ TEST_F(PragmaTest, Comments)
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(PragmaTest, MissingNewline) TEST_F(PragmaTest, MissingNewline)
{ {
const char* str = "#pragma foo(bar)"; const char* str = "#pragma foo(bar)";
const char* expected = "";
using testing::_; using testing::_;
// Pragma successfully parsed. // Pragma successfully parsed.
...@@ -98,7 +93,7 @@ TEST_F(PragmaTest, MissingNewline) ...@@ -98,7 +93,7 @@ TEST_F(PragmaTest, MissingNewline)
// Error reported about EOF. // Error reported about EOF.
EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::EOF_IN_DIRECTIVE, _, _)); EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::EOF_IN_DIRECTIVE, _, _));
preprocess(str); preprocess(str, expected);
} }
class InvalidPragmaTest : public PragmaTest, class InvalidPragmaTest : public PragmaTest,
...@@ -109,6 +104,7 @@ class InvalidPragmaTest : public PragmaTest, ...@@ -109,6 +104,7 @@ class InvalidPragmaTest : public PragmaTest,
TEST_P(InvalidPragmaTest, Identified) TEST_P(InvalidPragmaTest, Identified)
{ {
const char* str = GetParam(); const char* str = GetParam();
const char* expected = "\n";
using testing::_; using testing::_;
// No handlePragma calls. // No handlePragma calls.
...@@ -118,7 +114,7 @@ TEST_P(InvalidPragmaTest, Identified) ...@@ -118,7 +114,7 @@ TEST_P(InvalidPragmaTest, Identified)
print(pp::Diagnostics::UNRECOGNIZED_PRAGMA, print(pp::Diagnostics::UNRECOGNIZED_PRAGMA,
pp::SourceLocation(0, 1), _)); pp::SourceLocation(0, 1), _));
preprocess(str); preprocess(str, expected);
} }
INSTANTIATE_TEST_CASE_P(All, InvalidPragmaTest, testing::Values( INSTANTIATE_TEST_CASE_P(All, InvalidPragmaTest, testing::Values(
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
class SpaceTest : public PreprocessorTest class SpaceTest : public PreprocessorTest
{ {
protected: protected:
void preprocess(const std::string& str) void expectSpace(const std::string& str)
{ {
const char* cstr = str.c_str(); const char* cstr = str.c_str();
ASSERT_TRUE(mPreprocessor.init(1, &cstr, 0)); ASSERT_TRUE(mPreprocessor.init(1, &cstr, 0));
...@@ -42,8 +42,8 @@ TEST_P(SpaceCharTest, SpaceIgnored) ...@@ -42,8 +42,8 @@ TEST_P(SpaceCharTest, SpaceIgnored)
// Construct test string with the whitespace char before "foo". // Construct test string with the whitespace char before "foo".
std::string str(1, GetParam()); std::string str(1, GetParam());
str.append("foo"); str.append("foo");
preprocess(str); expectSpace(str);
} }
INSTANTIATE_TEST_CASE_P(SingleSpaceChar, INSTANTIATE_TEST_CASE_P(SingleSpaceChar,
...@@ -68,7 +68,7 @@ TEST_P(SpaceStringTest, SpaceIgnored) ...@@ -68,7 +68,7 @@ TEST_P(SpaceStringTest, SpaceIgnored)
str.push_back(std::tr1::get<2>(GetParam())); str.push_back(std::tr1::get<2>(GetParam()));
str.append("foo"); str.append("foo");
preprocess(str); expectSpace(str);
} }
INSTANTIATE_TEST_CASE_P(SpaceCharCombination, INSTANTIATE_TEST_CASE_P(SpaceCharCombination,
......
...@@ -9,21 +9,12 @@ ...@@ -9,21 +9,12 @@
class VersionTest : public PreprocessorTest class VersionTest : public PreprocessorTest
{ {
protected:
void preprocess(const char* str)
{
ASSERT_TRUE(mPreprocessor.init(1, &str, NULL));
pp::Token token;
mPreprocessor.lex(&token);
EXPECT_EQ(pp::Token::LAST, token.type);
EXPECT_EQ("", token.value);
}
}; };
TEST_F(VersionTest, Valid) TEST_F(VersionTest, Valid)
{ {
const char* str = "#version 200\n"; const char* str = "#version 200\n";
const char* expected = "\n";
using testing::_; using testing::_;
EXPECT_CALL(mDirectiveHandler, EXPECT_CALL(mDirectiveHandler,
...@@ -31,7 +22,7 @@ TEST_F(VersionTest, Valid) ...@@ -31,7 +22,7 @@ TEST_F(VersionTest, Valid)
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(VersionTest, CommentsIgnored) TEST_F(VersionTest, CommentsIgnored)
...@@ -45,6 +36,7 @@ TEST_F(VersionTest, CommentsIgnored) ...@@ -45,6 +36,7 @@ TEST_F(VersionTest, CommentsIgnored)
"/*foo*/" "/*foo*/"
"//foo" "//foo"
"\n"; "\n";
const char* expected = "\n";
using testing::_; using testing::_;
EXPECT_CALL(mDirectiveHandler, EXPECT_CALL(mDirectiveHandler,
...@@ -52,12 +44,13 @@ TEST_F(VersionTest, CommentsIgnored) ...@@ -52,12 +44,13 @@ TEST_F(VersionTest, CommentsIgnored)
// No error or warning. // No error or warning.
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0); EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
preprocess(str); preprocess(str, expected);
} }
TEST_F(VersionTest, MissingNewline) TEST_F(VersionTest, MissingNewline)
{ {
const char* str = "#version 200"; const char* str = "#version 200";
const char* expected = "";
using testing::_; using testing::_;
// Directive successfully parsed. // Directive successfully parsed.
...@@ -66,7 +59,7 @@ TEST_F(VersionTest, MissingNewline) ...@@ -66,7 +59,7 @@ TEST_F(VersionTest, MissingNewline)
// Error reported about EOF. // Error reported about EOF.
EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::EOF_IN_DIRECTIVE, _, _)); EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::EOF_IN_DIRECTIVE, _, _));
preprocess(str); preprocess(str, expected);
} }
struct VersionTestParam struct VersionTestParam
...@@ -83,6 +76,7 @@ class InvalidVersionTest : public VersionTest, ...@@ -83,6 +76,7 @@ class InvalidVersionTest : public VersionTest,
TEST_P(InvalidVersionTest, Identified) TEST_P(InvalidVersionTest, Identified)
{ {
VersionTestParam param = GetParam(); VersionTestParam param = GetParam();
const char* expected = "\n";
using testing::_; using testing::_;
// No handleVersion call. // No handleVersion call.
...@@ -90,7 +84,7 @@ TEST_P(InvalidVersionTest, Identified) ...@@ -90,7 +84,7 @@ TEST_P(InvalidVersionTest, Identified)
// Invalid version directive call. // Invalid version directive call.
EXPECT_CALL(mDiagnostics, print(param.id, pp::SourceLocation(0, 1), _)); EXPECT_CALL(mDiagnostics, print(param.id, pp::SourceLocation(0, 1), _));
preprocess(param.str); preprocess(param.str, expected);
} }
static const VersionTestParam kParams[] = { static const VersionTestParam kParams[] = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment