blob: b7ef7d79e5f99f8636ec60d55da8d0dcc0fbeddd [file] [log] [blame]
David Blaikied9078382014-11-12 02:06:08 +00001//===- 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
13using namespace llvm;
14
15namespace {
16
Chandler Carruthcc60d7b2017-07-09 06:12:56 +000017// Ensure that there is a default constructor and we can test for a null
18// function_ref.
19TEST(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 Blaikied9078382014-11-12 02:06:08 +000031// Ensure that copies of a function_ref copy the underlying state rather than
32// causing one function_ref to chain to the next.
33TEST(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}