diff options
author | dim <dim@FreeBSD.org> | 2011-10-20 21:10:27 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-10-20 21:10:27 +0000 |
commit | 7b3392326c40c3c20697816acae597ba7b3144eb (patch) | |
tree | 2cbcf22585e99f8a87d12d5ff94f392c0d266819 /unittests/ADT/APIntTest.cpp | |
parent | 1176aa52646fe641a4243a246aa7f960c708a274 (diff) | |
download | FreeBSD-src-7b3392326c40c3c20697816acae597ba7b3144eb.zip FreeBSD-src-7b3392326c40c3c20697816acae597ba7b3144eb.tar.gz |
Vendor import of llvm release_30 branch r142614:
http://llvm.org/svn/llvm-project/llvm/branches/release_30@142614
Diffstat (limited to 'unittests/ADT/APIntTest.cpp')
-rw-r--r-- | unittests/ADT/APIntTest.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp index 1f78cd3..490811d 100644 --- a/unittests/ADT/APIntTest.cpp +++ b/unittests/ADT/APIntTest.cpp @@ -237,6 +237,24 @@ TEST(APIntTest, fromString) { EXPECT_EQ(APInt(32, uint64_t(-16LL)), APInt(32, "-10", 16)); EXPECT_EQ(APInt(32, uint64_t(-31LL)), APInt(32, "-1F", 16)); EXPECT_EQ(APInt(32, uint64_t(-32LL)), APInt(32, "-20", 16)); + + EXPECT_EQ(APInt(32, 0), APInt(32, "0", 36)); + EXPECT_EQ(APInt(32, 1), APInt(32, "1", 36)); + EXPECT_EQ(APInt(32, 35), APInt(32, "Z", 36)); + EXPECT_EQ(APInt(32, 36), APInt(32, "10", 36)); + EXPECT_EQ(APInt(32, 71), APInt(32, "1Z", 36)); + EXPECT_EQ(APInt(32, 72), APInt(32, "20", 36)); + + EXPECT_EQ(APInt(32, uint64_t(-0LL)), APInt(32, "-0", 36)); + EXPECT_EQ(APInt(32, uint64_t(-1LL)), APInt(32, "-1", 36)); + EXPECT_EQ(APInt(32, uint64_t(-35LL)), APInt(32, "-Z", 36)); + EXPECT_EQ(APInt(32, uint64_t(-36LL)), APInt(32, "-10", 36)); + EXPECT_EQ(APInt(32, uint64_t(-71LL)), APInt(32, "-1Z", 36)); + EXPECT_EQ(APInt(32, uint64_t(-72LL)), APInt(32, "-20", 36)); +} + +TEST(APIntTest, FromArray) { + EXPECT_EQ(APInt(32, uint64_t(1)), APInt(32, ArrayRef<uint64_t>(1))); } TEST(APIntTest, StringBitsNeeded2) { @@ -336,6 +354,9 @@ TEST(APIntTest, toString) { APInt(8, 0).toString(S, 16, true, true); EXPECT_EQ(S.str().str(), "0x0"); S.clear(); + APInt(8, 0).toString(S, 36, true, true); + EXPECT_EQ(S.str().str(), "0"); + S.clear(); isSigned = false; APInt(8, 255, isSigned).toString(S, 2, isSigned, true); @@ -350,6 +371,9 @@ TEST(APIntTest, toString) { APInt(8, 255, isSigned).toString(S, 16, isSigned, true); EXPECT_EQ(S.str().str(), "0xFF"); S.clear(); + APInt(8, 255, isSigned).toString(S, 36, isSigned, true); + EXPECT_EQ(S.str().str(), "73"); + S.clear(); isSigned = true; APInt(8, 255, isSigned).toString(S, 2, isSigned, true); @@ -364,6 +388,9 @@ TEST(APIntTest, toString) { APInt(8, 255, isSigned).toString(S, 16, isSigned, true); EXPECT_EQ(S.str().str(), "-0x1"); S.clear(); + APInt(8, 255, isSigned).toString(S, 36, isSigned, true); + EXPECT_EQ(S.str().str(), "-1"); + S.clear(); } TEST(APIntTest, Log2) { @@ -403,7 +430,7 @@ TEST(APIntTest, magicu) { TEST(APIntTest, StringDeath) { EXPECT_DEATH(APInt(0, "", 0), "Bitwidth too small"); EXPECT_DEATH(APInt(32, "", 0), "Invalid string length"); - EXPECT_DEATH(APInt(32, "0", 0), "Radix should be 2, 8, 10, or 16!"); + EXPECT_DEATH(APInt(32, "0", 0), "Radix should be 2, 8, 10, 16, or 36!"); EXPECT_DEATH(APInt(32, "", 10), "Invalid string length"); EXPECT_DEATH(APInt(32, "-", 10), "String is only a sign, needs a value."); EXPECT_DEATH(APInt(1, "1234", 10), "Insufficient bit width"); @@ -414,4 +441,13 @@ TEST(APIntTest, StringDeath) { #endif #endif +TEST(APIntTest, mul_clear) { + APInt ValA(65, -1ULL); + APInt ValB(65, 4); + APInt ValC(65, 0); + ValC = ValA * ValB; + ValA *= ValB; + EXPECT_EQ(ValA.toString(10, false), ValC.toString(10, false)); +} + } |