X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FADT%2FTwineTest.cpp;h=9683e97511b6cb583e9e4f977f2fe2a410371837;hb=205d072f694fe0e9c9dc18a2da9c74bf5151ef57;hp=2f874769507e24bb0ea22ea8278b754261036904;hpb=4baffeb6be3a224f7adadbee17512ded22610fd0;p=oota-llvm.git diff --git a/unittests/ADT/TwineTest.cpp b/unittests/ADT/TwineTest.cpp index 2f874769507..9683e97511b 100644 --- a/unittests/ADT/TwineTest.cpp +++ b/unittests/ADT/TwineTest.cpp @@ -7,9 +7,10 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/Twine.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Support/raw_ostream.h" +#include "gtest/gtest.h" using namespace llvm; namespace { @@ -28,18 +29,23 @@ TEST(TwineTest, Construction) { EXPECT_EQ("hi", Twine(StringRef("hi")).str()); EXPECT_EQ("hi", Twine(StringRef(std::string("hi"))).str()); EXPECT_EQ("hi", Twine(StringRef("hithere", 2)).str()); + EXPECT_EQ("hi", Twine(SmallString<4>("hi")).str()); } TEST(TwineTest, Numbers) { - EXPECT_EQ("123", Twine::utostr(123).str()); - EXPECT_EQ("-123", Twine::itostr(-123).str()); - EXPECT_EQ("123", Twine::utostr(123).str()); - EXPECT_EQ("-123", Twine::itostr(-123).str()); - EXPECT_EQ("123", Twine::utostr((char) 123).str()); - EXPECT_EQ("-123", Twine::itostr((signed char) -123).str()); + EXPECT_EQ("123", Twine(123U).str()); + EXPECT_EQ("123", Twine(123).str()); + EXPECT_EQ("-123", Twine(-123).str()); + EXPECT_EQ("123", Twine(123).str()); + EXPECT_EQ("-123", Twine(-123).str()); + + EXPECT_EQ("7b", Twine::utohexstr(123).str()); +} - EXPECT_EQ("7B", Twine::utohexstr(123).str()); - EXPECT_EQ("FFFFFFFFFFFFFF85", Twine::itohexstr(-123).str()); +TEST(TwineTest, Characters) { + EXPECT_EQ("x", Twine('x').str()); + EXPECT_EQ("x", Twine(static_cast('x')).str()); + EXPECT_EQ("x", Twine(static_cast('x')).str()); } TEST(TwineTest, Concat) { @@ -57,6 +63,10 @@ TEST(TwineTest, Concat) { repr(Twine("hi").concat(Twine()))); EXPECT_EQ("(Twine cstring:\"hi\" empty)", repr(Twine().concat(Twine("hi")))); + EXPECT_EQ("(Twine smallstring:\"hi\" empty)", + repr(Twine().concat(Twine(SmallString<5>("hi"))))); + EXPECT_EQ("(Twine smallstring:\"hey\" cstring:\"there\")", + repr(Twine(SmallString<7>("hey")).concat(Twine("there")))); // Concatenation of unary ropes. EXPECT_EQ("(Twine cstring:\"a\" cstring:\"b\")", @@ -67,6 +77,18 @@ TEST(TwineTest, Concat) { repr(Twine("a").concat(Twine("b")).concat(Twine("c")))); EXPECT_EQ("(Twine cstring:\"a\" rope:(Twine cstring:\"b\" cstring:\"c\"))", repr(Twine("a").concat(Twine("b").concat(Twine("c"))))); + EXPECT_EQ("(Twine cstring:\"a\" rope:(Twine smallstring:\"b\" cstring:\"c\"))", + repr(Twine("a").concat(Twine(SmallString<3>("b")).concat(Twine("c"))))); +} + +TEST(TwineTest, toNullTerminatedStringRef) { + SmallString<8> storage; + EXPECT_EQ(0, *Twine("hello").toNullTerminatedStringRef(storage).end()); + EXPECT_EQ(0, + *Twine(StringRef("hello")).toNullTerminatedStringRef(storage).end()); + EXPECT_EQ(0, *Twine(SmallString<11>("hello")) + .toNullTerminatedStringRef(storage) + .end()); } // I suppose linking in the entire code generator to add a unit test to check