diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2009-10-14 17:57:32 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2009-10-14 17:57:32 +0000 |
commit | cd749a9c07f1de2fb8affde90537efa4bc3e7c54 (patch) | |
tree | b21f6de4e08b89bb7931806bab798fc2a5e3a686 /unittests/ADT/TwineTest.cpp | |
parent | 72621d11de5b873f1695f391eb95f0b336c3d2d4 (diff) | |
download | FreeBSD-src-cd749a9c07f1de2fb8affde90537efa4bc3e7c54.zip FreeBSD-src-cd749a9c07f1de2fb8affde90537efa4bc3e7c54.tar.gz |
Update llvm to r84119.
Diffstat (limited to 'unittests/ADT/TwineTest.cpp')
-rw-r--r-- | unittests/ADT/TwineTest.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/unittests/ADT/TwineTest.cpp b/unittests/ADT/TwineTest.cpp new file mode 100644 index 0000000..61e8a0a --- /dev/null +++ b/unittests/ADT/TwineTest.cpp @@ -0,0 +1,75 @@ +//===- TwineTest.cpp - Twine unit tests -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Support/raw_ostream.h" +using namespace llvm; + +namespace { + +std::string repr(const Twine &Value) { + std::string res; + llvm::raw_string_ostream OS(res); + Value.printRepr(OS); + return OS.str(); +} + +TEST(TwineTest, Construction) { + EXPECT_EQ("", Twine().str()); + EXPECT_EQ("hi", Twine("hi").str()); + EXPECT_EQ("hi", Twine(std::string("hi")).str()); + EXPECT_EQ("hi", Twine(StringRef("hi")).str()); + EXPECT_EQ("hi", Twine(StringRef(std::string("hi"))).str()); + EXPECT_EQ("hi", Twine(StringRef("hithere", 2)).str()); +} + +TEST(TwineTest, Numbers) { + 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("123", Twine((char) 123).str()); + EXPECT_EQ("-123", Twine((signed char) -123).str()); + + EXPECT_EQ("7b", Twine::utohexstr(123).str()); +} + +TEST(TwineTest, Concat) { + // Check verse repr, since we care about the actual representation not just + // the result. + + // Concat with null. + EXPECT_EQ("(Twine null empty)", + repr(Twine("hi").concat(Twine::createNull()))); + EXPECT_EQ("(Twine null empty)", + repr(Twine::createNull().concat(Twine("hi")))); + + // Concat with empty. + EXPECT_EQ("(Twine cstring:\"hi\" empty)", + repr(Twine("hi").concat(Twine()))); + EXPECT_EQ("(Twine cstring:\"hi\" empty)", + repr(Twine().concat(Twine("hi")))); + + // Concatenation of unary ropes. + EXPECT_EQ("(Twine cstring:\"a\" cstring:\"b\")", + repr(Twine("a").concat(Twine("b")))); + + // Concatenation of other ropes. + EXPECT_EQ("(Twine rope:(Twine cstring:\"a\" cstring:\"b\") cstring:\"c\")", + 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"))))); +} + + // I suppose linking in the entire code generator to add a unit test to check + // the code size of the concat operation is overkill... :) + +} // end anonymous namespace |