[InstCombine] Signed saturation tests. NFC
[llvm-complete.git] / unittests / ADT / FunctionRefTest.cpp
blob5064a2975a9c9db8ff9c4c5e6efa16d3bf6f114f
1 //===- llvm/unittest/ADT/MakeUniqueTest.cpp - std::make_unique unit tests ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/STLExtras.h"
10 #include "gtest/gtest.h"
12 using namespace llvm;
14 namespace {
16 // Ensure that there is a default constructor and we can test for a null
17 // function_ref.
18 TEST(FunctionRefTest, Null) {
19 function_ref<int()> F;
20 EXPECT_FALSE(F);
22 auto L = [] { return 1; };
23 F = L;
24 EXPECT_TRUE(F);
26 F = {};
27 EXPECT_FALSE(F);
30 // Ensure that copies of a function_ref copy the underlying state rather than
31 // causing one function_ref to chain to the next.
32 TEST(FunctionRefTest, Copy) {
33 auto A = [] { return 1; };
34 auto B = [] { return 2; };
35 function_ref<int()> X = A;
36 function_ref<int()> Y = X;
37 X = B;
38 EXPECT_EQ(1, Y());