blob: d7a6bb2747ec0004fc07e4611fb4a5fe2c798310 [file] [log] [blame]
Dan Sinclair6e581892020-03-02 15:47:43 -05001// 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 Clayton10d5c6a2020-11-13 21:58:28 +000015#include "src/ast/test_helper.h"
Dan Sinclair6e581892020-03-02 15:47:43 -050016
17namespace tint {
18namespace ast {
dan sinclair989cee62020-03-26 15:31:43 +000019namespace {
Dan Sinclair6e581892020-03-02 15:47:43 -050020
Ben Clayton10d5c6a2020-11-13 21:58:28 +000021using SintLiteralTest = TestHelper;
Dan Sinclair6e581892020-03-02 15:47:43 -050022
dan sinclairc6f29472020-06-02 20:11:44 +000023TEST_F(SintLiteralTest, Value) {
Ben Clayton109b18f2021-04-28 13:50:43 +000024 auto* i = create<SintLiteral>(47);
Ben Clayton1523f5c2020-12-14 22:30:57 +000025 ASSERT_TRUE(i->Is<SintLiteral>());
26 EXPECT_EQ(i->value(), 47);
Dan Sinclair6e581892020-03-02 15:47:43 -050027}
28
dan sinclairc6f29472020-06-02 20:11:44 +000029TEST_F(SintLiteralTest, Is) {
Ben Clayton109b18f2021-04-28 13:50:43 +000030 ast::Literal* l = create<SintLiteral>(42);
Ben Claytonacf76432020-11-30 23:30:58 +000031 EXPECT_FALSE(l->Is<BoolLiteral>());
32 EXPECT_TRUE(l->Is<SintLiteral>());
33 EXPECT_FALSE(l->Is<FloatLiteral>());
34 EXPECT_FALSE(l->Is<UintLiteral>());
Dan Sinclair6e581892020-03-02 15:47:43 -050035}
36
dan sinclairc6f29472020-06-02 20:11:44 +000037TEST_F(SintLiteralTest, ToStr) {
Ben Clayton109b18f2021-04-28 13:50:43 +000038 auto* i = create<SintLiteral>(-42);
Ben Clayton708dc2d2021-01-29 11:22:40 +000039 EXPECT_EQ(str(i), "-42");
Dan Sinclair6e581892020-03-02 15:47:43 -050040}
41
dan sinclairc6f29472020-06-02 20:11:44 +000042TEST_F(SintLiteralTest, Name_I32) {
Ben Clayton109b18f2021-04-28 13:50:43 +000043 auto* i = create<SintLiteral>(2);
44 EXPECT_EQ("__sint_2", i->name());
dan sinclair253ee1b2020-05-04 18:58:19 +000045}
dan sinclaire009c202020-06-02 20:11:54 +000046
dan sinclair989cee62020-03-26 15:31:43 +000047} // namespace
Dan Sinclair6e581892020-03-02 15:47:43 -050048} // namespace ast
49} // namespace tint