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/bitcast_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 BitcastExpressionTest = TestHelper;
25
TEST_F(BitcastExpressionTest,Create)26 TEST_F(BitcastExpressionTest, Create) {
27 auto* expr = Expr("expr");
28
29 auto* exp = create<BitcastExpression>(ty.f32(), expr);
30 EXPECT_TRUE(exp->type->Is<ast::F32>());
31 ASSERT_EQ(exp->expr, expr);
32 }
33
TEST_F(BitcastExpressionTest,CreateWithSource)34 TEST_F(BitcastExpressionTest, CreateWithSource) {
35 auto* expr = Expr("expr");
36
37 auto* exp = create<BitcastExpression>(Source{Source::Location{20, 2}},
38 ty.f32(), expr);
39 auto src = exp->source;
40 EXPECT_EQ(src.range.begin.line, 20u);
41 EXPECT_EQ(src.range.begin.column, 2u);
42 }
43
TEST_F(BitcastExpressionTest,IsBitcast)44 TEST_F(BitcastExpressionTest, IsBitcast) {
45 auto* expr = Expr("expr");
46
47 auto* exp = create<BitcastExpression>(ty.f32(), expr);
48 EXPECT_TRUE(exp->Is<BitcastExpression>());
49 }
50
TEST_F(BitcastExpressionTest,Assert_Null_Type)51 TEST_F(BitcastExpressionTest, Assert_Null_Type) {
52 EXPECT_FATAL_FAILURE(
53 {
54 ProgramBuilder b;
55 b.create<BitcastExpression>(nullptr, b.Expr("idx"));
56 },
57 "internal compiler error");
58 }
59
TEST_F(BitcastExpressionTest,Assert_Null_Expr)60 TEST_F(BitcastExpressionTest, Assert_Null_Expr) {
61 EXPECT_FATAL_FAILURE(
62 {
63 ProgramBuilder b;
64 b.create<BitcastExpression>(b.ty.f32(), nullptr);
65 },
66 "internal compiler error");
67 }
68
TEST_F(BitcastExpressionTest,Assert_DifferentProgramID_Expr)69 TEST_F(BitcastExpressionTest, Assert_DifferentProgramID_Expr) {
70 EXPECT_FATAL_FAILURE(
71 {
72 ProgramBuilder b1;
73 ProgramBuilder b2;
74 b1.create<BitcastExpression>(b1.ty.f32(), b2.Expr("idx"));
75 },
76 "internal compiler error");
77 }
78
79 } // namespace
80 } // namespace ast
81 } // namespace tint
82