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/utils/scoped_assignment.h"
16
17 #include "gtest/gtest.h"
18
19 namespace tint {
20 namespace utils {
21 namespace {
22
TEST(ScopedAssignmentTest,Scopes)23 TEST(ScopedAssignmentTest, Scopes) {
24 int i = 0;
25 EXPECT_EQ(i, 0);
26 {
27 EXPECT_EQ(i, 0);
28 TINT_SCOPED_ASSIGNMENT(i, 1);
29 EXPECT_EQ(i, 1);
30 {
31 EXPECT_EQ(i, 1);
32 TINT_SCOPED_ASSIGNMENT(i, 2);
33 EXPECT_EQ(i, 2);
34 }
35 {
36 EXPECT_EQ(i, 1);
37 TINT_SCOPED_ASSIGNMENT(i, 3);
38 EXPECT_EQ(i, 3);
39 }
40 EXPECT_EQ(i, 1);
41 }
42 EXPECT_EQ(i, 0);
43 }
44
45 } // namespace
46 } // namespace utils
47 } // namespace tint
48