diff options
| author | Dylan Noblesmith <nobled@dreamwidth.org> | 2011-06-15 23:36:34 +0000 |
|---|---|---|
| committer | Dylan Noblesmith <nobled@dreamwidth.org> | 2011-06-15 23:36:34 +0000 |
| commit | c8c184d2f80c2b3000a0d2cbf2462be0a58b0468 (patch) | |
| tree | 60068abef4f086eb33672826422750bfae62e1d8 /llvm/unittests/ADT/APIntTest.cpp | |
| parent | 96adc4a5401e05a94740a5096e096c45d528ecba (diff) | |
| download | llvm-c8c184d2f80c2b3000a0d2cbf2462be0a58b0468.zip llvm-c8c184d2f80c2b3000a0d2cbf2462be0a58b0468.tar.gz llvm-c8c184d2f80c2b3000a0d2cbf2462be0a58b0468.tar.bz2 | |
unittests: add test for APInt::toString()
Follow up to r133032.
llvm-svn: 133107
Diffstat (limited to 'llvm/unittests/ADT/APIntTest.cpp')
| -rw-r--r-- | llvm/unittests/ADT/APIntTest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index dbd0cb7..1f78cd33 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -320,6 +320,52 @@ TEST(APIntTest, StringBitsNeeded16) { EXPECT_EQ(9U, APInt::getBitsNeeded("-20", 16)); } +TEST(APIntTest, toString) { + SmallString<16> S; + bool isSigned; + + APInt(8, 0).toString(S, 2, true, true); + EXPECT_EQ(S.str().str(), "0b0"); + S.clear(); + APInt(8, 0).toString(S, 8, true, true); + EXPECT_EQ(S.str().str(), "00"); + S.clear(); + APInt(8, 0).toString(S, 10, true, true); + EXPECT_EQ(S.str().str(), "0"); + S.clear(); + APInt(8, 0).toString(S, 16, true, true); + EXPECT_EQ(S.str().str(), "0x0"); + S.clear(); + + isSigned = false; + APInt(8, 255, isSigned).toString(S, 2, isSigned, true); + EXPECT_EQ(S.str().str(), "0b11111111"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 8, isSigned, true); + EXPECT_EQ(S.str().str(), "0377"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 10, isSigned, true); + EXPECT_EQ(S.str().str(), "255"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 16, isSigned, true); + EXPECT_EQ(S.str().str(), "0xFF"); + S.clear(); + + isSigned = true; + APInt(8, 255, isSigned).toString(S, 2, isSigned, true); + EXPECT_EQ(S.str().str(), "-0b1"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 8, isSigned, true); + EXPECT_EQ(S.str().str(), "-01"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 10, isSigned, true); + EXPECT_EQ(S.str().str(), "-1"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 16, isSigned, true); + EXPECT_EQ(S.str().str(), "-0x1"); + S.clear(); +} + TEST(APIntTest, Log2) { EXPECT_EQ(APInt(15, 7).logBase2(), 2U); EXPECT_EQ(APInt(15, 7).ceilLogBase2(), 3U); |
