• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/ast/unary_op_expression.h"
16 
17 #include "gtest/gtest-spi.h"
18 #include "src/ast/test_helper.h"
19 
20 namespace tint {
21 namespace ast {
22 namespace {
23 
24 using UnaryOpExpressionTest = TestHelper;
25 
TEST_F(UnaryOpExpressionTest,Creation)26 TEST_F(UnaryOpExpressionTest, Creation) {
27   auto* ident = Expr("ident");
28 
29   auto* u = create<UnaryOpExpression>(UnaryOp::kNot, ident);
30   EXPECT_EQ(u->op, UnaryOp::kNot);
31   EXPECT_EQ(u->expr, ident);
32 }
33 
TEST_F(UnaryOpExpressionTest,Creation_WithSource)34 TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
35   auto* ident = Expr("ident");
36   auto* u = create<UnaryOpExpression>(Source{Source::Location{20, 2}},
37                                       UnaryOp::kNot, ident);
38   auto src = u->source;
39   EXPECT_EQ(src.range.begin.line, 20u);
40   EXPECT_EQ(src.range.begin.column, 2u);
41 }
42 
TEST_F(UnaryOpExpressionTest,IsUnaryOp)43 TEST_F(UnaryOpExpressionTest, IsUnaryOp) {
44   auto* ident = Expr("ident");
45   auto* u = create<UnaryOpExpression>(UnaryOp::kNot, ident);
46   EXPECT_TRUE(u->Is<UnaryOpExpression>());
47 }
48 
TEST_F(UnaryOpExpressionTest,Assert_Null_Expression)49 TEST_F(UnaryOpExpressionTest, Assert_Null_Expression) {
50   EXPECT_FATAL_FAILURE(
51       {
52         ProgramBuilder b;
53         b.create<UnaryOpExpression>(UnaryOp::kNot, nullptr);
54       },
55       "internal compiler error");
56 }
57 
TEST_F(UnaryOpExpressionTest,Assert_DifferentProgramID_Expression)58 TEST_F(UnaryOpExpressionTest, Assert_DifferentProgramID_Expression) {
59   EXPECT_FATAL_FAILURE(
60       {
61         ProgramBuilder b1;
62         ProgramBuilder b2;
63         b1.create<UnaryOpExpression>(UnaryOp::kNot, b2.Expr(true));
64       },
65       "internal compiler error");
66 }
67 
68 }  // namespace
69 }  // namespace ast
70 }  // namespace tint
71