blob: ad4ccb9dbd90c51c426a622f557011369b7f348e [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
17#include "gtest/gtest.h"
dan sinclair113fb072020-03-27 00:45:34 +000018#include "src/ast/type/i32_type.h"
dan sinclair253ee1b2020-05-04 18:58:19 +000019#include "src/ast/type/u32_type.h"
Dan Sinclair6e581892020-03-02 15:47:43 -050020
21namespace tint {
22namespace ast {
dan sinclair989cee62020-03-26 15:31:43 +000023namespace {
Dan Sinclair6e581892020-03-02 15:47:43 -050024
dan sinclairc6f29472020-06-02 20:11:44 +000025using SintLiteralTest = testing::Test;
Dan Sinclair6e581892020-03-02 15:47:43 -050026
dan sinclairc6f29472020-06-02 20:11:44 +000027TEST_F(SintLiteralTest, Value) {
dan sinclair113fb072020-03-27 00:45:34 +000028 ast::type::I32Type i32;
dan sinclairc6f29472020-06-02 20:11:44 +000029 SintLiteral i{&i32, 47};
30 ASSERT_TRUE(i.IsSint());
Dan Sinclair6e581892020-03-02 15:47:43 -050031 EXPECT_EQ(i.value(), 47);
32}
33
dan sinclairc6f29472020-06-02 20:11:44 +000034TEST_F(SintLiteralTest, Is) {
dan sinclair113fb072020-03-27 00:45:34 +000035 ast::type::I32Type i32;
dan sinclairc6f29472020-06-02 20:11:44 +000036 SintLiteral i{&i32, 42};
Dan Sinclair6e581892020-03-02 15:47:43 -050037 EXPECT_FALSE(i.IsBool());
dan sinclairc6f29472020-06-02 20:11:44 +000038 EXPECT_TRUE(i.IsSint());
Dan Sinclair6e581892020-03-02 15:47:43 -050039 EXPECT_FALSE(i.IsFloat());
40 EXPECT_FALSE(i.IsUint());
dan sinclair2287f332020-05-05 14:21:19 +000041 EXPECT_FALSE(i.IsNull());
Dan Sinclair6e581892020-03-02 15:47:43 -050042}
43
dan sinclairc6f29472020-06-02 20:11:44 +000044TEST_F(SintLiteralTest, ToStr) {
dan sinclair113fb072020-03-27 00:45:34 +000045 ast::type::I32Type i32;
dan sinclairc6f29472020-06-02 20:11:44 +000046 SintLiteral i{&i32, -42};
Dan Sinclair6e581892020-03-02 15:47:43 -050047
48 EXPECT_EQ(i.to_str(), "-42");
49}
50
dan sinclairc6f29472020-06-02 20:11:44 +000051TEST_F(SintLiteralTest, Name_I32) {
dan sinclair253ee1b2020-05-04 18:58:19 +000052 ast::type::I32Type i32;
dan sinclairc6f29472020-06-02 20:11:44 +000053 SintLiteral i{&i32, 2};
54 EXPECT_EQ("__sint__i32_2", i.name());
dan sinclair253ee1b2020-05-04 18:58:19 +000055}
56
dan sinclairc6f29472020-06-02 20:11:44 +000057TEST_F(SintLiteralTest, Name_U32) {
dan sinclair253ee1b2020-05-04 18:58:19 +000058 ast::type::U32Type u32;
dan sinclairc6f29472020-06-02 20:11:44 +000059 SintLiteral i{&u32, 2};
60 EXPECT_EQ("__sint__u32_2", i.name());
dan sinclair253ee1b2020-05-04 18:58:19 +000061}
dan sinclair989cee62020-03-26 15:31:43 +000062} // namespace
Dan Sinclair6e581892020-03-02 15:47:43 -050063} // namespace ast
64} // namespace tint