43TEST(bsl_grammar, EmptyTranslationUnit)
51TEST(bsl_grammar, PreprocessorDirectives)
54 "#define MY_MACRO 1\n"
56 "#define TEST_VAL 2.0\n"
61TEST(bsl_grammar, NamespaceDeclarations)
64 "namespace blender::gpu::shader {\n"
65 " struct InnerStruct {};\n"
70TEST(bsl_grammar, UsingStatements)
73 "using namespace blender::gpu;\n"
74 "using MyType = other::Namespace::Type;");
78TEST(bsl_grammar, StandardStructDeclaration)
88TEST(bsl_grammar, StructWithAccessSpecifiers)
95 " float private_var;\n"
100TEST(bsl_grammar, MemberKeywordsAndAttributes)
104 "struct HostShared {\n"
105 " static const int constant_val = 42;\n"
106 " constexpr float pi = 3.14159;\n"
111TEST(bsl_grammar, PipelineDeclarations)
114 "PipelineGraphic MyGraphicsPipeline(int sub_pass, float scale);\n"
115 "PipelineCompute MyComputePipeline(int work_groups);");
119TEST(bsl_grammar, TemplateDeclarationsAndInstantiations)
122 "template <typename T, int N>\n"
123 "struct BufferArray {\n"
126 "template struct BufferArray<float, 4>;");
130TEST(bsl_grammar, FunctionDeclarationsAndDefinitions)
133 "void compute_data(const int input, float &output) {\n"
134 " output = float(input) * 2.0;\n"
139TEST(bsl_grammar, ConditionalStatements)
142 "void check_value(int x) {\n"
143 " if constexpr (true) {\n"
145 " } else if (x == 0) {\n"
154TEST(bsl_grammar, LoopConstructs)
158 " for (int i = 0; i < 10; i++) { break; }\n"
159 " while (false) { continue; }\n"
160 " do { int x = 0; } while (false);\n"
165TEST(bsl_grammar, SwitchCaseParsing)
168 "void handle_switch(int val) {\n"
186 TestParser unsupported(
"[[vendor::attribute(1, 2)]] int structural_func();");
187 EXPECT_EQ(unsupported.
error(),
"Unexpected token \":\", expected attribute");
194 "enum class Color : int {\n"
203 "enum InvalidEnum {\n"
206 EXPECT_EQ(
parser.error(),
"enum declaration must explicitly use an underlying type");
210TEST(bsl_grammar, ForwardClassDeclarations)
213 EXPECT_EQ(
parser.error(),
"Forward declaration of classes is not supported");
216TEST(bsl_grammar, UnexpectedTokens)
219 EXPECT_EQ(
parser.error(),
"Unexpected token \"@\": Expecting declaration");
parser::IntermediateForm< parser::FullLexer, parser::FullParser > Parser
parser::ErrorHandler ErrorHandler
#define EXPECT_TRUE(result)
TEST(shader_tool, ExpressionParser)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
std::optional< Error > err
ast::LocalScope root() const
SourceProcessor::Parser Parser
parser::ast::LocalScope root() const
TestParser(const string &src)
SourceProcessor::ErrorHandler ErrorHandler