aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.core/next_word.test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'nihil.core/next_word.test.cc')
-rw-r--r--nihil.core/next_word.test.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/nihil.core/next_word.test.cc b/nihil.core/next_word.test.cc
new file mode 100644
index 0000000..2566ea6
--- /dev/null
+++ b/nihil.core/next_word.test.cc
@@ -0,0 +1,65 @@
+// This source code is released into the public domain.
+
+#include <catch2/catch_test_macros.hpp>
+
+import nihil.std;
+import nihil.core;
+
+namespace {
+
+TEST_CASE("next_word: basic", "[next_word]")
+{
+ using namespace std::literals;
+ auto s = "foo bar baz"sv;
+
+ auto words = nihil::next_word(s);
+ REQUIRE(words.first == "foo");
+ REQUIRE(words.second == " bar baz");
+
+ auto word = nihil::next_word(&s);
+ REQUIRE(word == "foo");
+ REQUIRE(s == " bar baz");
+}
+
+TEST_CASE("next_word: multiple spaces", "[next_word]")
+{
+ using namespace std::literals;
+ auto s = "foo bar baz"sv;
+
+ auto words = nihil::next_word(s);
+ REQUIRE(words.first == "foo");
+ REQUIRE(words.second == " bar baz");
+
+ auto word = nihil::next_word(&s);
+ REQUIRE(word == "foo");
+ REQUIRE(s == " bar baz");
+}
+
+TEST_CASE("next_word: leading spaces", "[next_word]")
+{
+ using namespace std::literals;
+ auto s = " \tfoo bar baz"sv;
+
+ auto words = nihil::next_word(s);
+ REQUIRE(words.first == "foo");
+ REQUIRE(words.second == " bar baz");
+
+ auto word = nihil::next_word(&s);
+ REQUIRE(word == "foo");
+ REQUIRE(s == " bar baz");
+}
+
+TEST_CASE("next_word: locale", "[next_word]")
+{
+ using namespace std::literals;
+ auto s = L"\u2003foo\u2003bar\u2003baz"sv;
+
+ auto words = nihil::next_word(s);
+ REQUIRE(words.first == s);
+
+ words = nihil::next_word(s, std::locale("C.UTF-8"));
+ REQUIRE(words.first == L"foo");
+ REQUIRE(words.second == L"\u2003bar\u2003baz");
+}
+
+} // anonymous namespace