Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 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 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 15 | #include "src/ast/sint_literal.h" |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 16 | |
| 17 | #include "gtest/gtest.h" |
dan sinclair | 113fb07 | 2020-03-27 00:45:34 +0000 | [diff] [blame] | 18 | #include "src/ast/type/i32_type.h" |
dan sinclair | 253ee1b | 2020-05-04 18:58:19 +0000 | [diff] [blame] | 19 | #include "src/ast/type/u32_type.h" |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 20 | |
| 21 | namespace tint { |
| 22 | namespace ast { |
dan sinclair | 989cee6 | 2020-03-26 15:31:43 +0000 | [diff] [blame] | 23 | namespace { |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 24 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 25 | using SintLiteralTest = testing::Test; |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 26 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 27 | TEST_F(SintLiteralTest, Value) { |
dan sinclair | 113fb07 | 2020-03-27 00:45:34 +0000 | [diff] [blame] | 28 | ast::type::I32Type i32; |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 29 | SintLiteral i{&i32, 47}; |
| 30 | ASSERT_TRUE(i.IsSint()); |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 31 | EXPECT_EQ(i.value(), 47); |
| 32 | } |
| 33 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 34 | TEST_F(SintLiteralTest, Is) { |
dan sinclair | 113fb07 | 2020-03-27 00:45:34 +0000 | [diff] [blame] | 35 | ast::type::I32Type i32; |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 36 | SintLiteral i{&i32, 42}; |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 37 | EXPECT_FALSE(i.IsBool()); |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 38 | EXPECT_TRUE(i.IsSint()); |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 39 | EXPECT_FALSE(i.IsFloat()); |
| 40 | EXPECT_FALSE(i.IsUint()); |
dan sinclair | 2287f33 | 2020-05-05 14:21:19 +0000 | [diff] [blame] | 41 | EXPECT_FALSE(i.IsNull()); |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 42 | } |
| 43 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 44 | TEST_F(SintLiteralTest, ToStr) { |
dan sinclair | 113fb07 | 2020-03-27 00:45:34 +0000 | [diff] [blame] | 45 | ast::type::I32Type i32; |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 46 | SintLiteral i{&i32, -42}; |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 47 | |
| 48 | EXPECT_EQ(i.to_str(), "-42"); |
| 49 | } |
| 50 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 51 | TEST_F(SintLiteralTest, Name_I32) { |
dan sinclair | 253ee1b | 2020-05-04 18:58:19 +0000 | [diff] [blame] | 52 | ast::type::I32Type i32; |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 53 | SintLiteral i{&i32, 2}; |
| 54 | EXPECT_EQ("__sint__i32_2", i.name()); |
dan sinclair | 253ee1b | 2020-05-04 18:58:19 +0000 | [diff] [blame] | 55 | } |
| 56 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 57 | TEST_F(SintLiteralTest, Name_U32) { |
dan sinclair | 253ee1b | 2020-05-04 18:58:19 +0000 | [diff] [blame] | 58 | ast::type::U32Type u32; |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame^] | 59 | SintLiteral i{&u32, 2}; |
| 60 | EXPECT_EQ("__sint__u32_2", i.name()); |
dan sinclair | 253ee1b | 2020-05-04 18:58:19 +0000 | [diff] [blame] | 61 | } |
dan sinclair | 989cee6 | 2020-03-26 15:31:43 +0000 | [diff] [blame] | 62 | } // namespace |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 63 | } // namespace ast |
| 64 | } // namespace tint |