ADT/PointerIntPairTest.cpp: Appease msc17.
[oota-llvm.git] / unittests / ADT / TwineTest.cpp
index 2f874769507e24bb0ea22ea8278b754261036904..39d3b561b66897684a5a5e64353a4475806b0537 100644 (file)
@@ -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 {
@@ -31,15 +32,19 @@ TEST(TwineTest, Construction) {
 }
 
 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<unsigned char>('x')).str());
+  EXPECT_EQ("x", Twine(static_cast<signed char>('x')).str());
 }
 
 TEST(TwineTest, Concat) {
@@ -69,6 +74,13 @@ TEST(TwineTest, Concat) {
             repr(Twine("a").concat(Twine("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());
+}
+
   // I suppose linking in the entire code generator to add a unit test to check
   // the code size of the concat operation is overkill... :)