David Blaikie | d907838 | 2014-11-12 02:06:08 +0000 | [diff] [blame] | 1 | //===- llvm/unittest/ADT/MakeUniqueTest.cpp - make_unique unit tests ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/ADT/STLExtras.h" |
| 11 | #include "gtest/gtest.h" |
| 12 | |
| 13 | using namespace llvm; |
| 14 | |
| 15 | namespace { |
| 16 | |
Chandler Carruth | cc60d7b | 2017-07-09 06:12:56 +0000 | [diff] [blame] | 17 | // Ensure that there is a default constructor and we can test for a null |
| 18 | // function_ref. |
| 19 | TEST(FunctionRefTest, Null) { |
| 20 | function_ref<int()> F; |
| 21 | EXPECT_FALSE(F); |
| 22 | |
| 23 | auto L = [] { return 1; }; |
| 24 | F = L; |
| 25 | EXPECT_TRUE(F); |
| 26 | |
| 27 | F = {}; |
| 28 | EXPECT_FALSE(F); |
| 29 | } |
| 30 | |
David Blaikie | d907838 | 2014-11-12 02:06:08 +0000 | [diff] [blame] | 31 | // Ensure that copies of a function_ref copy the underlying state rather than |
| 32 | // causing one function_ref to chain to the next. |
| 33 | TEST(FunctionRefTest, Copy) { |
| 34 | auto A = [] { return 1; }; |
| 35 | auto B = [] { return 2; }; |
| 36 | function_ref<int()> X = A; |
| 37 | function_ref<int()> Y = X; |
| 38 | X = B; |
| 39 | EXPECT_EQ(1, Y()); |
| 40 | } |
| 41 | |
| 42 | } |