• 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/return_statement.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 ReturnStatementTest = TestHelper;
25 
TEST_F(ReturnStatementTest,Creation)26 TEST_F(ReturnStatementTest, Creation) {
27   auto* expr = Expr("expr");
28 
29   auto* r = create<ReturnStatement>(expr);
30   EXPECT_EQ(r->value, expr);
31 }
32 
TEST_F(ReturnStatementTest,Creation_WithSource)33 TEST_F(ReturnStatementTest, Creation_WithSource) {
34   auto* r = create<ReturnStatement>(Source{Source::Location{20, 2}});
35   auto src = r->source;
36   EXPECT_EQ(src.range.begin.line, 20u);
37   EXPECT_EQ(src.range.begin.column, 2u);
38 }
39 
TEST_F(ReturnStatementTest,IsReturn)40 TEST_F(ReturnStatementTest, IsReturn) {
41   auto* r = create<ReturnStatement>();
42   EXPECT_TRUE(r->Is<ReturnStatement>());
43 }
44 
TEST_F(ReturnStatementTest,WithoutValue)45 TEST_F(ReturnStatementTest, WithoutValue) {
46   auto* r = create<ReturnStatement>();
47   EXPECT_EQ(r->value, nullptr);
48 }
49 
TEST_F(ReturnStatementTest,WithValue)50 TEST_F(ReturnStatementTest, WithValue) {
51   auto* expr = Expr("expr");
52   auto* r = create<ReturnStatement>(expr);
53   EXPECT_NE(r->value, nullptr);
54 }
55 
TEST_F(ReturnStatementTest,Assert_DifferentProgramID_Expr)56 TEST_F(ReturnStatementTest, Assert_DifferentProgramID_Expr) {
57   EXPECT_FATAL_FAILURE(
58       {
59         ProgramBuilder b1;
60         ProgramBuilder b2;
61         b1.create<ReturnStatement>(b2.Expr(true));
62       },
63       "internal compiler error");
64 }
65 
66 }  // namespace
67 }  // namespace ast
68 }  // namespace tint
69