| // 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/operand.h" |
| |
| #include "gtest/gtest.h" |
| |
| namespace tint::spirv::writer { |
| namespace { |
| |
| using SpirvWriterOperandtest = testing::Test; |
| |
| TEST_F(SpirvWriterOperandtest, CreateFloat) { |
| auto o = Operand(1.2f); |
| ASSERT_TRUE(std::holds_alternative<float>(o)); |
| EXPECT_FLOAT_EQ(std::get<float>(o), 1.2f); |
| } |
| |
| TEST_F(SpirvWriterOperandtest, CreateInt) { |
| auto o = Operand(1u); |
| ASSERT_TRUE(std::holds_alternative<uint32_t>(o)); |
| EXPECT_EQ(std::get<uint32_t>(o), 1u); |
| } |
| |
| TEST_F(SpirvWriterOperandtest, CreateString) { |
| auto o = Operand("my string"); |
| ASSERT_TRUE(std::holds_alternative<std::string>(o)); |
| EXPECT_EQ(std::get<std::string>(o), "my string"); |
| } |
| |
| TEST_F(SpirvWriterOperandtest, Length_Float) { |
| auto o = Operand(1.2f); |
| EXPECT_EQ(OperandLength(o), 1u); |
| } |
| |
| TEST_F(SpirvWriterOperandtest, Length_Int) { |
| auto o = U32Operand(1); |
| EXPECT_EQ(OperandLength(o), 1u); |
| } |
| |
| TEST_F(SpirvWriterOperandtest, Length_String) { |
| auto o = Operand("my string"); |
| EXPECT_EQ(OperandLength(o), 3u); |
| } |
| |
| TEST_F(SpirvWriterOperandtest, Length_String_Empty) { |
| auto o = Operand(""); |
| EXPECT_EQ(OperandLength(o), 1u); |
| } |
| |
| } // namespace |
| } // namespace tint::spirv::writer |