aboutsummaryrefslogtreecommitdiff
path: root/unittests/ADT/StringRefTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/ADT/StringRefTest.cpp')
-rw-r--r--unittests/ADT/StringRefTest.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp
index 5b6822ed757d..e308f2d7c64b 100644
--- a/unittests/ADT/StringRefTest.cpp
+++ b/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,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";
@@ -878,6 +913,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);
}