-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathlexerTests.cpp
83 lines (70 loc) · 1.42 KB
/
lexerTests.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "testsMain.h"
#include "../graphics/shader/lexer.h"
#include "../graphics/shader/parser.h"
#include "../util/log.h"
using namespace P3D;
static const char* code = R"(
struct Light {
vec3 position;
vec3 color;
float intensity;
Attenuation attenuation;
};
#define maxLights 10
uniform Light lights[maxLights];
)";
static const char* names[] = {
"Error",
"Comma",
"Semicolon",
"LeftParenthesis",
"RightParenthesis",
"Equals",
"Dot",
"InOut",
"Layout",
"Uniform",
"Qualifier",
"Struct",
"Version",
"Preprocessor",
"Datatype",
"Identifier",
"LeftCurl",
"RightCurl",
"LeftBracket",
"RightBracket",
"Number",
"Operator",
"SingleQuote",
"DoubleQuote",
"String",
"Comment",
"End"
};
TEST_CASE(lexVersionPreprocessor) {
using namespace P3D::Graphics;
const char* code = R"(
#version 123;
#version #ifdef 2 #else 4
)";
Lexer lexer(code);
auto current = lexer.next();
while(current.type != Lexer::Token::End) {
Log::debug("%s[%s]", names[current.type], current.string(code).c_str());
current = lexer.next();
}
}
TEST_CASE(lexShader) {
using namespace P3D::Graphics;
Lexer lexer(code);
auto current = lexer.next();
while(current.type != Lexer::Token::End) {
Log::debug("%s[%s]", names[current.type], current.string(code).c_str());
current = lexer.next();
}
}
TEST_CASE(parseShader) {
using namespace Graphics;
Parser::Parse result = Parser::parse(code);
}