Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/preprocessor_tests/pragma_test.cpp
1693 views
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 PragmaTest : public SimplePreprocessorTest
14
{};
15
16
TEST_F(PragmaTest, EmptyName)
17
{
18
const char *str = "#pragma\n";
19
const char *expected = "\n";
20
21
using testing::_;
22
// No handlePragma calls.
23
EXPECT_CALL(mDirectiveHandler, handlePragma(_, _, _, false)).Times(0);
24
// No error or warning.
25
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
26
27
preprocess(str, expected);
28
}
29
30
TEST_F(PragmaTest, EmptyValue)
31
{
32
const char *str = "#pragma foo\n";
33
const char *expected = "\n";
34
35
using testing::_;
36
EXPECT_CALL(mDirectiveHandler, handlePragma(pp::SourceLocation(0, 1), "foo", "", false));
37
// No error or warning.
38
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
39
40
preprocess(str, expected);
41
}
42
43
TEST_F(PragmaTest, NameValue)
44
{
45
const char *str = "#pragma foo(bar)\n";
46
const char *expected = "\n";
47
48
using testing::_;
49
EXPECT_CALL(mDirectiveHandler, handlePragma(pp::SourceLocation(0, 1), "foo", "bar", false));
50
// No error or warning.
51
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
52
53
preprocess(str, expected);
54
}
55
56
TEST_F(PragmaTest, STDGL)
57
{
58
const char *str = "#pragma STDGL\n";
59
const char *expected = "\n";
60
61
using testing::_;
62
EXPECT_CALL(mDirectiveHandler, handlePragma(_, _, _, _)).Times(0);
63
// No error or warning.
64
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
65
66
preprocess(str, expected);
67
}
68
69
TEST_F(PragmaTest, STDGLInvariantAll)
70
{
71
const char *str = "#pragma STDGL invariant(all)\n";
72
const char *expected = "\n";
73
74
using testing::_;
75
EXPECT_CALL(mDirectiveHandler,
76
handlePragma(pp::SourceLocation(0, 1), "invariant", "all", true));
77
// No error or warning.
78
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
79
80
preprocess(str, expected);
81
}
82
83
TEST_F(PragmaTest, Comments)
84
{
85
const char *str =
86
"/*foo*/"
87
"#"
88
"/*foo*/"
89
"pragma"
90
"/*foo*/"
91
"foo"
92
"/*foo*/"
93
"("
94
"/*foo*/"
95
"bar"
96
"/*foo*/"
97
")"
98
"/*foo*/"
99
"//foo"
100
"\n";
101
const char *expected = "\n";
102
103
using testing::_;
104
EXPECT_CALL(mDirectiveHandler, handlePragma(pp::SourceLocation(0, 1), "foo", "bar", false));
105
// No error or warning.
106
EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
107
108
preprocess(str, expected);
109
}
110
111
TEST_F(PragmaTest, MissingNewline)
112
{
113
const char *str = "#pragma foo(bar)";
114
const char *expected = "";
115
116
using testing::_;
117
// Pragma successfully parsed.
118
EXPECT_CALL(mDirectiveHandler, handlePragma(pp::SourceLocation(0, 1), "foo", "bar", false));
119
// Error reported about EOF.
120
EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_EOF_IN_DIRECTIVE, _, _));
121
122
preprocess(str, expected);
123
}
124
125
class InvalidPragmaTest : public PragmaTest, public testing::WithParamInterface<const char *>
126
{};
127
128
TEST_P(InvalidPragmaTest, Identified)
129
{
130
const char *str = GetParam();
131
const char *expected = "\n";
132
133
using testing::_;
134
// No handlePragma calls.
135
EXPECT_CALL(mDirectiveHandler, handlePragma(_, _, _, false)).Times(0);
136
// Unrecognized pragma warning.
137
EXPECT_CALL(mDiagnostics,
138
print(pp::Diagnostics::PP_UNRECOGNIZED_PRAGMA, pp::SourceLocation(0, 1), _));
139
140
preprocess(str, expected);
141
}
142
143
INSTANTIATE_TEST_SUITE_P(All,
144
InvalidPragmaTest,
145
testing::Values("#pragma 1\n", // Invalid name.
146
"#pragma foo()\n", // Missing value.
147
"#pragma foo bar)\n", // Missing left paren,
148
"#pragma foo(bar\n", // Missing right paren.
149
"#pragma foo bar\n", // Missing parens.
150
"#pragma foo(bar) baz\n")); // Extra tokens.
151
152
} // namespace angle
153
154