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