blob: e50bd42f56a01f8e41559c42e3c5d97618df9740 [file] [log] [blame]
dan sinclair2287f332020-05-05 14:21:19 +00001// 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 Claytonacf76432020-11-30 23:30:58 +000017#include "src/ast/bool_literal.h"
18#include "src/ast/float_literal.h"
19#include "src/ast/sint_literal.h"
Ben Clayton10d5c6a2020-11-13 21:58:28 +000020#include "src/ast/test_helper.h"
Ben Claytonacf76432020-11-30 23:30:58 +000021#include "src/ast/uint_literal.h"
Ben Clayton207b5e22021-01-21 15:42:10 +000022#include "src/type/i32_type.h"
dan sinclair2287f332020-05-05 14:21:19 +000023
24namespace tint {
25namespace ast {
26namespace {
27
Ben Clayton10d5c6a2020-11-13 21:58:28 +000028using NullLiteralTest = TestHelper;
dan sinclair2287f332020-05-05 14:21:19 +000029
30TEST_F(NullLiteralTest, Is) {
Ben Clayton8d391f72021-01-26 16:57:10 +000031 ast::Literal* l = create<NullLiteral>(ty.i32());
Ben Claytonacf76432020-11-30 23:30:58 +000032 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 sinclair2287f332020-05-05 14:21:19 +000038}
39
40TEST_F(NullLiteralTest, ToStr) {
Ben Clayton8d391f72021-01-26 16:57:10 +000041 auto* i = create<NullLiteral>(ty.i32());
dan sinclair2287f332020-05-05 14:21:19 +000042
Ben Clayton1523f5c2020-12-14 22:30:57 +000043 EXPECT_EQ(i->to_str(), "null __i32");
dan sinclair2287f332020-05-05 14:21:19 +000044}
45
46TEST_F(NullLiteralTest, Name_I32) {
Ben Clayton8d391f72021-01-26 16:57:10 +000047 auto* i = create<NullLiteral>(ty.i32());
Ben Clayton1523f5c2020-12-14 22:30:57 +000048 EXPECT_EQ("__null__i32", i->name());
dan sinclair2287f332020-05-05 14:21:19 +000049}
50
51} // namespace
52} // namespace ast
dan sinclairc6f29472020-06-02 20:11:44 +000053} // namespace tint