diff options
author | Alex Lorenz <arphaman@gmail.com> | 2015-06-23 18:22:10 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2015-06-23 18:22:10 +0000 |
commit | 6f8a6be145875d96ed4e4ee78099805ddabfaaa0 (patch) | |
tree | 407145368320891ca76dab8f73faa0795e2e3f55 /llvm/unittests/ADT/APSIntTest.cpp | |
parent | a5d9c1d32fe0573b31cbbe5cc6d892fcebb92e9c (diff) | |
download | bcm5719-llvm-6f8a6be145875d96ed4e4ee78099805ddabfaaa0.tar.gz bcm5719-llvm-6f8a6be145875d96ed4e4ee78099805ddabfaaa0.zip |
ADT: Add a string APSInt constructor.
This commit moves the APSInt initialization code that's used by
the LLLexer class into a new APSInt constructor that constructs
APSInts from strings.
This change is useful for MIR Serialization, as it would allow
the MILexer class to use the same APSInt initialization as
LLexer when parsing immediate machine operands.
llvm-svn: 240436
Diffstat (limited to 'llvm/unittests/ADT/APSIntTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/APSIntTest.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/APSIntTest.cpp b/llvm/unittests/ADT/APSIntTest.cpp index 5e4e87440bd..44430055e90 100644 --- a/llvm/unittests/ADT/APSIntTest.cpp +++ b/llvm/unittests/ADT/APSIntTest.cpp @@ -143,4 +143,23 @@ TEST(APSIntTest, compareValues) { EXPECT_TRUE(APSInt::compareValues(U(8), S(-7).trunc(32)) > 0); } +TEST(APSIntTest, FromString) { + EXPECT_EQ(APSInt("1").getExtValue(), 1); + EXPECT_EQ(APSInt("-1").getExtValue(), -1); + EXPECT_EQ(APSInt("0").getExtValue(), 0); + EXPECT_EQ(APSInt("56789").getExtValue(), 56789); + EXPECT_EQ(APSInt("-1234").getExtValue(), -1234); } + +#ifdef GTEST_HAS_DEATH_TEST +#ifndef NDEBUG + +TEST(APSIntTest, StringDeath) { + EXPECT_DEATH(APSInt(""), "Invalid string length"); + EXPECT_DEATH(APSInt("1a"), "Invalid character in digit string"); +} + +#endif +#endif + +} // end anonymous namespace |