blob: a37f6c2c171446ecf138a3eb5c5a9d9f4f9c2da0 [file] [log] [blame]
// 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 "gtest/gtest-spi.h"
#include "src/tint/lang/wgsl/ast/test_helper.h"
namespace tint::ast {
namespace {
using namespace tint::number_suffixes; // NOLINT
using IdentifierExpressionTest = TestHelper;
TEST_F(IdentifierExpressionTest, Creation) {
auto* i = Expr("ident");
EXPECT_EQ(i->identifier->symbol, Symbol(1, ID(), "ident"));
}
TEST_F(IdentifierExpressionTest, CreationTemplated) {
auto* i = Expr(Ident("ident", true));
EXPECT_EQ(i->identifier->symbol, Symbol(1, ID(), "ident"));
auto* tmpl_ident = i->identifier->As<TemplatedIdentifier>();
ASSERT_NE(tmpl_ident, nullptr);
EXPECT_EQ(tmpl_ident->arguments.Length(), 1_u);
EXPECT_TRUE(tmpl_ident->arguments[0]->Is<BoolLiteralExpression>());
}
TEST_F(IdentifierExpressionTest, Creation_WithSource) {
auto* i = Expr(Source{{20, 2}}, "ident");
EXPECT_EQ(i->identifier->symbol, Symbol(1, ID(), "ident"));
EXPECT_EQ(i->source.range, (Source::Range{{20, 2}}));
EXPECT_EQ(i->identifier->source.range, (Source::Range{{20, 2}}));
}
TEST_F(IdentifierExpressionTest, Assert_InvalidSymbol) {
EXPECT_FATAL_FAILURE(
{
ProgramBuilder b;
b.Expr("");
},
"internal compiler error");
}
TEST_F(IdentifierExpressionTest, Assert_DifferentGenerationID_Symbol) {
EXPECT_FATAL_FAILURE(
{
ProgramBuilder b1;
ProgramBuilder b2;
b1.Expr(b2.Sym("b2"));
},
"internal compiler error");
}
} // namespace
} // namespace tint::ast