1 //
2 // Copyright 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 "compiler/preprocessor/Token.h"
9
10 namespace angle
11 {
12
13 class CommentTest : public SimplePreprocessorTest, public testing::WithParamInterface<const char *>
14 {};
15
TEST_P(CommentTest,CommentIgnored)16 TEST_P(CommentTest, CommentIgnored)
17 {
18 const char *str = GetParam();
19
20 pp::Token token;
21 lexSingleToken(str, &token);
22 EXPECT_EQ(pp::Token::LAST, token.type);
23 }
24
25 INSTANTIATE_TEST_SUITE_P(LineComment,
26 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_SUITE_P(BlockComment,
34 CommentTest,
35 testing::Values("/*foo*/",
36 "/*foo\n*/", // With newline.
37 "/*//*/", // Nested line comment.
38 "/*/**/", // Nested block comment.
39 "/***/", // With lone '*'.
40 "/*\"*/")); // Invalid character.
41
42 class BlockCommentTest : public SimplePreprocessorTest
43 {};
44
TEST_F(BlockCommentTest,CommentReplacedWithSpace)45 TEST_F(BlockCommentTest, CommentReplacedWithSpace)
46 {
47 const char *str = "/*foo*/bar";
48
49 pp::Token token;
50 lexSingleToken(str, &token);
51 EXPECT_EQ(pp::Token::IDENTIFIER, token.type);
52 EXPECT_EQ("bar", token.text);
53 EXPECT_TRUE(token.hasLeadingSpace());
54 }
55
TEST_F(BlockCommentTest,UnterminatedComment)56 TEST_F(BlockCommentTest, UnterminatedComment)
57 {
58 const char *str = "/*foo";
59
60 using testing::_;
61 EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_EOF_IN_COMMENT, _, _));
62
63 preprocess(str);
64 }
65
66 } // namespace angle
67