From 994b70feb919b49acd46ae5d71a1af5ee3192bd5 Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Wed, 21 Dec 2022 21:15:03 +0000 Subject: [PATCH] tint: add AFloat and AInt const eval scalar constructor tests Bug: tint:1581 Change-Id: I0cb190e3114f3fd1c68f4cb821399547830239a2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/115240 Reviewed-by: James Price Kokoro: Kokoro --- .../resolver/const_eval_construction_test.cc | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/tint/resolver/const_eval_construction_test.cc b/src/tint/resolver/const_eval_construction_test.cc index 93871b48f7..32fb5cd807 100644 --- a/src/tint/resolver/const_eval_construction_test.cc +++ b/src/tint/resolver/const_eval_construction_test.cc @@ -19,6 +19,40 @@ using namespace tint::number_suffixes; // NOLINT namespace tint::resolver { namespace { +TEST_F(ResolverConstEvalTest, Scalar_AFloat) { + auto* expr = Expr(99.0_a); + auto* a = Const("a", expr); + WrapInFunction(a); + + EXPECT_TRUE(r()->Resolve()) << r()->error(); + + auto* sem = Sem().Get(expr); + ASSERT_NE(sem, nullptr); + EXPECT_TRUE(sem->Type()->Is()); + EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type()); + EXPECT_TRUE(sem->ConstantValue()->AllEqual()); + EXPECT_FALSE(sem->ConstantValue()->AnyZero()); + EXPECT_FALSE(sem->ConstantValue()->AllZero()); + EXPECT_EQ(sem->ConstantValue()->ValueAs(), 99.0f); +} + +TEST_F(ResolverConstEvalTest, Scalar_AInt) { + auto* expr = Expr(99_a); + auto* a = Const("a", expr); + WrapInFunction(a); + + EXPECT_TRUE(r()->Resolve()) << r()->error(); + + auto* sem = Sem().Get(expr); + ASSERT_NE(sem, nullptr); + EXPECT_TRUE(sem->Type()->Is()); + EXPECT_TYPE(sem->ConstantValue()->Type(), sem->Type()); + EXPECT_TRUE(sem->ConstantValue()->AllEqual()); + EXPECT_FALSE(sem->ConstantValue()->AnyZero()); + EXPECT_FALSE(sem->ConstantValue()->AllZero()); + EXPECT_EQ(sem->ConstantValue()->ValueAs(), 99); +} + TEST_F(ResolverConstEvalTest, Scalar_i32) { auto* expr = Expr(99_i); WrapInFunction(expr);