• 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/call_statement.h"
16 #include "src/writer/hlsl/test_helper.h"
17 
18 namespace tint {
19 namespace writer {
20 namespace hlsl {
21 namespace {
22 
23 using HlslGeneratorImplTest_Call = TestHelper;
24 
TEST_F(HlslGeneratorImplTest_Call,EmitExpression_Call_WithoutParams)25 TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
26   Func("my_func", {}, ty.f32(), {Return(1.23f)});
27 
28   auto* call = Call("my_func");
29   WrapInFunction(call);
30 
31   GeneratorImpl& gen = Build();
32 
33   std::stringstream out;
34   ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
35   EXPECT_EQ(out.str(), "my_func()");
36 }
37 
TEST_F(HlslGeneratorImplTest_Call,EmitExpression_Call_WithParams)38 TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
39   Func("my_func",
40        {
41            Param(Sym(), ty.f32()),
42            Param(Sym(), ty.f32()),
43        },
44        ty.f32(), {Return(1.23f)});
45   Global("param1", ty.f32(), ast::StorageClass::kPrivate);
46   Global("param2", ty.f32(), ast::StorageClass::kPrivate);
47 
48   auto* call = Call("my_func", "param1", "param2");
49   WrapInFunction(call);
50 
51   GeneratorImpl& gen = Build();
52 
53   std::stringstream out;
54   ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
55   EXPECT_EQ(out.str(), "my_func(param1, param2)");
56 }
57 
TEST_F(HlslGeneratorImplTest_Call,EmitStatement_Call)58 TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
59   Func("my_func",
60        {
61            Param(Sym(), ty.f32()),
62            Param(Sym(), ty.f32()),
63        },
64        ty.void_(), ast::StatementList{}, ast::DecorationList{});
65   Global("param1", ty.f32(), ast::StorageClass::kPrivate);
66   Global("param2", ty.f32(), ast::StorageClass::kPrivate);
67 
68   auto* call = CallStmt(Call("my_func", "param1", "param2"));
69   WrapInFunction(call);
70 
71   GeneratorImpl& gen = Build();
72 
73   gen.increment_indent();
74   ASSERT_TRUE(gen.EmitStatement(call)) << gen.error();
75   EXPECT_EQ(gen.result(), "  my_func(param1, param2);\n");
76 }
77 
78 }  // namespace
79 }  // namespace hlsl
80 }  // namespace writer
81 }  // namespace tint
82