diff --git a/src/tint/sem/constant_test.cc b/src/tint/sem/constant_test.cc index 27cea729af..b3ab0257f7 100644 --- a/src/tint/sem/constant_test.cc +++ b/src/tint/sem/constant_test.cc @@ -69,105 +69,155 @@ TEST_F(ConstantTest, ConstructorInitializerList) { } TEST_F(ConstantTest, Element_ai) { - Constant c(create(), {1_a}); + auto* ty = create(); + Constant c(ty, {1_a}); EXPECT_EQ(c.Element(0), 1_a); EXPECT_EQ(c.ElementCount(), 1u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), ty); } TEST_F(ConstantTest, Element_i32) { - Constant c(create(), {1_a}); + auto* ty = create(); + Constant c(ty, {1_a}); EXPECT_EQ(c.Element(0), 1_i); EXPECT_EQ(c.ElementCount(), 1u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), ty); } TEST_F(ConstantTest, Element_u32) { - Constant c(create(), {1_a}); + auto* ty = create(); + Constant c(ty, {1_a}); EXPECT_EQ(c.Element(0), 1_u); EXPECT_EQ(c.ElementCount(), 1u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), ty); } TEST_F(ConstantTest, Element_bool) { - Constant c(create(), {true}); + auto* ty = create(); + Constant c(ty, {true}); EXPECT_EQ(c.Element(0), true); EXPECT_EQ(c.ElementCount(), 1u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), ty); } TEST_F(ConstantTest, Element_af) { - Constant c(create(), {1.0_a}); + auto* ty = create(); + Constant c(ty, {1.0_a}); EXPECT_EQ(c.Element(0), 1.0_a); EXPECT_EQ(c.ElementCount(), 1u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), ty); } TEST_F(ConstantTest, Element_f32) { - Constant c(create(), {1.0_a}); + auto* ty = create(); + Constant c(ty, {1.0_a}); EXPECT_EQ(c.Element(0), 1.0_f); EXPECT_EQ(c.ElementCount(), 1u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), ty); } TEST_F(ConstantTest, Element_f16) { - Constant c(create(), {1.0_a}); + auto* ty = create(); + Constant c(ty, {1.0_a}); EXPECT_EQ(c.Element(0), 1.0_h); EXPECT_EQ(c.ElementCount(), 1u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), ty); } TEST_F(ConstantTest, Element_vec3_ai) { - Constant c(create(create(), 3u), {1_a, 2_a, 3_a}); + auto* el_ty = create(); + auto* ty = create(el_ty, 3u); + Constant c(ty, {1_a, 2_a, 3_a}); EXPECT_EQ(c.Element(0), 1_a); EXPECT_EQ(c.Element(1), 2_a); EXPECT_EQ(c.Element(2), 3_a); EXPECT_EQ(c.ElementCount(), 3u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), el_ty); } TEST_F(ConstantTest, Element_vec3_i32) { - Constant c(create(create(), 3u), {1_a, 2_a, 3_a}); + auto* el_ty = create(); + auto* ty = create(el_ty, 3u); + Constant c(ty, {1_a, 2_a, 3_a}); EXPECT_EQ(c.Element(0), 1_i); EXPECT_EQ(c.Element(1), 2_i); EXPECT_EQ(c.Element(2), 3_i); EXPECT_EQ(c.ElementCount(), 3u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), el_ty); } TEST_F(ConstantTest, Element_vec3_u32) { - Constant c(create(create(), 3u), {1_a, 2_a, 3_a}); + auto* el_ty = create(); + auto* ty = create(el_ty, 3u); + Constant c(ty, {1_a, 2_a, 3_a}); EXPECT_EQ(c.Element(0), 1_u); EXPECT_EQ(c.Element(1), 2_u); EXPECT_EQ(c.Element(2), 3_u); EXPECT_EQ(c.ElementCount(), 3u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), el_ty); } TEST_F(ConstantTest, Element_vec3_bool) { - Constant c(create(create(), 2u), {true, false}); + auto* el_ty = create(); + auto* ty = create(el_ty, 2u); + Constant c(ty, {true, false}); EXPECT_EQ(c.Element(0), true); EXPECT_EQ(c.Element(1), false); EXPECT_EQ(c.ElementCount(), 2u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), el_ty); } TEST_F(ConstantTest, Element_vec3_af) { - Constant c(create(create(), 3u), {1.0_a, 2.0_a, 3.0_a}); + auto* el_ty = create(); + auto* ty = create(el_ty, 3u); + Constant c(ty, {1.0_a, 2.0_a, 3.0_a}); EXPECT_EQ(c.Element(0), 1.0_a); EXPECT_EQ(c.Element(1), 2.0_a); EXPECT_EQ(c.Element(2), 3.0_a); EXPECT_EQ(c.ElementCount(), 3u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), el_ty); } TEST_F(ConstantTest, Element_vec3_f32) { - Constant c(create(create(), 3u), {1.0_a, 2.0_a, 3.0_a}); + auto* el_ty = create(); + auto* ty = create(el_ty, 3u); + Constant c(ty, {1.0_a, 2.0_a, 3.0_a}); EXPECT_EQ(c.Element(0), 1.0_f); EXPECT_EQ(c.Element(1), 2.0_f); EXPECT_EQ(c.Element(2), 3.0_f); EXPECT_EQ(c.ElementCount(), 3u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), el_ty); } TEST_F(ConstantTest, Element_vec3_f16) { - Constant c(create(create(), 3u), {1.0_a, 2.0_a, 3.0_a}); + auto* el_ty = create(); + auto* ty = create(el_ty, 3u); + Constant c(ty, {1.0_a, 2.0_a, 3.0_a}); EXPECT_EQ(c.Element(0), 1.0_h); EXPECT_EQ(c.Element(1), 2.0_h); EXPECT_EQ(c.Element(2), 3.0_h); EXPECT_EQ(c.ElementCount(), 3u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), el_ty); } TEST_F(ConstantTest, Element_mat2x3_af) { - Constant c(create(create(create(), 3u), 2u), - {1.0_a, 2.0_a, 3.0_a, 4.0_a, 5.0_a, 6.0_a}); + auto* el_ty = create(); + auto* ty = create(create(el_ty, 3u), 2u); + Constant c(ty, {1.0_a, 2.0_a, 3.0_a, 4.0_a, 5.0_a, 6.0_a}); EXPECT_EQ(c.Element(0), 1.0_a); EXPECT_EQ(c.Element(1), 2.0_a); EXPECT_EQ(c.Element(2), 3.0_a); @@ -175,11 +225,14 @@ TEST_F(ConstantTest, Element_mat2x3_af) { EXPECT_EQ(c.Element(4), 5.0_a); EXPECT_EQ(c.Element(5), 6.0_a); EXPECT_EQ(c.ElementCount(), 6u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), el_ty); } TEST_F(ConstantTest, Element_mat2x3_f32) { - Constant c(create(create(create(), 3u), 2u), - {1.0_a, 2.0_a, 3.0_a, 4.0_a, 5.0_a, 6.0_a}); + auto* el_ty = create(); + auto* ty = create(create(el_ty, 3u), 2u); + Constant c(ty, {1.0_a, 2.0_a, 3.0_a, 4.0_a, 5.0_a, 6.0_a}); EXPECT_EQ(c.Element(0), 1.0_f); EXPECT_EQ(c.Element(1), 2.0_f); EXPECT_EQ(c.Element(2), 3.0_f); @@ -187,11 +240,14 @@ TEST_F(ConstantTest, Element_mat2x3_f32) { EXPECT_EQ(c.Element(4), 5.0_f); EXPECT_EQ(c.Element(5), 6.0_f); EXPECT_EQ(c.ElementCount(), 6u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), el_ty); } TEST_F(ConstantTest, Element_mat2x3_f16) { - Constant c(create(create(create(), 3u), 2u), - {1.0_a, 2.0_a, 3.0_a, 4.0_a, 5.0_a, 6.0_a}); + auto* el_ty = create(); + auto* ty = create(create(el_ty, 3u), 2u); + Constant c(ty, {1.0_a, 2.0_a, 3.0_a, 4.0_a, 5.0_a, 6.0_a}); EXPECT_EQ(c.Element(0), 1.0_h); EXPECT_EQ(c.Element(1), 2.0_h); EXPECT_EQ(c.Element(2), 3.0_h); @@ -199,6 +255,8 @@ TEST_F(ConstantTest, Element_mat2x3_f16) { EXPECT_EQ(c.Element(4), 5.0_h); EXPECT_EQ(c.Element(5), 6.0_h); EXPECT_EQ(c.ElementCount(), 6u); + EXPECT_TYPE(c.Type(), ty); + EXPECT_TYPE(c.ElementType(), el_ty); } TEST_F(ConstantTest, AnyZero) {