| // Copyright 2020 The Tint Authors. | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // http://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| #include "src/tint/lang/spirv/writer/ast_printer/scalar_constant.h" | |
| #include "src/tint/lang/spirv/writer/ast_printer/helper_test.h" | |
| namespace tint::spirv::writer { | |
| namespace { | |
| using SpirvASTPrinterScalarConstantTest = TestHelper; | |
| TEST_F(SpirvASTPrinterScalarConstantTest, Equality) { | |
| ScalarConstant a{}; | |
| ScalarConstant b{}; | |
| EXPECT_EQ(a, b); | |
| a.kind = ScalarConstant::Kind::kU32; | |
| EXPECT_NE(a, b); | |
| b.kind = ScalarConstant::Kind::kU32; | |
| EXPECT_EQ(a, b); | |
| a.value.b = true; | |
| EXPECT_NE(a, b); | |
| b.value.b = true; | |
| EXPECT_EQ(a, b); | |
| } | |
| TEST_F(SpirvASTPrinterScalarConstantTest, U32) { | |
| auto c = ScalarConstant::U32(123); | |
| EXPECT_EQ(c.value.u32, 123u); | |
| EXPECT_EQ(c.kind, ScalarConstant::Kind::kU32); | |
| } | |
| TEST_F(SpirvASTPrinterScalarConstantTest, F16) { | |
| auto c = ScalarConstant::F16(123.456f); | |
| // 123.456f will be quantized to f16 123.4375h, bit pattern 0x57b7 | |
| EXPECT_EQ(c.value.f16.bits_representation, 0x57b7u); | |
| EXPECT_EQ(c.kind, ScalarConstant::Kind::kF16); | |
| } | |
| } // namespace | |
| } // namespace tint::spirv::writer |