Mercurial > hg > CbC > CbC_llvm
comparison unittests/ADT/StringRefTest.cpp @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
comparison
equal
deleted
inserted
replaced
146:3fc4d5c3e21e | 148:63bd29f05246 |
---|---|
1 //===- llvm/unittest/ADT/StringRefTest.cpp - StringRef unit tests ---------===// | 1 //===- llvm/unittest/ADT/StringRefTest.cpp - StringRef unit tests ---------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 // | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // This file is distributed under the University of Illinois Open Source | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // License. See LICENSE.TXT for details. | |
7 // | 6 // |
8 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
9 | 8 |
10 #include "llvm/ADT/StringRef.h" | 9 #include "llvm/ADT/StringRef.h" |
11 #include "llvm/ADT/Hashing.h" | 10 #include "llvm/ADT/Hashing.h" |
33 } | 32 } |
34 | 33 |
35 // Check that we can't accidentally assign a temporary std::string to a | 34 // Check that we can't accidentally assign a temporary std::string to a |
36 // StringRef. (Unfortunately we can't make use of the same thing with | 35 // StringRef. (Unfortunately we can't make use of the same thing with |
37 // constructors.) | 36 // constructors.) |
38 // | |
39 // Disable this check under MSVC; even MSVC 2015 isn't consistent between | |
40 // std::is_assignable and actually writing such an assignment. | |
41 #if !defined(_MSC_VER) | |
42 static_assert( | 37 static_assert( |
43 !std::is_assignable<StringRef&, std::string>::value, | 38 !std::is_assignable<StringRef&, std::string>::value, |
44 "Assigning from prvalue std::string"); | 39 "Assigning from prvalue std::string"); |
45 static_assert( | 40 static_assert( |
46 !std::is_assignable<StringRef&, std::string &&>::value, | 41 !std::is_assignable<StringRef&, std::string &&>::value, |
55 std::is_assignable<StringRef&, const char * &&>::value, | 50 std::is_assignable<StringRef&, const char * &&>::value, |
56 "Assigning from xvalue C string"); | 51 "Assigning from xvalue C string"); |
57 static_assert( | 52 static_assert( |
58 std::is_assignable<StringRef&, const char * &>::value, | 53 std::is_assignable<StringRef&, const char * &>::value, |
59 "Assigning from lvalue C string"); | 54 "Assigning from lvalue C string"); |
60 #endif | |
61 | |
62 | 55 |
63 namespace { | 56 namespace { |
64 TEST(StringRefTest, Construction) { | 57 TEST(StringRefTest, Construction) { |
65 EXPECT_EQ("", StringRef()); | 58 EXPECT_EQ("", StringRef()); |
66 EXPECT_EQ("hello", StringRef("hello")); | 59 EXPECT_EQ("hello", StringRef("hello")); |
179 Str.rsplit('h')); | 172 Str.rsplit('h')); |
180 EXPECT_EQ(std::make_pair(StringRef("hel"), StringRef("o")), | 173 EXPECT_EQ(std::make_pair(StringRef("hel"), StringRef("o")), |
181 Str.rsplit('l')); | 174 Str.rsplit('l')); |
182 EXPECT_EQ(std::make_pair(StringRef("hell"), StringRef("")), | 175 EXPECT_EQ(std::make_pair(StringRef("hell"), StringRef("")), |
183 Str.rsplit('o')); | 176 Str.rsplit('o')); |
177 | |
178 EXPECT_EQ(std::make_pair(StringRef("he"), StringRef("o")), | |
179 Str.rsplit("ll")); | |
180 EXPECT_EQ(std::make_pair(StringRef(""), StringRef("ello")), | |
181 Str.rsplit("h")); | |
182 EXPECT_EQ(std::make_pair(StringRef("hell"), StringRef("")), | |
183 Str.rsplit("o")); | |
184 EXPECT_EQ(std::make_pair(StringRef("hello"), StringRef("")), | |
185 Str.rsplit("::")); | |
186 EXPECT_EQ(std::make_pair(StringRef("hel"), StringRef("o")), | |
187 Str.rsplit("l")); | |
184 } | 188 } |
185 | 189 |
186 TEST(StringRefTest, Split2) { | 190 TEST(StringRefTest, Split2) { |
187 SmallVector<StringRef, 5> parts; | 191 SmallVector<StringRef, 5> parts; |
188 SmallVector<StringRef, 5> expected; | 192 SmallVector<StringRef, 5> expected; |
1049 constexpr StringLiteral Strings[] = {"Foo", "Bar"}; | 1053 constexpr StringLiteral Strings[] = {"Foo", "Bar"}; |
1050 EXPECT_EQ(StringRef("Foo"), Strings[0]); | 1054 EXPECT_EQ(StringRef("Foo"), Strings[0]); |
1051 EXPECT_EQ(StringRef("Bar"), Strings[1]); | 1055 EXPECT_EQ(StringRef("Bar"), Strings[1]); |
1052 } | 1056 } |
1053 | 1057 |
1058 static_assert(is_trivially_copyable<StringRef>::value, "trivially copyable"); | |
1059 | |
1054 } // end anonymous namespace | 1060 } // end anonymous namespace |