we don't want people to override printBasicBlockLabel.
[llvm/avr.git] / unittests / ADT / TwineTest.cpp
blob61e8a0ac37cbbccfe7cd1cb13103cffaef24b276
1 //===- TwineTest.cpp - Twine 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 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
11 #include "llvm/ADT/Twine.h"
12 #include "llvm/Support/raw_ostream.h"
13 using namespace llvm;
15 namespace {
17 std::string repr(const Twine &Value) {
18 std::string res;
19 llvm::raw_string_ostream OS(res);
20 Value.printRepr(OS);
21 return OS.str();
24 TEST(TwineTest, Construction) {
25 EXPECT_EQ("", Twine().str());
26 EXPECT_EQ("hi", Twine("hi").str());
27 EXPECT_EQ("hi", Twine(std::string("hi")).str());
28 EXPECT_EQ("hi", Twine(StringRef("hi")).str());
29 EXPECT_EQ("hi", Twine(StringRef(std::string("hi"))).str());
30 EXPECT_EQ("hi", Twine(StringRef("hithere", 2)).str());
33 TEST(TwineTest, Numbers) {
34 EXPECT_EQ("123", Twine(123U).str());
35 EXPECT_EQ("123", Twine(123).str());
36 EXPECT_EQ("-123", Twine(-123).str());
37 EXPECT_EQ("123", Twine(123).str());
38 EXPECT_EQ("-123", Twine(-123).str());
39 EXPECT_EQ("123", Twine((char) 123).str());
40 EXPECT_EQ("-123", Twine((signed char) -123).str());
42 EXPECT_EQ("7b", Twine::utohexstr(123).str());
45 TEST(TwineTest, Concat) {
46 // Check verse repr, since we care about the actual representation not just
47 // the result.
49 // Concat with null.
50 EXPECT_EQ("(Twine null empty)",
51 repr(Twine("hi").concat(Twine::createNull())));
52 EXPECT_EQ("(Twine null empty)",
53 repr(Twine::createNull().concat(Twine("hi"))));
55 // Concat with empty.
56 EXPECT_EQ("(Twine cstring:\"hi\" empty)",
57 repr(Twine("hi").concat(Twine())));
58 EXPECT_EQ("(Twine cstring:\"hi\" empty)",
59 repr(Twine().concat(Twine("hi"))));
61 // Concatenation of unary ropes.
62 EXPECT_EQ("(Twine cstring:\"a\" cstring:\"b\")",
63 repr(Twine("a").concat(Twine("b"))));
65 // Concatenation of other ropes.
66 EXPECT_EQ("(Twine rope:(Twine cstring:\"a\" cstring:\"b\") cstring:\"c\")",
67 repr(Twine("a").concat(Twine("b")).concat(Twine("c"))));
68 EXPECT_EQ("(Twine cstring:\"a\" rope:(Twine cstring:\"b\" cstring:\"c\"))",
69 repr(Twine("a").concat(Twine("b").concat(Twine("c")))));
72 // I suppose linking in the entire code generator to add a unit test to check
73 // the code size of the concat operation is overkill... :)
75 } // end anonymous namespace