1 // Copyright 2020 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "src/writer/spirv/operand.h"
16
17 #include "gtest/gtest.h"
18
19 namespace tint {
20 namespace writer {
21 namespace spirv {
22 namespace {
23
24 using OperandTest = testing::Test;
25
TEST_F(OperandTest,CreateFloat)26 TEST_F(OperandTest, CreateFloat) {
27 auto o = Operand::Float(1.2f);
28 EXPECT_TRUE(o.IsFloat());
29 EXPECT_FLOAT_EQ(o.to_f(), 1.2f);
30 }
31
TEST_F(OperandTest,CreateInt)32 TEST_F(OperandTest, CreateInt) {
33 auto o = Operand::Int(1);
34 EXPECT_TRUE(o.IsInt());
35 EXPECT_EQ(o.to_i(), 1u);
36 }
37
TEST_F(OperandTest,CreateString)38 TEST_F(OperandTest, CreateString) {
39 auto o = Operand::String("my string");
40 EXPECT_TRUE(o.IsString());
41 EXPECT_EQ(o.to_s(), "my string");
42 }
43
TEST_F(OperandTest,Length_Float)44 TEST_F(OperandTest, Length_Float) {
45 auto o = Operand::Float(1.2f);
46 EXPECT_EQ(o.length(), 1u);
47 }
48
TEST_F(OperandTest,Length_Int)49 TEST_F(OperandTest, Length_Int) {
50 auto o = Operand::Int(1);
51 EXPECT_EQ(o.length(), 1u);
52 }
53
TEST_F(OperandTest,Length_String)54 TEST_F(OperandTest, Length_String) {
55 auto o = Operand::String("my string");
56 EXPECT_EQ(o.length(), 3u);
57 }
58
TEST_F(OperandTest,Length_String_Empty)59 TEST_F(OperandTest, Length_String_Empty) {
60 auto o = Operand::String("");
61 EXPECT_EQ(o.length(), 1u);
62 }
63
64 } // namespace
65 } // namespace spirv
66 } // namespace writer
67 } // namespace tint
68