1 #include <muleunit/test.h>
2 #include <common/StringFunctions.h>
4 #include <wx/filename.h>
6 using namespace muleunit
;
8 DECLARE_SIMPLE(StringFunctions
)
11 ///////////////////////////////////////////////////////////
12 // Tests for the JoinPaths function
14 TEST(StringFunctions
, JoinPaths
)
16 const wxString seps
= wxFileName::GetPathSeparators();
17 const wxString sep
= wxFileName::GetPathSeparator();
19 for (size_t i
= 0; i
< seps
.Length(); ++i
) {
20 const wxString cur_sep
= seps
.Mid(i
, 1);
22 ASSERT_EQUALS(wxT("a") + sep
+ wxT("b"), JoinPaths(wxT("a"), wxT("b")));
23 ASSERT_EQUALS(wxT("a") + sep
+ wxT("b"), JoinPaths(wxT("a") + cur_sep
, wxT("b")));
24 ASSERT_EQUALS(wxT("a") + sep
+ wxT("b"), JoinPaths(wxT("a"), cur_sep
+ wxT("b")));
25 ASSERT_EQUALS(wxT("a") + sep
+ wxT("b"), JoinPaths(wxT("a") + cur_sep
, cur_sep
+ wxT("b")));
26 ASSERT_EQUALS(wxT("a"), JoinPaths(wxT("a"), wxEmptyString
));
27 ASSERT_EQUALS(wxT("b"), JoinPaths(wxEmptyString
, wxT("b")));
28 ASSERT_EQUALS(wxEmptyString
, JoinPaths(wxEmptyString
, wxEmptyString
));
33 ///////////////////////////////////////////////////////////
34 // Tests for the FuzzyStrCmp function
36 //! Returns the number of items in an array.
37 #define itemsof(x) (sizeof(x)/sizeof(x[0]))
39 TEST(StringFunctions
, FuzzyStrCmp
)
47 FuzzyTest checks
[] = {
48 { wxT("a (10)"), wxT("a (2)"), 1},
49 { wxT("a (10)"), wxT("b (2)"), -1},
50 { wxT("c3 (7)"), wxT("c3 (12)"), -1},
51 { wxT("c3 (12)"), wxT("c3 (7)"), 1},
52 { wxT("c3 12d"), wxT("c3 12d"), 0},
53 { wxT("a (10) "), wxT("a (2) "), 1},
54 { wxT("a (10) "), wxT("b (2) "), -1},
55 { wxT(" c3 (7)"), wxT(" c3 (12)"), -1},
56 { wxT(" c3 (12)"), wxT(" c3 (7)"), 1},
57 { wxT("c3 12d"), wxT("c3 12d"), 0},
58 { wxT(""), wxT(""), 0},
59 { wxT(""), wxT("c3 12d"), -1},
60 { wxT("c3 12d"), wxT(""), 1},
61 { wxT(" "), wxT("c3 12d"), -1},
62 { wxT("c3 12d"), wxT(" "), 1},
63 { wxT("17.10"), wxT("17.2"), 1},
64 { wxT(" c3 (a)"), wxT(" c3 (12)"), 1},
65 { wxT(" c3 (12)"), wxT(" c3 (a)"), -1},
68 for (size_t i
= 0; i
< itemsof(checks
); ++i
) {
69 wxString a
= checks
[i
].a
;
70 wxString b
= checks
[i
].b
;
72 ASSERT_EQUALS(checks
[i
].expected
, FuzzyStrCmp(a
, b
));
77 ///////////////////////////////////////////////////////////
78 // Tests for the CSimpleParser class
80 DECLARE_SIMPLE(SimpleParser
)
83 TEST(SimpleParser
, Constructor
)
85 // Empty strings are acceptable and should just return an empty string
87 CSimpleTokenizer
tkz1(wxEmptyString
, wxT('-'));
88 ASSERT_EQUALS(wxT(""), tkz1
.remaining());
89 ASSERT_EQUALS(wxEmptyString
, tkz1
.next());
90 ASSERT_EQUALS(wxT(""), tkz1
.remaining());
91 ASSERT_EQUALS(wxEmptyString
, tkz1
.next());
94 // String with no tokens should be return immediatly
96 CSimpleTokenizer
tkz2(wxT(" abc "), wxT('-'));
97 ASSERT_EQUALS(wxT(" abc "), tkz2
.remaining());
98 ASSERT_EQUALS(wxT(" abc "), tkz2
.next());
99 ASSERT_EQUALS(wxEmptyString
, tkz2
.next());
100 ASSERT_EQUALS(wxEmptyString
, tkz2
.next());
105 TEST(SimpleParser
, EmptyTokens
)
108 CSimpleTokenizer
tkz1(wxT(" a"), wxT(' '));
109 ASSERT_EQUALS(wxT(" a"), tkz1
.remaining());
110 ASSERT_EQUALS(0u, tkz1
.tokenCount());
112 ASSERT_EQUALS(wxEmptyString
, tkz1
.next());
113 ASSERT_EQUALS(wxT("a"), tkz1
.remaining());
114 ASSERT_EQUALS(1u, tkz1
.tokenCount());
116 ASSERT_EQUALS(wxT("a"), tkz1
.next());
117 ASSERT_EQUALS(wxT(""), tkz1
.remaining());
118 ASSERT_EQUALS(1u, tkz1
.tokenCount());
120 ASSERT_EQUALS(wxEmptyString
, tkz1
.next());
121 ASSERT_EQUALS(wxT(""), tkz1
.remaining());
122 ASSERT_EQUALS(1u, tkz1
.tokenCount());
126 CSimpleTokenizer
tkz2(wxT("c "), wxT(' '));
127 ASSERT_EQUALS(wxT("c "), tkz2
.remaining());
128 ASSERT_EQUALS(0u, tkz2
.tokenCount());
130 ASSERT_EQUALS(wxT("c"), tkz2
.next());
131 ASSERT_EQUALS(wxT(""), tkz2
.remaining());
132 ASSERT_EQUALS(1u, tkz2
.tokenCount());
134 ASSERT_EQUALS(wxEmptyString
, tkz2
.next());
135 ASSERT_EQUALS(wxT(""), tkz2
.remaining());
136 ASSERT_EQUALS(1u, tkz2
.tokenCount());
138 ASSERT_EQUALS(wxEmptyString
, tkz2
.next());
139 ASSERT_EQUALS(wxT(""), tkz2
.remaining());
140 ASSERT_EQUALS(1u, tkz2
.tokenCount());
144 CSimpleTokenizer
tkz3(wxT(" a c "), wxT(' '));
145 ASSERT_EQUALS(wxT(" a c "), tkz3
.remaining());
146 ASSERT_EQUALS(0u, tkz3
.tokenCount());
148 ASSERT_EQUALS(wxEmptyString
, tkz3
.next());
149 ASSERT_EQUALS(wxT("a c "), tkz3
.remaining());
150 ASSERT_EQUALS(1u, tkz3
.tokenCount());
152 ASSERT_EQUALS(wxT("a"), tkz3
.next());
153 ASSERT_EQUALS(wxT("c "), tkz3
.remaining());
154 ASSERT_EQUALS(2u, tkz3
.tokenCount());
156 ASSERT_EQUALS(wxT("c"), tkz3
.next());
157 ASSERT_EQUALS(wxT(""), tkz3
.remaining());
158 ASSERT_EQUALS(3u, tkz3
.tokenCount());
160 ASSERT_EQUALS(wxEmptyString
, tkz3
.next());
161 ASSERT_EQUALS(wxT(""), tkz3
.remaining());
162 ASSERT_EQUALS(3u, tkz3
.tokenCount());
164 ASSERT_EQUALS(wxEmptyString
, tkz3
.next());
165 ASSERT_EQUALS(wxT(""), tkz3
.remaining());
166 ASSERT_EQUALS(3u, tkz3
.tokenCount());
171 TEST(SimpleParser
, NormalTokens
)
173 CSimpleTokenizer
tkz(wxT("a c"), wxT(' '));
174 ASSERT_EQUALS(wxT("a c"), tkz
.remaining());
175 ASSERT_EQUALS(0u, tkz
.tokenCount());
177 ASSERT_EQUALS(wxT("a"), tkz
.next());
178 ASSERT_EQUALS(wxT("c"), tkz
.remaining());
179 ASSERT_EQUALS(1u, tkz
.tokenCount());
181 ASSERT_EQUALS(wxT("c"), tkz
.next());
182 ASSERT_EQUALS(wxT(""), tkz
.remaining());
183 ASSERT_EQUALS(1u, tkz
.tokenCount());
185 ASSERT_EQUALS(wxEmptyString
, tkz
.next());
186 ASSERT_EQUALS(wxT(""), tkz
.remaining());
187 ASSERT_EQUALS(1u, tkz
.tokenCount());
189 ASSERT_EQUALS(wxEmptyString
, tkz
.next());
190 ASSERT_EQUALS(wxT(""), tkz
.remaining());
191 ASSERT_EQUALS(1u, tkz
.tokenCount());