dan sinclair | 2287f33 | 2020-05-05 14:21:19 +0000 | [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 | |
| 15 | #include "src/ast/null_literal.h" |
| 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/sint_literal.h" |
Ben Clayton | 10d5c6a | 2020-11-13 21:58:28 +0000 | [diff] [blame] | 20 | #include "src/ast/test_helper.h" |
Ben Clayton | acf7643 | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 21 | #include "src/ast/uint_literal.h" |
Ben Clayton | 207b5e2 | 2021-01-21 15:42:10 +0000 | [diff] [blame] | 22 | #include "src/type/i32_type.h" |
dan sinclair | 2287f33 | 2020-05-05 14:21:19 +0000 | [diff] [blame] | 23 | |
| 24 | namespace tint { |
| 25 | namespace ast { |
| 26 | namespace { |
| 27 | |
Ben Clayton | 10d5c6a | 2020-11-13 21:58:28 +0000 | [diff] [blame] | 28 | using NullLiteralTest = TestHelper; |
dan sinclair | 2287f33 | 2020-05-05 14:21:19 +0000 | [diff] [blame] | 29 | |
| 30 | TEST_F(NullLiteralTest, Is) { |
Ben Clayton | 8d391f7 | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 31 | ast::Literal* l = create<NullLiteral>(ty.i32()); |
Ben Clayton | acf7643 | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 32 | EXPECT_FALSE(l->Is<BoolLiteral>()); |
| 33 | EXPECT_FALSE(l->Is<SintLiteral>()); |
| 34 | EXPECT_FALSE(l->Is<FloatLiteral>()); |
| 35 | EXPECT_FALSE(l->Is<UintLiteral>()); |
| 36 | EXPECT_FALSE(l->Is<IntLiteral>()); |
| 37 | EXPECT_TRUE(l->Is<NullLiteral>()); |
dan sinclair | 2287f33 | 2020-05-05 14:21:19 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | TEST_F(NullLiteralTest, ToStr) { |
Ben Clayton | 8d391f7 | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 41 | auto* i = create<NullLiteral>(ty.i32()); |
dan sinclair | 2287f33 | 2020-05-05 14:21:19 +0000 | [diff] [blame] | 42 | |
Ben Clayton | 1523f5c | 2020-12-14 22:30:57 +0000 | [diff] [blame] | 43 | EXPECT_EQ(i->to_str(), "null __i32"); |
dan sinclair | 2287f33 | 2020-05-05 14:21:19 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | TEST_F(NullLiteralTest, Name_I32) { |
Ben Clayton | 8d391f7 | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 47 | auto* i = create<NullLiteral>(ty.i32()); |
Ben Clayton | 1523f5c | 2020-12-14 22:30:57 +0000 | [diff] [blame] | 48 | EXPECT_EQ("__null__i32", i->name()); |
dan sinclair | 2287f33 | 2020-05-05 14:21:19 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } // namespace |
| 52 | } // namespace ast |
dan sinclair | c6f2947 | 2020-06-02 20:11:44 +0000 | [diff] [blame] | 53 | } // namespace tint |