blob: 828a9e228dd4769cdf5ffc3efded863d410b0a3b [file] [log] [blame]
Ben Claytone43c8302021-01-29 11:59:32 +00001// Copyright 2021 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/program_builder.h"
16
17#include "gtest/gtest.h"
18
19namespace tint {
20namespace {
21
22using ProgramBuilderTest = testing::Test;
23
24TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) {
25 Program inner([] {
26 ProgramBuilder builder;
27 auto* ty = builder.ty.f32();
Ben Clayton42d1e092021-02-02 14:29:15 +000028 builder.Func("a", {}, ty, {}, {});
Ben Claytone43c8302021-01-29 11:59:32 +000029 return builder;
30 }());
31
32 ASSERT_EQ(inner.AST().Functions().size(), 1u);
33 ASSERT_TRUE(inner.Symbols().Get("a").IsValid());
34 ASSERT_FALSE(inner.Symbols().Get("b").IsValid());
35
36 ProgramBuilder outer = ProgramBuilder::Wrap(&inner);
37
38 ASSERT_EQ(inner.AST().Functions().size(), 1u);
39 ASSERT_EQ(outer.AST().Functions().size(), 1u);
40 EXPECT_EQ(inner.AST().Functions()[0], outer.AST().Functions()[0]);
41 EXPECT_TRUE(inner.Symbols().Get("a").IsValid());
42 EXPECT_EQ(inner.Symbols().Get("a"), outer.Symbols().Get("a"));
43 EXPECT_TRUE(inner.Symbols().Get("a").IsValid());
44 EXPECT_TRUE(outer.Symbols().Get("a").IsValid());
45 EXPECT_FALSE(inner.Symbols().Get("b").IsValid());
46 EXPECT_FALSE(outer.Symbols().Get("b").IsValid());
47
48 auto* ty = outer.ty.f32();
Ben Clayton42d1e092021-02-02 14:29:15 +000049 outer.Func("b", {}, ty, {}, {});
Ben Claytone43c8302021-01-29 11:59:32 +000050
51 ASSERT_EQ(inner.AST().Functions().size(), 1u);
52 ASSERT_EQ(outer.AST().Functions().size(), 2u);
53 EXPECT_EQ(inner.AST().Functions()[0], outer.AST().Functions()[0]);
54 EXPECT_EQ(outer.AST().Functions()[1]->symbol(), outer.Symbols().Get("b"));
55 EXPECT_EQ(inner.Symbols().Get("a"), outer.Symbols().Get("a"));
56 EXPECT_TRUE(inner.Symbols().Get("a").IsValid());
57 EXPECT_TRUE(outer.Symbols().Get("a").IsValid());
58 EXPECT_FALSE(inner.Symbols().Get("b").IsValid());
59 EXPECT_TRUE(outer.Symbols().Get("b").IsValid());
60}
61
62} // namespace
63} // namespace tint