diff options
| author | 2017-10-04 20:27:34 +0000 | |
|---|---|---|
| committer | 2017-10-04 20:27:34 +0000 | |
| commit | 31eb748944903b7f4f38afda9851951ca9dfc1ae (patch) | |
| tree | 9b95b6ea45d0874d75eb05b90c0840e191416439 /gnu/llvm/unittests/ADT/StringRefTest.cpp | |
| parent | Don't try to handle IPv4-compatible IPv6 addresses (diff) | |
| download | wireguard-openbsd-31eb748944903b7f4f38afda9851951ca9dfc1ae.tar.xz wireguard-openbsd-31eb748944903b7f4f38afda9851951ca9dfc1ae.zip | |
Import LLVM 5.0.0 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/unittests/ADT/StringRefTest.cpp')
| -rw-r--r-- | gnu/llvm/unittests/ADT/StringRefTest.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/gnu/llvm/unittests/ADT/StringRefTest.cpp b/gnu/llvm/unittests/ADT/StringRefTest.cpp index 5b6822ed757..0684afe678f 100644 --- a/gnu/llvm/unittests/ADT/StringRefTest.cpp +++ b/gnu/llvm/unittests/ADT/StringRefTest.cpp @@ -504,8 +504,22 @@ TEST(StringRefTest, Count) { } TEST(StringRefTest, EditDistance) { - StringRef Str("hello"); - EXPECT_EQ(2U, Str.edit_distance("hill")); + StringRef Hello("hello"); + EXPECT_EQ(2U, Hello.edit_distance("hill")); + + StringRef Industry("industry"); + EXPECT_EQ(6U, Industry.edit_distance("interest")); + + StringRef Soylent("soylent green is people"); + EXPECT_EQ(19U, Soylent.edit_distance("people soiled our green")); + EXPECT_EQ(26U, Soylent.edit_distance("people soiled our green", + /* allow replacements = */ false)); + EXPECT_EQ(9U, Soylent.edit_distance("people soiled our green", + /* allow replacements = */ true, + /* max edit distance = */ 8)); + EXPECT_EQ(53U, Soylent.edit_distance("people soiled our green " + "people soiled our green " + "people soiled our green ")); } TEST(StringRefTest, Misc) { @@ -852,6 +866,28 @@ 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"; @@ -878,6 +914,8 @@ TEST(StringRefTest, joinStrings) { EXPECT_TRUE(v2_join2); bool v2_join3 = join(v2.begin(), v2.end(), "::") == join_result3; EXPECT_TRUE(v2_join3); + v2_join3 = join(v2, "::") == join_result3; + EXPECT_TRUE(v2_join3); } |
