diff options
Diffstat (limited to 'llvm/unittests/ADT/StringRefTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/StringRefTest.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp index 5b6822ed757..614ec5d59e6 100644 --- a/llvm/unittests/ADT/StringRefTest.cpp +++ b/llvm/unittests/ADT/StringRefTest.cpp @@ -852,6 +852,27 @@ TEST(StringRefTest, consumeIntegerSigned) { } } +struct GetDoubleStrings { + const char *Str; + bool AllowInexact; + bool ShouldFail; + double D; +} DoubleStrings[] = {{"0", false, false, 0.0}, + {"0.0", false, false, 0.0}, + {"-0.0", false, false, -0.0}, + {"123.45", false, true, 123.45}, + {"123.45", true, false, 123.45}}; + +TEST(StringRefTest, getAsDouble) { + for (const auto &Entry : DoubleStrings) { + double Result; + StringRef S(Entry.Str); + EXPECT_EQ(Entry.ShouldFail, S.getAsDouble(Result, Entry.AllowInexact)); + if (!Entry.ShouldFail) + EXPECT_EQ(Result, Entry.D); + } +} + static const char *join_input[] = { "a", "b", "c" }; static const char join_result1[] = "a"; static const char join_result2[] = "a:b:c"; |