1 // 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
15 #include "gtest/gtest-spi.h"
16 #include "src/ast/test_helper.h"
17
18 namespace tint {
19 namespace ast {
20 namespace {
21
22 using IdentifierExpressionTest = TestHelper;
23
TEST_F(IdentifierExpressionTest,Creation)24 TEST_F(IdentifierExpressionTest, Creation) {
25 auto* i = Expr("ident");
26 EXPECT_EQ(i->symbol, Symbol(1, ID()));
27 }
28
TEST_F(IdentifierExpressionTest,Creation_WithSource)29 TEST_F(IdentifierExpressionTest, Creation_WithSource) {
30 auto* i = Expr(Source{Source::Location{20, 2}}, "ident");
31 EXPECT_EQ(i->symbol, Symbol(1, ID()));
32
33 auto src = i->source;
34 EXPECT_EQ(src.range.begin.line, 20u);
35 EXPECT_EQ(src.range.begin.column, 2u);
36 }
37
TEST_F(IdentifierExpressionTest,IsIdentifier)38 TEST_F(IdentifierExpressionTest, IsIdentifier) {
39 auto* i = Expr("ident");
40 EXPECT_TRUE(i->Is<IdentifierExpression>());
41 }
42
TEST_F(IdentifierExpressionTest,Assert_InvalidSymbol)43 TEST_F(IdentifierExpressionTest, Assert_InvalidSymbol) {
44 EXPECT_FATAL_FAILURE(
45 {
46 ProgramBuilder b;
47 b.Expr("");
48 },
49 "internal compiler error");
50 }
51
TEST_F(IdentifierExpressionTest,Assert_DifferentProgramID_Symbol)52 TEST_F(IdentifierExpressionTest, Assert_DifferentProgramID_Symbol) {
53 EXPECT_FATAL_FAILURE(
54 {
55 ProgramBuilder b1;
56 ProgramBuilder b2;
57 b1.Expr(b2.Sym("b2"));
58 },
59 "internal compiler error");
60 }
61
62 } // namespace
63 } // namespace ast
64 } // namespace tint
65