blob: 09b4a34b2bc27cc3c2f57d87488717b17420eea3 [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
dan sinclairc6f29472020-06-02 20:11:44 +000015#include "src/ast/sint_literal.h"
Dan Sinclair6e581892020-03-02 15:47:43 -050016
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/null_literal.h"
Ben Clayton10d5c6a2020-11-13 21:58:28 +000020#include "src/ast/test_helper.h"
dan sinclair113fb072020-03-27 00:45:34 +000021#include "src/ast/type/i32_type.h"
dan sinclair253ee1b2020-05-04 18:58:19 +000022#include "src/ast/type/u32_type.h"
Ben Claytonacf76432020-11-30 23:30:58 +000023#include "src/ast/uint_literal.h"
Dan Sinclair6e581892020-03-02 15:47:43 -050024
25namespace tint {
26namespace ast {
dan sinclair989cee62020-03-26 15:31:43 +000027namespace {
Dan Sinclair6e581892020-03-02 15:47:43 -050028
Ben Clayton10d5c6a2020-11-13 21:58:28 +000029using SintLiteralTest = TestHelper;
Dan Sinclair6e581892020-03-02 15:47:43 -050030
dan sinclairc6f29472020-06-02 20:11:44 +000031TEST_F(SintLiteralTest, Value) {
Ben Claytonf1b0e1e2020-11-30 23:30:58 +000032 type::I32 i32;
dan sinclairc6f29472020-06-02 20:11:44 +000033 SintLiteral i{&i32, 47};
Ben Claytonacf76432020-11-30 23:30:58 +000034 ASSERT_TRUE(i.Is<SintLiteral>());
Dan Sinclair6e581892020-03-02 15:47:43 -050035 EXPECT_EQ(i.value(), 47);
36}
37
dan sinclairc6f29472020-06-02 20:11:44 +000038TEST_F(SintLiteralTest, Is) {
Ben Claytonf1b0e1e2020-11-30 23:30:58 +000039 type::I32 i32;
dan sinclairc6f29472020-06-02 20:11:44 +000040 SintLiteral i{&i32, 42};
Ben Claytonacf76432020-11-30 23:30:58 +000041 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 Sinclair6e581892020-03-02 15:47:43 -050047}
48
dan sinclairc6f29472020-06-02 20:11:44 +000049TEST_F(SintLiteralTest, ToStr) {
Ben Claytonf1b0e1e2020-11-30 23:30:58 +000050 type::I32 i32;
dan sinclairc6f29472020-06-02 20:11:44 +000051 SintLiteral i{&i32, -42};
Dan Sinclair6e581892020-03-02 15:47:43 -050052
53 EXPECT_EQ(i.to_str(), "-42");
54}
55
dan sinclairc6f29472020-06-02 20:11:44 +000056TEST_F(SintLiteralTest, Name_I32) {
Ben Claytonf1b0e1e2020-11-30 23:30:58 +000057 type::I32 i32;
dan sinclairc6f29472020-06-02 20:11:44 +000058 SintLiteral i{&i32, 2};
59 EXPECT_EQ("__sint__i32_2", i.name());
dan sinclair253ee1b2020-05-04 18:58:19 +000060}
61
dan sinclairc6f29472020-06-02 20:11:44 +000062TEST_F(SintLiteralTest, Name_U32) {
Ben Claytonf1b0e1e2020-11-30 23:30:58 +000063 type::U32 u32;
dan sinclairc6f29472020-06-02 20:11:44 +000064 SintLiteral i{&u32, 2};
65 EXPECT_EQ("__sint__u32_2", i.name());
dan sinclair253ee1b2020-05-04 18:58:19 +000066}
dan sinclaire009c202020-06-02 20:11:54 +000067
dan sinclair989cee62020-03-26 15:31:43 +000068} // namespace
Dan Sinclair6e581892020-03-02 15:47:43 -050069} // namespace ast
70} // namespace tint