1 // 2 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 #include "PreprocessorTest.h" 8 #include "Token.h" 9 10 class CommentTest : public PreprocessorTest, 11 public testing::WithParamInterface<const char*> 12 { 13 }; 14 15 TEST_P(CommentTest, CommentIgnored) 16 { 17 const char* str = GetParam(); 18 19 ASSERT_TRUE(mPreprocessor.init(1, &str, 0)); 20 21 pp::Token token; 22 mPreprocessor.lex(&token); 23 EXPECT_EQ(pp::Token::LAST, token.type); 24 } 25 26 INSTANTIATE_TEST_CASE_P(LineComment, CommentTest, 27 testing::Values("//foo\n", // With newline. 28 "//foo", // Without newline. 29 "//**/", // Nested block comment. 30 "////", // Nested line comment. 31 "//\"")); // Invalid character. 32 33 INSTANTIATE_TEST_CASE_P(BlockComment, CommentTest, 34 testing::Values("/*foo*/", 35 "/*foo\n*/", // With newline. 36 "/*//*/", // Nested line comment. 37 "/*/**/", // Nested block comment. 38 "/***/", // With lone '*'. 39 "/*\"*/")); // Invalid character. 40 41 class BlockCommentTest : public PreprocessorTest 42 { 43 }; 44 45 TEST_F(BlockCommentTest, CommentReplacedWithSpace) 46 { 47 const char* str = "/*foo*/bar"; 48 49 ASSERT_TRUE(mPreprocessor.init(1, &str, 0)); 50 51 pp::Token token; 52 mPreprocessor.lex(&token); 53 EXPECT_EQ(pp::Token::IDENTIFIER, token.type); 54 EXPECT_EQ("bar", token.text); 55 EXPECT_TRUE(token.hasLeadingSpace()); 56 } 57 58 TEST_F(BlockCommentTest, UnterminatedComment) 59 { 60 const char* str = "/*foo"; 61 62 ASSERT_TRUE(mPreprocessor.init(1, &str, 0)); 63 64 using testing::_; 65 EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_EOF_IN_COMMENT, _, _)); 66 67 pp::Token token; 68 mPreprocessor.lex(&token); 69 } 70