aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.core/next_word.test.cc
blob: 2566ea63885d44f855c6870417d70bb8d18a9c5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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