-
-
Notifications
You must be signed in to change notification settings - Fork 462
Expand file tree
/
Copy pathHLSLParserTest.cpp
More file actions
64 lines (53 loc) · 1.37 KB
/
Copy pathHLSLParserTest.cpp
File metadata and controls
64 lines (53 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <gtest/gtest.h>
#include <HLSLParser.h>
#include <HLSLTree.h>
#include <cstring>
namespace {
bool ParseHLSL(const char* code)
{
M4::Allocator allocator;
M4::HLSLTree tree(&allocator);
M4::HLSLParser parser(&allocator, &tree);
return parser.Parse("test.hlsl", code, strlen(code));
}
} // namespace
// Regression test for issue #940: parenthesized constructor with binary operator
// was rejected with "expected ';'" error.
TEST(HLSLParser, ParenthesizedConstructorWithMultiply)
{
EXPECT_TRUE(ParseHLSL(
"float scalar = 2.0;\n"
"float2 var = (float2(1.0, 2.0)) * scalar;\n"
));
}
TEST(HLSLParser, ParenthesizedConstructorWithAdd)
{
EXPECT_TRUE(ParseHLSL(
"float2 var = (float2(1.0, 2.0)) + float2(3.0, 4.0);\n"
));
}
TEST(HLSLParser, DoubleNestedParensWithOperator)
{
EXPECT_TRUE(ParseHLSL(
"float2 var = ((float2(1.0, 2.0))) * 2.0;\n"
));
}
TEST(HLSLParser, BothOperandsParenthesized)
{
EXPECT_TRUE(ParseHLSL(
"float2 var = (float2(1.0, 2.0)) * (float2(3.0, 4.0));\n"
));
}
TEST(HLSLParser, ChainedOperatorsAfterParens)
{
EXPECT_TRUE(ParseHLSL(
"float a = 1.0; float b = 2.0; float c = 3.0;\n"
"float x = (a) * b + c;\n"
));
}
TEST(HLSLParser, ConstructorWithoutParensStillWorks)
{
EXPECT_TRUE(ParseHLSL(
"float2 var = float2(1.0, 2.0) * 2.0;\n"
));
}