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/variable_decl_statement.h"
16 #include "src/writer/wgsl/test_helper.h"
17
18 namespace tint {
19 namespace writer {
20 namespace wgsl {
21 namespace {
22
23 using WgslGeneratorImplTest = TestHelper;
24
TEST_F(WgslGeneratorImplTest,Emit_VariableDeclStatement)25 TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement) {
26 auto* var = Var("a", ty.f32());
27
28 auto* stmt = Decl(var);
29 WrapInFunction(stmt);
30
31 GeneratorImpl& gen = Build();
32
33 gen.increment_indent();
34
35 ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
36 EXPECT_EQ(gen.result(), " var a : f32;\n");
37 }
38
TEST_F(WgslGeneratorImplTest,Emit_VariableDeclStatement_InferredType)39 TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_InferredType) {
40 auto* var = Var("a", nullptr, ast::StorageClass::kNone, Expr(123));
41
42 auto* stmt = Decl(var);
43 WrapInFunction(stmt);
44
45 GeneratorImpl& gen = Build();
46
47 gen.increment_indent();
48
49 ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
50 EXPECT_EQ(gen.result(), " var a = 123;\n");
51 }
52
53 } // namespace
54 } // namespace wgsl
55 } // namespace writer
56 } // namespace tint
57