-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now uses string_view, supports a max split count, and has unit tests.
- Loading branch information
Showing
5 changed files
with
81 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN | ||
#include "doctest.h" | ||
|
||
#include "linfunc.h" | ||
|
||
|
||
TEST_CASE("Empty string") { | ||
const std::string text = ""; | ||
const std::list<std::string_view> result = tokenize(text, ','); | ||
CHECK(result.size() == 1); | ||
CHECK(result.front() == text); | ||
} | ||
|
||
TEST_CASE("No delimiter") { | ||
const std::string text = "textwithoutdelimiter"; | ||
const std::list<std::string_view> result = tokenize(text, ','); | ||
CHECK(result.size() == 1); | ||
CHECK(result.front() == text); | ||
} | ||
|
||
TEST_CASE("One or more delimiters") { | ||
const std::string text = "apple,banana,cherry"; | ||
|
||
SUBCASE("Zero") { | ||
const std::list<std::string_view> result = tokenize(text, ',', 0); | ||
const std::list<std::string_view> expected {"apple,banana,cherry"}; | ||
CHECK(result.size() == expected.size()); | ||
CHECK(result == expected); | ||
} | ||
|
||
SUBCASE("One split") { | ||
const std::list<std::string_view> result = tokenize(text, ',', 1); | ||
const std::list<std::string_view> expected {"apple", "banana,cherry"}; | ||
CHECK(result.size() == expected.size()); | ||
CHECK(result == expected); | ||
} | ||
|
||
SUBCASE("Two splits") { | ||
const std::list<std::string_view> result = tokenize(text, ',', 2); | ||
const std::list<std::string_view> expected {"apple", "banana", "cherry"}; | ||
CHECK(result.size() == expected.size()); | ||
CHECK(result == expected); | ||
} | ||
|
||
SUBCASE("Unlimited") { | ||
const std::list<std::string_view> result = tokenize(text, ','); | ||
const std::list<std::string_view> expected {"apple", "banana", "cherry"}; | ||
CHECK(result.size() == expected.size()); | ||
CHECK(result == expected); | ||
} | ||
} |