diff options
author | Tommy Nguyen <remyabel@gmail.com> | 2019-12-02 07:42:33 -0500 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-02 13:52:42 +0100 |
commit | 2eb5793d55b48782cc1c4974f957ebcce9881dba (patch) | |
tree | b95b2967cc414f249961048b23c9e000060021ad /AK/Tests | |
parent | 035c4e15f48a7189683d03a3af8fc99fd127ac21 (diff) | |
download | serenity-2eb5793d55b48782cc1c4974f957ebcce9881dba.zip |
LibMarkdown: Handle CRLF line endings
Previously, MDDocument only split on Unix-style line endings. This adds
a new function to StringView which handles LF, CR and CRLF.
Diffstat (limited to 'AK/Tests')
-rw-r--r-- | AK/Tests/TestStringView.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/AK/Tests/TestStringView.cpp b/AK/Tests/TestStringView.cpp index add8726a1b..d98c74138d 100644 --- a/AK/Tests/TestStringView.cpp +++ b/AK/Tests/TestStringView.cpp @@ -42,4 +42,25 @@ TEST_CASE(starts_with) EXPECT(!test_string_view.starts_with("DEF")); } +TEST_CASE(lines) +{ + String test_string = "a\nb\r\nc\rd"; + StringView test_string_view = test_string.view(); + Vector<StringView> test_string_vector = test_string_view.lines(); + EXPECT_EQ(test_string_vector.size(), 4); + EXPECT(test_string_vector.at(0) == String("a")); + EXPECT(test_string_vector.at(1) == String("b")); + EXPECT(test_string_vector.at(2) == String("c")); + EXPECT(test_string_vector.at(3) == String("d")); + + test_string = "```\nHello there\r\nHello there\n```"; + test_string_view = test_string.view(); + test_string_vector = test_string_view.lines(); + EXPECT_EQ(test_string_vector.size(), 4); + EXPECT(test_string_vector.at(0) == String("```")); + EXPECT(test_string_vector.at(1) == String("Hello there")); + EXPECT(test_string_vector.at(2) == String("Hello there")); + EXPECT(test_string_vector.at(3) == String("```")); +} + TEST_MAIN(StringView) |