BoundArrayAccessors: Add more tests

Bug: tint:521
Change-Id: I0a9ea7f487b052d1ee6ffa5be079d18633acc72c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42844
Commit-Queue: Austin Eng <enga@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Ben Clayton 2021-02-26 18:53:36 +00:00 committed by Commit Bot service account
parent 4bd4b8fecb
commit d5638c93c5
1 changed files with 73 additions and 0 deletions

View File

@ -218,6 +218,79 @@ fn f() -> void {
EXPECT_EQ(expect, str(got)); EXPECT_EQ(expect, str(got));
} }
TEST_F(BoundArrayAccessorsTest, Vector_Swizzle_Idx_Scalar) {
auto* src = R"(
var a : vec3<f32>;
fn f() -> void {
var b : f32 = a.xy[2];
}
)";
auto* expect = R"(
var a : vec3<f32>;
fn f() -> void {
var b : f32 = a.xy[1];
}
)";
auto got = Transform<BoundArrayAccessors>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(BoundArrayAccessorsTest, Vector_Swizzle_Idx_Var) {
auto* src = R"(
var a : vec3<f32>;
var c : u32;
fn f() -> void {
var b : f32 = a.xy[c];
}
)";
auto* expect = R"(
var a : vec3<f32>;
var c : u32;
fn f() -> void {
var b : f32 = a.xy[min(u32(c), 1u)];
}
)";
auto got = Transform<BoundArrayAccessors>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(BoundArrayAccessorsTest, Vector_Swizzle_Idx_Expr) {
auto* src = R"(
var a : vec3<f32>;
var c : u32;
fn f() -> void {
var b : f32 = a.xy[c + 2 - 3];
}
)";
auto* expect = R"(
var a : vec3<f32>;
var c : u32;
fn f() -> void {
var b : f32 = a.xy[min(u32(((c + 2) - 3)), 1u)];
}
)";
auto got = Transform<BoundArrayAccessors>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) { TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) {
auto* src = R"( auto* src = R"(
var a : vec3<f32>; var a : vec3<f32>;