mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-14 09:06:11 +00:00
Rename: • kFloatFLiteral -> kFloatLiteral_F • kIntILiteral -> kIntLiteral_I • kIntULiteral -> kIntLiteral_U As suggested in review: https://dawn-review.googlesource.com/c/dawn/+/89031/comments/b37253a3_e830b482 Bug: tint:1504 Change-Id: I4120f2904d8614152d4c804c226c9710f2ef8653 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/89661 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
97 lines
3.4 KiB
C++
97 lines
3.4 KiB
C++
// Copyright 2020 The Tint Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "src/tint/reader/wgsl/token.h"
|
|
|
|
#include <limits>
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
namespace tint::reader::wgsl {
|
|
namespace {
|
|
|
|
using ::testing::EndsWith;
|
|
using ::testing::Not;
|
|
using ::testing::StartsWith;
|
|
|
|
using TokenTest = testing::Test;
|
|
|
|
TEST_F(TokenTest, ReturnsF64) {
|
|
Token t1(Token::Type::kFloatLiteral_F, Source{}, -2.345);
|
|
EXPECT_EQ(t1.to_f64(), -2.345);
|
|
|
|
Token t2(Token::Type::kFloatLiteral_F, Source{}, 2.345);
|
|
EXPECT_EQ(t2.to_f64(), 2.345);
|
|
}
|
|
|
|
TEST_F(TokenTest, ReturnsI32) {
|
|
Token t1(Token::Type::kIntLiteral_I, Source{}, static_cast<int64_t>(-2345));
|
|
EXPECT_EQ(t1.to_i64(), -2345);
|
|
|
|
Token t2(Token::Type::kIntLiteral_I, Source{}, static_cast<int64_t>(2345));
|
|
EXPECT_EQ(t2.to_i64(), 2345);
|
|
}
|
|
|
|
TEST_F(TokenTest, HandlesMaxI32) {
|
|
Token t1(Token::Type::kIntLiteral_I, Source{},
|
|
static_cast<int64_t>(std::numeric_limits<int32_t>::max()));
|
|
EXPECT_EQ(t1.to_i64(), std::numeric_limits<int32_t>::max());
|
|
}
|
|
|
|
TEST_F(TokenTest, HandlesMinI32) {
|
|
Token t1(Token::Type::kIntLiteral_I, Source{},
|
|
static_cast<int64_t>(std::numeric_limits<int32_t>::min()));
|
|
EXPECT_EQ(t1.to_i64(), std::numeric_limits<int32_t>::min());
|
|
}
|
|
|
|
TEST_F(TokenTest, ReturnsU32) {
|
|
Token t2(Token::Type::kIntLiteral_U, Source{}, static_cast<int64_t>(2345u));
|
|
EXPECT_EQ(t2.to_i64(), 2345u);
|
|
}
|
|
|
|
TEST_F(TokenTest, ReturnsMaxU32) {
|
|
Token t1(Token::Type::kIntLiteral_U, Source{},
|
|
static_cast<int64_t>(std::numeric_limits<uint32_t>::max()));
|
|
EXPECT_EQ(t1.to_i64(), std::numeric_limits<uint32_t>::max());
|
|
}
|
|
|
|
TEST_F(TokenTest, Source) {
|
|
Source src;
|
|
src.range.begin = Source::Location{3, 9};
|
|
src.range.end = Source::Location{4, 3};
|
|
|
|
Token t(Token::Type::kIntLiteral, src);
|
|
EXPECT_EQ(t.source().range.begin.line, 3u);
|
|
EXPECT_EQ(t.source().range.begin.column, 9u);
|
|
EXPECT_EQ(t.source().range.end.line, 4u);
|
|
EXPECT_EQ(t.source().range.end.column, 3u);
|
|
}
|
|
|
|
TEST_F(TokenTest, ToStr) {
|
|
double d = 123.0;
|
|
int64_t i = 123;
|
|
EXPECT_THAT(Token(Token::Type::kFloatLiteral, Source{}, d).to_str(), StartsWith("123"));
|
|
EXPECT_THAT(Token(Token::Type::kFloatLiteral, Source{}, d).to_str(), Not(EndsWith("f")));
|
|
EXPECT_THAT(Token(Token::Type::kFloatLiteral_F, Source{}, d).to_str(), StartsWith("123"));
|
|
EXPECT_THAT(Token(Token::Type::kFloatLiteral_F, Source{}, d).to_str(), EndsWith("f"));
|
|
EXPECT_EQ(Token(Token::Type::kIntLiteral, Source{}, i).to_str(), "123");
|
|
EXPECT_EQ(Token(Token::Type::kIntLiteral_I, Source{}, i).to_str(), "123i");
|
|
EXPECT_EQ(Token(Token::Type::kIntLiteral_U, Source{}, i).to_str(), "123u");
|
|
EXPECT_EQ(Token(Token::Type::kIdentifier, Source{}, "blah").to_str(), "blah");
|
|
EXPECT_EQ(Token(Token::Type::kError, Source{}, "blah").to_str(), "blah");
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace tint::reader::wgsl
|