blob: e1ec8dd6256053ed5f39e7dc9c399a94aa95c020 [file] [log] [blame]
Ryan Harrisondbc13af2022-02-21 15:19:07 +00001// 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/tint/ast/unary_op_expression.h"
16
17#include "gtest/gtest-spi.h"
18#include "src/tint/ast/test_helper.h"
19
dan sinclair34323ac2022-04-07 18:39:35 +000020namespace tint::ast {
Ryan Harrisondbc13af2022-02-21 15:19:07 +000021namespace {
22
23using UnaryOpExpressionTest = TestHelper;
24
25TEST_F(UnaryOpExpressionTest, Creation) {
dan sinclair41e4d9a2022-05-01 14:40:55 +000026 auto* ident = Expr("ident");
Ryan Harrisondbc13af2022-02-21 15:19:07 +000027
dan sinclair41e4d9a2022-05-01 14:40:55 +000028 auto* u = create<UnaryOpExpression>(UnaryOp::kNot, ident);
29 EXPECT_EQ(u->op, UnaryOp::kNot);
30 EXPECT_EQ(u->expr, ident);
Ryan Harrisondbc13af2022-02-21 15:19:07 +000031}
32
33TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
dan sinclair41e4d9a2022-05-01 14:40:55 +000034 auto* ident = Expr("ident");
35 auto* u = create<UnaryOpExpression>(Source{Source::Location{20, 2}}, UnaryOp::kNot, ident);
36 auto src = u->source;
37 EXPECT_EQ(src.range.begin.line, 20u);
38 EXPECT_EQ(src.range.begin.column, 2u);
Ryan Harrisondbc13af2022-02-21 15:19:07 +000039}
40
41TEST_F(UnaryOpExpressionTest, IsUnaryOp) {
dan sinclair41e4d9a2022-05-01 14:40:55 +000042 auto* ident = Expr("ident");
43 auto* u = create<UnaryOpExpression>(UnaryOp::kNot, ident);
44 EXPECT_TRUE(u->Is<UnaryOpExpression>());
Ryan Harrisondbc13af2022-02-21 15:19:07 +000045}
46
47TEST_F(UnaryOpExpressionTest, Assert_Null_Expression) {
dan sinclair41e4d9a2022-05-01 14:40:55 +000048 EXPECT_FATAL_FAILURE(
49 {
50 ProgramBuilder b;
51 b.create<UnaryOpExpression>(UnaryOp::kNot, nullptr);
52 },
53 "internal compiler error");
Ryan Harrisondbc13af2022-02-21 15:19:07 +000054}
55
56TEST_F(UnaryOpExpressionTest, Assert_DifferentProgramID_Expression) {
dan sinclair41e4d9a2022-05-01 14:40:55 +000057 EXPECT_FATAL_FAILURE(
58 {
59 ProgramBuilder b1;
60 ProgramBuilder b2;
61 b1.create<UnaryOpExpression>(UnaryOp::kNot, b2.Expr(true));
62 },
63 "internal compiler error");
Ryan Harrisondbc13af2022-02-21 15:19:07 +000064}
65
66} // namespace
dan sinclair34323ac2022-04-07 18:39:35 +000067} // namespace tint::ast