Add more StructMember tests.
This Cl adds more IsValid tests to the StructMember AST node. Bug: tint:11 Change-Id: I7fec6fb5e96f025735fd444c74f97d4ded8b3ae6 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/16671 Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This commit is contained in:
parent
7c44407cd3
commit
097c3a544d
|
@ -36,12 +36,14 @@ StructMember::StructMember(
|
||||||
StructMember::~StructMember() = default;
|
StructMember::~StructMember() = default;
|
||||||
|
|
||||||
bool StructMember::IsValid() const {
|
bool StructMember::IsValid() const {
|
||||||
if (name_.empty()) {
|
if (name_.empty() || type_ == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (type_ == nullptr) {
|
for (const auto& deco : decorations_) {
|
||||||
|
if (deco == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,16 @@ TEST_F(StructMemberTest, IsValid_NullType) {
|
||||||
EXPECT_FALSE(st.IsValid());
|
EXPECT_FALSE(st.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(StructMemberTest, IsValid_Null_Decoration) {
|
||||||
|
type::I32Type i32;
|
||||||
|
std::vector<std::unique_ptr<StructMemberDecoration>> decorations;
|
||||||
|
decorations.emplace_back(std::make_unique<StructMemberOffsetDecoration>(4));
|
||||||
|
decorations.push_back(nullptr);
|
||||||
|
|
||||||
|
StructMember st{"a", &i32, std::move(decorations)};
|
||||||
|
EXPECT_FALSE(st.IsValid());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(StructMemberTest, ToStr) {
|
TEST_F(StructMemberTest, ToStr) {
|
||||||
type::I32Type i32;
|
type::I32Type i32;
|
||||||
std::vector<std::unique_ptr<StructMemberDecoration>> decorations;
|
std::vector<std::unique_ptr<StructMemberDecoration>> decorations;
|
||||||
|
@ -76,7 +86,7 @@ TEST_F(StructMemberTest, ToStr) {
|
||||||
|
|
||||||
StructMember st{"a", &i32, std::move(decorations)};
|
StructMember st{"a", &i32, std::move(decorations)};
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
st.to_str(out, 0);
|
st.to_str(out, 2);
|
||||||
EXPECT_EQ(out.str(), " StructMember{[[ offset 4 ]] a: __i32}\n");
|
EXPECT_EQ(out.str(), " StructMember{[[ offset 4 ]] a: __i32}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +94,7 @@ TEST_F(StructMemberTest, ToStrNoDecorations) {
|
||||||
type::I32Type i32;
|
type::I32Type i32;
|
||||||
StructMember st{"a", &i32, {}};
|
StructMember st{"a", &i32, {}};
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
st.to_str(out, 0);
|
st.to_str(out, 2);
|
||||||
EXPECT_EQ(out.str(), " StructMember{a: __i32}\n");
|
EXPECT_EQ(out.str(), " StructMember{a: __i32}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue