Googler | b56d709 | 2021-11-26 12:38:29 +0000 | [diff] [blame] | 1 | // Part of the Crubit project, under the Apache License v2.0 with LLVM |
| 2 | // Exceptions. See /LICENSE for license information. |
| 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | |
| 5 | #include "lifetime_annotations/lifetime.h" |
| 6 | |
Luca Versari | c21d92f | 2022-05-25 00:56:30 -0700 | [diff] [blame] | 7 | #include "gmock/gmock.h" |
| 8 | #include "gtest/gtest.h" |
Googler | b56d709 | 2021-11-26 12:38:29 +0000 | [diff] [blame] | 9 | |
Martin Brænne | 1a207c5 | 2022-04-19 00:05:38 -0700 | [diff] [blame] | 10 | namespace clang { |
| 11 | namespace tidy { |
| 12 | namespace lifetimes { |
Googler | b56d709 | 2021-11-26 12:38:29 +0000 | [diff] [blame] | 13 | namespace { |
| 14 | |
| 15 | TEST(Lifetime, IsVariable) { |
| 16 | EXPECT_TRUE(Lifetime::CreateVariable().IsVariable()); |
| 17 | EXPECT_FALSE(Lifetime::Static().IsVariable()); |
| 18 | EXPECT_FALSE(Lifetime::CreateLocal().IsVariable()); |
| 19 | } |
| 20 | |
| 21 | TEST(Lifetime, IsConstant) { |
| 22 | EXPECT_TRUE(Lifetime::Static().IsConstant()); |
| 23 | EXPECT_TRUE(Lifetime::CreateLocal().IsConstant()); |
| 24 | EXPECT_FALSE(Lifetime::CreateVariable().IsConstant()); |
| 25 | } |
| 26 | |
| 27 | TEST(Lifetime, IsLocal) { |
| 28 | EXPECT_TRUE(Lifetime::CreateLocal().IsLocal()); |
| 29 | EXPECT_FALSE(Lifetime::Static().IsLocal()); |
| 30 | } |
| 31 | |
| 32 | TEST(Lifetime, Equality) { |
| 33 | Lifetime l1 = Lifetime::CreateVariable(); |
| 34 | Lifetime l2 = Lifetime::CreateVariable(); |
| 35 | |
| 36 | EXPECT_EQ(l1, l1); |
| 37 | EXPECT_EQ(l2, l2); |
| 38 | EXPECT_NE(l1, l2); |
| 39 | EXPECT_NE(l2, l1); |
| 40 | |
| 41 | EXPECT_EQ(Lifetime::Static(), Lifetime::Static()); |
| 42 | EXPECT_NE(l1, Lifetime::Static()); |
| 43 | |
| 44 | Lifetime local1 = Lifetime::CreateLocal(); |
| 45 | Lifetime local2 = Lifetime::CreateLocal(); |
| 46 | EXPECT_NE(local1, local2); |
| 47 | EXPECT_NE(l1, local1); |
| 48 | } |
| 49 | |
| 50 | TEST(Lifetime, Copy) { |
| 51 | Lifetime l1 = Lifetime::CreateVariable(); |
| 52 | Lifetime l2 = l1; |
| 53 | |
| 54 | EXPECT_EQ(l1, l2); |
| 55 | |
| 56 | Lifetime l3 = Lifetime::CreateVariable(); |
| 57 | EXPECT_NE(l1, l3); |
| 58 | l3 = l1; |
| 59 | EXPECT_EQ(l1, l3); |
| 60 | } |
| 61 | |
| 62 | } // namespace |
Martin Brænne | 1a207c5 | 2022-04-19 00:05:38 -0700 | [diff] [blame] | 63 | } // namespace lifetimes |
| 64 | } // namespace tidy |
| 65 | } // namespace clang |