Ben Clayton | e43c830 | 2021-01-29 11:59:32 +0000 | [diff] [blame] | 1 | // 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 | |
| 19 | namespace tint { |
| 20 | namespace { |
| 21 | |
| 22 | using ProgramBuilderTest = testing::Test; |
| 23 | |
| 24 | TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) { |
| 25 | Program inner([] { |
| 26 | ProgramBuilder builder; |
| 27 | auto* ty = builder.ty.f32(); |
Ben Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 28 | builder.Func("a", {}, ty, {}, {}); |
Ben Clayton | e43c830 | 2021-01-29 11:59:32 +0000 | [diff] [blame] | 29 | 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 Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 49 | outer.Func("b", {}, ty, {}, {}); |
Ben Clayton | e43c830 | 2021-01-29 11:59:32 +0000 | [diff] [blame] | 50 | |
| 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 |