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 | |
Ben Clayton | acf7643 | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 17 | #include "src/ast/bool_literal.h" |
| 18 | #include "src/ast/float_literal.h" |
| 19 | #include "src/ast/null_literal.h" |
Ben Clayton | 10d5c6a | 2020-11-13 21:58:28 +0000 | [diff] [blame] | 20 | #include "src/ast/test_helper.h" |
dan sinclair | 113fb07 | 2020-03-27 00:45:34 +0000 | [diff] [blame] | 21 | #include "src/ast/type/i32_type.h" |
dan sinclair | 253ee1b | 2020-05-04 18:58:19 +0000 | [diff] [blame] | 22 | #include "src/ast/type/u32_type.h" |
Ben Clayton | acf7643 | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 23 | #include "src/ast/uint_literal.h" |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 24 | |
| 25 | namespace tint { |
| 26 | namespace ast { |
dan sinclair | 989cee6 | 2020-03-26 15:31:43 +0000 | [diff] [blame] | 27 | namespace { |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 28 | |
Ben Clayton | 10d5c6a | 2020-11-13 21:58:28 +0000 | [diff] [blame] | 29 | using SintLiteralTest = TestHelper; |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 30 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 31 | TEST_F(SintLiteralTest, Value) { |
Ben Clayton | f1b0e1e | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 32 | type::I32 i32; |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 33 | SintLiteral i{&i32, 47}; |
Ben Clayton | acf7643 | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 34 | ASSERT_TRUE(i.Is<SintLiteral>()); |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 35 | EXPECT_EQ(i.value(), 47); |
| 36 | } |
| 37 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 38 | TEST_F(SintLiteralTest, Is) { |
Ben Clayton | f1b0e1e | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 39 | type::I32 i32; |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 40 | SintLiteral i{&i32, 42}; |
Ben Clayton | acf7643 | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 41 | Literal* l = &i; |
| 42 | EXPECT_FALSE(l->Is<BoolLiteral>()); |
| 43 | EXPECT_TRUE(l->Is<SintLiteral>()); |
| 44 | EXPECT_FALSE(l->Is<FloatLiteral>()); |
| 45 | EXPECT_FALSE(l->Is<UintLiteral>()); |
| 46 | EXPECT_FALSE(l->Is<NullLiteral>()); |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 47 | } |
| 48 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 49 | TEST_F(SintLiteralTest, ToStr) { |
Ben Clayton | f1b0e1e | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 50 | type::I32 i32; |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 51 | SintLiteral i{&i32, -42}; |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 52 | |
| 53 | EXPECT_EQ(i.to_str(), "-42"); |
| 54 | } |
| 55 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 56 | TEST_F(SintLiteralTest, Name_I32) { |
Ben Clayton | f1b0e1e | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 57 | type::I32 i32; |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 58 | SintLiteral i{&i32, 2}; |
| 59 | EXPECT_EQ("__sint__i32_2", i.name()); |
dan sinclair | 253ee1b | 2020-05-04 18:58:19 +0000 | [diff] [blame] | 60 | } |
| 61 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 62 | TEST_F(SintLiteralTest, Name_U32) { |
Ben Clayton | f1b0e1e | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 63 | type::U32 u32; |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 64 | SintLiteral i{&u32, 2}; |
| 65 | EXPECT_EQ("__sint__u32_2", i.name()); |
dan sinclair | 253ee1b | 2020-05-04 18:58:19 +0000 | [diff] [blame] | 66 | } |
dan sinclair | e009c20 | 2020-06-02 20:11:54 +0000 | [diff] [blame] | 67 | |
dan sinclair | 989cee6 | 2020-03-26 15:31:43 +0000 | [diff] [blame] | 68 | } // namespace |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 69 | } // namespace ast |
| 70 | } // namespace tint |