From 8bd42a1a98377b717bfa3fae6efde4f72c18fea4 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Tue, 14 Feb 2017 19:06:37 +0000 Subject: [Support] Add StringRef::getAsDouble. Differential Revision: https://reviews.llvm.org/D29918 llvm-svn: 295089 --- llvm/unittests/ADT/StringRefTest.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'llvm/unittests/ADT/StringRefTest.cpp') 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"; -- cgit v1.2.3