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,11 +36,13 @@ StructMember::StructMember(
|
|||
StructMember::~StructMember() = default;
|
||||
|
||||
bool StructMember::IsValid() const {
|
||||
if (name_.empty()) {
|
||||
if (name_.empty() || type_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (type_ == nullptr) {
|
||||
return false;
|
||||
for (const auto& deco : decorations_) {
|
||||
if (deco == nullptr) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -69,6 +69,16 @@ TEST_F(StructMemberTest, IsValid_NullType) {
|
|||
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) {
|
||||
type::I32Type i32;
|
||||
std::vector<std::unique_ptr<StructMemberDecoration>> decorations;
|
||||
|
@ -76,16 +86,16 @@ TEST_F(StructMemberTest, ToStr) {
|
|||
|
||||
StructMember st{"a", &i32, std::move(decorations)};
|
||||
std::ostringstream out;
|
||||
st.to_str(out, 0);
|
||||
EXPECT_EQ(out.str(), "StructMember{[[ offset 4 ]] a: __i32}\n");
|
||||
st.to_str(out, 2);
|
||||
EXPECT_EQ(out.str(), " StructMember{[[ offset 4 ]] a: __i32}\n");
|
||||
}
|
||||
|
||||
TEST_F(StructMemberTest, ToStrNoDecorations) {
|
||||
type::I32Type i32;
|
||||
StructMember st{"a", &i32, {}};
|
||||
std::ostringstream out;
|
||||
st.to_str(out, 0);
|
||||
EXPECT_EQ(out.str(), "StructMember{a: __i32}\n");
|
||||
st.to_str(out, 2);
|
||||
EXPECT_EQ(out.str(), " StructMember{a: __i32}\n");
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
|
|
Loading…
Reference in New Issue