Add Variable test for invalid initializer.
This CL adds a test to the variable AST node to verify the initializer is valid. Bug: tint:11 Change-Id: I95553e8572124e8e2e861b451003e5c9bf6358f1 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/16743 Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This commit is contained in:
parent
02d94b2903
commit
1e31f161db
|
@ -44,6 +44,9 @@ bool Variable::IsValid() const {
|
||||||
if (type_ == nullptr) {
|
if (type_ == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (initializer_ && !initializer_->IsValid()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "src/ast/variable.h"
|
#include "src/ast/variable.h"
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/type/f32_type.h"
|
#include "src/ast/type/f32_type.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
|
|
||||||
|
@ -69,6 +70,13 @@ TEST_F(VariableTest, IsValid) {
|
||||||
EXPECT_TRUE(v.IsValid());
|
EXPECT_TRUE(v.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(VariableTest, IsValid_WithInitializer) {
|
||||||
|
type::I32Type t;
|
||||||
|
Variable v{"my_var", StorageClass::kNone, &t};
|
||||||
|
v.set_initializer(std::make_unique<IdentifierExpression>("ident"));
|
||||||
|
EXPECT_TRUE(v.IsValid());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(VariableTest, IsValid_MissinName) {
|
TEST_F(VariableTest, IsValid_MissinName) {
|
||||||
type::I32Type t;
|
type::I32Type t;
|
||||||
Variable v{"", StorageClass::kNone, &t};
|
Variable v{"", StorageClass::kNone, &t};
|
||||||
|
@ -85,6 +93,13 @@ TEST_F(VariableTest, IsValid_MissingBoth) {
|
||||||
EXPECT_FALSE(v.IsValid());
|
EXPECT_FALSE(v.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(VariableTest, IsValid_InvalidInitializer) {
|
||||||
|
type::I32Type t;
|
||||||
|
Variable v{"my_var", StorageClass::kNone, &t};
|
||||||
|
v.set_initializer(std::make_unique<IdentifierExpression>(""));
|
||||||
|
EXPECT_FALSE(v.IsValid());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(VariableTest, to_str) {
|
TEST_F(VariableTest, to_str) {
|
||||||
type::F32Type t;
|
type::F32Type t;
|
||||||
Variable v{"my_var", StorageClass::kFunction, &t};
|
Variable v{"my_var", StorageClass::kFunction, &t};
|
||||||
|
|
Loading…
Reference in New Issue