aboutsummaryrefslogtreecommitdiffstats
path: root/tests/next_word.cc
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-21 13:53:10 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-21 13:53:10 +0100
commitca90e97a9da4457790262c53515cb5ab58a2ce4f (patch)
treea8e184fe9d6af5731c6462ab56a390c4e08274f6 /tests/next_word.cc
parent243d958df14b85788232aca623b83826115a5eb9 (diff)
downloadnihil-ca90e97a9da4457790262c53515cb5ab58a2ce4f.tar.gz
nihil-ca90e97a9da4457790262c53515cb5ab58a2ce4f.tar.bz2
add command_map, skipws, next_word
Diffstat (limited to 'tests/next_word.cc')
-rw-r--r--tests/next_word.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/next_word.cc b/tests/next_word.cc
new file mode 100644
index 0000000..4055485
--- /dev/null
+++ b/tests/next_word.cc
@@ -0,0 +1,65 @@
+/*
+ * This source code is released into the public domain.
+ */
+
+#include <locale>
+#include <string>
+
+#include <catch2/catch_test_macros.hpp>
+
+import nihil;
+
+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");
+}