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 | |
Ben Clayton | 10d5c6a | 2020-11-13 21:58:28 +0000 | [diff] [blame] | 15 | #include "src/ast/test_helper.h" |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 16 | |
| 17 | namespace tint { |
| 18 | namespace ast { |
dan sinclair | 989cee6 | 2020-03-26 15:31:43 +0000 | [diff] [blame] | 19 | namespace { |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 20 | |
Ben Clayton | 10d5c6a | 2020-11-13 21:58:28 +0000 | [diff] [blame] | 21 | using SintLiteralTest = TestHelper; |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 22 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 23 | TEST_F(SintLiteralTest, Value) { |
Ben Clayton | 109b18f | 2021-04-28 13:50:43 +0000 | [diff] [blame^] | 24 | auto* i = create<SintLiteral>(47); |
Ben Clayton | 1523f5c | 2020-12-14 22:30:57 +0000 | [diff] [blame] | 25 | ASSERT_TRUE(i->Is<SintLiteral>()); |
| 26 | EXPECT_EQ(i->value(), 47); |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 27 | } |
| 28 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 29 | TEST_F(SintLiteralTest, Is) { |
Ben Clayton | 109b18f | 2021-04-28 13:50:43 +0000 | [diff] [blame^] | 30 | ast::Literal* l = create<SintLiteral>(42); |
Ben Clayton | acf7643 | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 31 | EXPECT_FALSE(l->Is<BoolLiteral>()); |
| 32 | EXPECT_TRUE(l->Is<SintLiteral>()); |
| 33 | EXPECT_FALSE(l->Is<FloatLiteral>()); |
| 34 | EXPECT_FALSE(l->Is<UintLiteral>()); |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 35 | } |
| 36 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 37 | TEST_F(SintLiteralTest, ToStr) { |
Ben Clayton | 109b18f | 2021-04-28 13:50:43 +0000 | [diff] [blame^] | 38 | auto* i = create<SintLiteral>(-42); |
Ben Clayton | 708dc2d | 2021-01-29 11:22:40 +0000 | [diff] [blame] | 39 | EXPECT_EQ(str(i), "-42"); |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 40 | } |
| 41 | |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 42 | TEST_F(SintLiteralTest, Name_I32) { |
Ben Clayton | 109b18f | 2021-04-28 13:50:43 +0000 | [diff] [blame^] | 43 | auto* i = create<SintLiteral>(2); |
| 44 | EXPECT_EQ("__sint_2", i->name()); |
dan sinclair | 253ee1b | 2020-05-04 18:58:19 +0000 | [diff] [blame] | 45 | } |
dan sinclair | e009c20 | 2020-06-02 20:11:54 +0000 | [diff] [blame] | 46 | |
dan sinclair | 989cee6 | 2020-03-26 15:31:43 +0000 | [diff] [blame] | 47 | } // namespace |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 48 | } // namespace ast |
| 49 | } // namespace tint |