xref: /aosp_15_r20/external/stg/scope_test.cc (revision 9e3b08ae94a55201065475453d799e8b1378bea6)
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- mode: C++ -*-
3 //
4 // Copyright 2024 Google LLC
5 //
6 // Licensed under the Apache License v2.0 with LLVM Exceptions (the
7 // "License"); you may not use this file except in compliance with the
8 // License.  You may obtain a copy of the License at
9 //
10 //     https://llvm.org/LICENSE.txt
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 // Author: Giuliano Procida
19 
20 #include "scope.h"
21 
22 #include <string>
23 
24 #include <catch2/catch.hpp>
25 
26 namespace Test {
27 
28 using stg::Scope;
29 using stg::PushScopeName;
30 
31 TEST_CASE("scope") {
32   Scope scope;
33   CHECK(scope.name.empty());
34   CHECK(scope.named);
35   {
36     const PushScopeName p1(scope, "1", "A");
37     CHECK(!scope.name.empty());
38     CHECK(scope.named);
39     {
40       const PushScopeName p2 (scope, "2", std::string());
41       CHECK(!scope.name.empty());
42       CHECK(!scope.named);
43       {
44         const PushScopeName p3(scope, "3", "B");
45         CHECK(!scope.name.empty());
46         CHECK(!scope.named);
47       }
48       CHECK(!scope.name.empty());
49       CHECK(!scope.named);
50     }
51     CHECK(!scope.name.empty());
52     CHECK(scope.named);
53   }
54   CHECK(scope.name.empty());
55   CHECK(scope.named);
56 }
57 
58 }  // namespace Test
59