-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword_set_gtest.cc
127 lines (111 loc) · 3.08 KB
/
word_set_gtest.cc
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* -*- mode: C++; c-basic-offset: 4; tab-width: 8; -*-
* vi: set shiftwidth=4 tabstop=8:
* :indentSize=4:tabSize=8:
*/
#include "gtest/gtest.h"
#include "word_set.h"
TEST(word_set, empty_set_returns_nothing)
{
std::string err, word;
clear_word_set();
auto s = complete_word_set(word, err);
ASSERT_EQ(0u, s.size());
word = "something";
s = complete_word_set(word, err);
ASSERT_EQ(0u, s.size());
}
TEST(word_set, empty_string_completes_everything)
{
std::string err, word;
clear_word_set();
add_to_word_set(" something everything ");
auto s = complete_word_set(word, err);
ASSERT_EQ(2u, s.size());
auto it = s.begin();
ASSERT_EQ(std::string("everything"), *it);
++it;
ASSERT_EQ(std::string("something"), *it);
++it;
ASSERT_EQ(s.end(), it);
}
TEST(word_set, parsing_works)
{
std::string err, word;
clear_word_set();
add_to_word_set("a");
auto s = complete_word_set(word, err);
ASSERT_EQ(1u, s.size());
ASSERT_EQ(std::string("a"), word);
clear_word_set();
add_to_word_set(" a");
word.clear();
s = complete_word_set(word, err);
ASSERT_EQ(1u, s.size());
ASSERT_EQ(std::string("a"), word);
clear_word_set();
add_to_word_set("a ");
word.clear();
s = complete_word_set(word, err);
ASSERT_EQ(1u, s.size());
ASSERT_EQ(std::string("a"), word);
clear_word_set();
add_to_word_set(" a ");
word.clear();
s = complete_word_set(word, err);
ASSERT_EQ(1u, s.size());
ASSERT_EQ(std::string("a"), word);
clear_word_set();
add_to_word_set("a b");
word.clear();
s = complete_word_set(word, err);
ASSERT_EQ(2u, s.size());
ASSERT_TRUE(word.empty());
clear_word_set();
add_to_word_set(" a b");
word.clear();
s = complete_word_set(word, err);
ASSERT_EQ(2u, s.size());
ASSERT_TRUE(word.empty());
clear_word_set();
add_to_word_set("a b ");
word.clear();
s = complete_word_set(word, err);
ASSERT_EQ(2u, s.size());
ASSERT_TRUE(word.empty());
clear_word_set();
add_to_word_set(" a) _b ");
word.clear();
s = complete_word_set(word, err);
ASSERT_EQ(2u, s.size());
ASSERT_TRUE(word.empty());
}
TEST(word_set, completition_works)
{
std::string err, word;
clear_word_set();
add_to_word_set("dirk oliver jagdmann");
word = "di";
auto s = complete_word_set(word, err);
ASSERT_EQ(1u, s.size());
ASSERT_EQ(std::string("dirk"), *(s.begin()));
ASSERT_EQ(std::string("dirk"), word);
word = "oli";
s = complete_word_set(word, err);
ASSERT_EQ(1u, s.size());
ASSERT_EQ(std::string("oliver"), *(s.begin()));
ASSERT_EQ(std::string("oliver"), word);
word = "Jagd";
s = complete_word_set(word, err);
ASSERT_EQ(0u, s.size());
ASSERT_EQ(std::string("Jagd"), word);
}
TEST(word_set, sets_longest_matching_prefix)
{
std::string err, word;
clear_word_set();
add_to_word_set("aaaaa aaab aaaZZ not match aaaaaahg");
word = "a";
auto s = complete_word_set(word, err);
ASSERT_EQ(4u, s.size());
ASSERT_EQ(std::string("aaa"), word);
}