GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/stringutils.cc Lines: 1194 1194 100.0 %
Date: 2018-12-09 Branches: 4078 10600 38.5 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2018  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "unittests/unittests.h"
22
23
#include "configuration.h"
24
25
#include "const/utils/utf8.h"
26
27
#include "fs/virtfs/fs.h"
28
29
#include "utils/dtor.h"
30
31
#include "utils/translation/translationmanager.h"
32
33
#include "resources/iteminfo.h"
34
35
#include "resources/db/itemdb.h"
36
37
#include "resources/resourcemanager/resourcemanager.h"
38
39
#include "debug.h"
40
41
3
TEST_CASE("stringuntils  trim 1", "")
42
{
43
4
    std::string str = "str";
44




4
    REQUIRE("str" == trim(str));
45
46
    str = " str";
47




4
    REQUIRE("str" == trim(str));
48




4
    REQUIRE("str" == trim(str));
49
50
    str = " str   this IS Long Стринг "
51
        "[email protected]#$%^&*()_+`-=[]\\{}|;':\",./<>?   ";
52




4
    REQUIRE("str   this IS Long Стринг [email protected]#$%^&*()_+`-=[]\\{}|;':\",./<>?" ==
53
        trim(str));
54
55
    str = "";
56




4
    REQUIRE(trim(str).empty());
57
1
}
58
59
3
TEST_CASE("stringuntils toLower 1", "")
60
{
61
4
    std::string str = "str";
62




4
    REQUIRE("str" == toLower(str));
63
64
    str = " StR";
65




4
    REQUIRE(" str" == toLower(str));
66
67
    str = " str   this IS Long  "
68
        "[email protected]#$%^&*()_+`-=[]\\{}|;':\",./<>?   ";
69
70




4
    REQUIRE(" str   this is long  [email protected]#$%^&*()_+`-=[]\\{}|;':\",./<>?   " ==
71
        toLower(str));
72
73
    str = "";
74




4
    REQUIRE(toLower(str).empty());
75
1
}
76
77
3
TEST_CASE("stringuntils toUpper 1", "")
78
{
79
4
    std::string str = "str";
80




4
    REQUIRE("STR" == toUpper(str));
81
82
    str = " StR";
83




4
    REQUIRE(" STR" == toUpper(str));
84
85
    str = " str   this IS Long  "
86
        "[email protected]#$%^&*()_+`-=[]\\{}|;':,./<>?   ";
87
88




4
    REQUIRE(" STR   THIS IS LONG  [email protected]#$%^&*()_+`-=[]\\{}|;':,./<>?   " ==
89
        toUpper(str));
90
91
    str = "";
92




4
    REQUIRE(toUpper(str).empty());
93
1
}
94
95
3
TEST_CASE("stringuntils atox 1", "")
96
{
97
4
    std::string str = "0x10";
98




4
    REQUIRE(16 == atox(str));
99
100
    str = "0x0";
101




4
    REQUIRE(0 == atox(str));
102
103
    str = "0x1";
104




4
    REQUIRE(1 == atox(str));
105
106
    str = "0x0x0x0x0x0x0x0";
107




4
    REQUIRE(0 == atox(str));
108
109
1
    str = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
110
1
    const int k = atox(str);
111
1
    printf("%d\n", k);  // for avoid warning
112
113
    str = "";
114




4
    REQUIRE(0 == atox(str));
115
116
    str = "0";
117




4
    REQUIRE(0 == atox(str));
118
119
    str = "0x";
120




4
    REQUIRE(0 == atox(str));
121
122
    str = "zzz";
123




4
    REQUIRE(0 == atox(str));
124
1
}
125
126
3
TEST_CASE("stringuntils ipToString 1", "")
127
{
128




7
    REQUIRE("0.0.0.0" == std::string(ipToString(0)));
129




7
    REQUIRE("219.255.210.73" == std::string(ipToString(1238564827)));
130
1
}
131
132
3
TEST_CASE("stringuntils toString 1", "")
133
{
134




6
    REQUIRE(strprintf("%d", 0) == toString(0));
135




6
    REQUIRE(strprintf("%d", -1) == toString(-1));
136




6
    REQUIRE(strprintf("%d", 30000000) == toString(30000000));
137




6
    REQUIRE(strprintf("%d", -10000000) == toString(-10000000));
138




6
    REQUIRE(strprintf("%d", 30000000) == toString(
139
        static_cast<signed int>(30000000)));
140




6
    REQUIRE(strprintf("%d", 3000) == toString(CAST_U16(3000)));
141




6
    REQUIRE(strprintf("%d", 123) == toString(CAST_U8(123)));
142




6
    REQUIRE(strprintf("%u", static_cast<uint32_t>(30000000)) == toString(
143
        static_cast<uint32_t>(30000000)));
144




6
    REQUIRE(strprintf("%f", 3.1F) == toString(3.1F));
145




6
    REQUIRE(strprintf("%f", 3.1) == toString(3.1));
146
1
}
147
148
3
TEST_CASE("stringuntils toStringPrint 1", "")
149
{
150



5
    REQUIRE(toStringPrint(0) == "0 0x0");
151



5
    REQUIRE(toStringPrint(10) == "10 0xa");
152



5
    REQUIRE(toStringPrint(255) == "255 0xff");
153
1
}
154
155
3
TEST_CASE("stringuntils parse2Int 1", "")
156
{
157
1
    int a = -1;
158
1
    int b = -1;
159
160




7
    REQUIRE(parse2Int("", a, b) == false);
161



4
    REQUIRE(a == -1);
162



4
    REQUIRE(b == -1);
163
164
1
    a = -1;
165
1
    b = -1;
166




7
    REQUIRE(parse2Int(",", a, b) == false);
167



4
    REQUIRE(a == -1);
168



4
    REQUIRE(b == -1);
169
170
1
    a = -1;
171
1
    b = -1;
172




7
    REQUIRE(parse2Int("10,20", a, b) == true);
173



4
    REQUIRE(a == 10);
174



4
    REQUIRE(b == 20);
175
176
1
    a = -1;
177
1
    b = -1;
178




7
    REQUIRE(parse2Int("10 20", a, b) == true);
179



4
    REQUIRE(a == 10);
180



4
    REQUIRE(b == 20);
181
182
1
    a = -1;
183
1
    b = -1;
184




7
    REQUIRE(parse2Int("10 z20", a, b) == true);
185



4
    REQUIRE(a == 10);
186



4
    REQUIRE(b == 0);
187
1
}
188
189
3
TEST_CASE("stringuntils parse2Str 1", "")
190
{
191
4
    std::string str1 = "-";
192
4
    std::string str2 = "-";
193
194




7
    REQUIRE(parse2Str("", str1, str2) == false);
195



4
    REQUIRE(str1 == "-");
196



4
    REQUIRE(str2 == "-");
197
198




7
    REQUIRE(parse2Str(",", str1, str2) == false);
199



4
    REQUIRE(str1 == "-");
200



4
    REQUIRE(str2 == "-");
201
202
1
    str1 = "-";
203
    str2 = "-";
204




7
    REQUIRE(parse2Str("test line", str1, str2) == true);
205



4
    REQUIRE(str1 == "test");
206



4
    REQUIRE(str2 == "line");
207
208
1
    str1 = "-";
209
    str2 = "-";
210




7
    REQUIRE(parse2Str("test,line", str1, str2) == true);
211



4
    REQUIRE(str1 == "test");
212



4
    REQUIRE(str2 == "line");
213
1
}
214
215
3
TEST_CASE("stringuntils parseNumber 1", "")
216
{
217




7
    REQUIRE(parseNumber("") == 0);
218




7
    REQUIRE(parseNumber("0x") == 0);
219




7
    REQUIRE(parseNumber("10") == 10);
220




7
    REQUIRE(parseNumber("h10") == 16);
221




7
    REQUIRE(parseNumber("x100") == 256);
222




7
    REQUIRE(parseNumber("0x20") == 32);
223
1
}
224
225
3
TEST_CASE("stringuntils removeToken 1", "")
226
{
227
1
    std::string str;
228
229




8
    REQUIRE(removeToken(str, " ").empty());
230



4
    REQUIRE(str.empty());
231
232
    str = "test";
233




8
    REQUIRE(removeToken(str, " ").empty());
234



4
    REQUIRE(str.empty());
235
236
    str = "test line";
237




8
    REQUIRE(removeToken(str, " ") == "line");
238



4
    REQUIRE(str == "line");
239
240
    str = "test,line";
241




8
    REQUIRE(removeToken(str, ",") == "line");
242



4
    REQUIRE(str == "line");
243
244
    str = "test line";
245




8
    REQUIRE(removeToken(str, ",").empty());
246



4
    REQUIRE(str.empty());
247
248
    str = ",line";
249




8
    REQUIRE(removeToken(str, ",").empty());
250



4
    REQUIRE(str.empty());
251
1
}
252
253
3
TEST_CASE("stringuntils strprintf 1", "")
254
{
255



5
    REQUIRE(strprintf("%s very long string. 123456789012345678901234567890"
256
        "+++++++++++++++++++++++++++++++++++++++"
257
        "________________________________"
258
        "***********************************"
259
        "----------------------------------------"
260
        "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| %s",
261
        "test", "end of test") ==
262
        "test very long string. 123456789012345678901234567890"
263
        "+++++++++++++++++++++++++++++++++++++++"
264
        "________________________________"
265
        "***********************************"
266
        "----------------------------------------"
267
        "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| "
268
        "end of test");
269
1
}
270
271
3
TEST_CASE("stringuntils toString 2", "")
272
{
273
81302
    for (int f = 0; f < 10000000; f += 123)
274
    {
275




487806
        REQUIRE(strprintf("%d", f) == toString(f));
276
    }
277
1
}
278
279
3
TEST_CASE("stringuntils removeColors 1", "")
280
{
281




8
    REQUIRE(removeColors("").empty());
282




8
    REQUIRE("#" == removeColors("#"));
283




8
    REQUIRE("##" == removeColors("##"));
284




8
    REQUIRE(removeColors("##1").empty());
285




8
    REQUIRE("2" == removeColors("##12"));
286




8
    REQUIRE("1##" == removeColors("1##"));
287




8
    REQUIRE("1" == removeColors("1##2"));
288




8
    REQUIRE("13" == removeColors("1##23"));
289




8
    REQUIRE("#1#2" == removeColors("#1#2"));
290




8
    REQUIRE("#1" == removeColors("#1##2"));
291
1
}
292
293
3
TEST_CASE("stringuntils compareStrI 1", "")
294
{
295
2
    std::string str1;
296
1
    std::string str2;
297




4
    REQUIRE(0 == compareStrI(str1, str2));
298
299
1
    str1 = "test";
300
    str2 = "test";
301




4
    REQUIRE(0 == compareStrI(str1, str2));
302
303
1
    str1 = "test";
304
    str2 = "test1";
305




4
    REQUIRE(0 > compareStrI(str1, str2));
306
307
1
    str1 = "test";
308
    str2 = "aest1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
309




4
    REQUIRE(0 < compareStrI(str1, str2));
310
311
1
    str1 = "testaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
312
    str2 = "testaa";
313




4
    REQUIRE(0 < compareStrI(str1, str2));
314
1
}
315
316
3
TEST_CASE("stringuntils isWordSeparator 1", "")
317
{
318



3
    REQUIRE(isWordSeparator(' '));
319



3
    REQUIRE(isWordSeparator(','));
320



3
    REQUIRE(isWordSeparator('.'));
321



3
    REQUIRE(isWordSeparator('\"'));
322



3
    REQUIRE(!isWordSeparator(0));
323



3
    REQUIRE(!isWordSeparator('a'));
324



3
    REQUIRE(!isWordSeparator('-'));
325
1
}
326
327
3
TEST_CASE("stringuntils findSameSubstring", "")
328
{
329
2
    std::string str1;
330
1
    std::string str2;
331
332





11
    REQUIRE(findSameSubstring("", "").empty());
333
334
1
    str1 = "test line";
335
    str2 = "test line";
336




5
    REQUIRE("test line" == findSameSubstring(str1, str2));
337
338
1
    str1 = "test li";
339
    str2 = "test line";
340




5
    REQUIRE("test li" == findSameSubstring(str1, str2));
341
342
1
    str1 = "test li";
343
    str2 = "est li";
344




5
    REQUIRE(findSameSubstring(str1, str2).empty());
345
1
}
346
347
3
TEST_CASE("stringuntils findSameSubstringI", "")
348
{
349
2
    std::string str1;
350
1
    std::string str2;
351
352





11
    REQUIRE(findSameSubstringI("", "").empty());
353
354
1
    str1 = "tEst line";
355
    str2 = "tesT line";
356




5
    REQUIRE("tEst line" == findSameSubstringI(str1, str2));
357
358
1
    str1 = "test Li";
359
    str2 = "test lINe";
360




5
    REQUIRE("test Li" == findSameSubstringI(str1, str2));
361
362
1
    str1 = "test lINe";
363
    str2 = "test Li";
364




5
    REQUIRE("test lI" == findSameSubstringI(str1, str2));
365
366
1
    str1 = "teSt li";
367
    str2 = "est li";
368




5
    REQUIRE(findSameSubstringI(str1, str2).empty());
369
1
}
370
371
3
TEST_CASE("stringuntils findI 1", "")
372
{
373




10
    REQUIRE(0 == findI("", ""));
374




10
    REQUIRE(std::string::npos == findI("test", "line"));
375




10
    REQUIRE(0 == findI("test line", "t"));
376




10
    REQUIRE(0 == findI("test line", "te"));
377




10
    REQUIRE(3 == findI("test line", "t l"));
378
1
}
379
380
3
TEST_CASE("stringuntils findI 2", "")
381
{
382
2
    STD_VECTOR <std::string> vect1;
383
5
    vect1.push_back("test");
384
5
    vect1.push_back("line");
385
5
    vect1.push_back("qwe");
386
387




7
    REQUIRE(std::string::npos == findI("", vect1));
388




7
    REQUIRE(0 == findI("test", vect1));
389




7
    REQUIRE(0 == findI("tesT lIne", vect1));
390




7
    REQUIRE(5 == findI("teoT line", vect1));
391




7
    REQUIRE(std::string::npos == findI("zzz", vect1));
392
1
}
393
394
3
TEST_CASE("stringuntils encodeStr 1", "")
395
{
396
2
    std::string str = encodeStr(10, 1);
397




4
    REQUIRE(10 == decodeStr(str));
398
399
    str.clear();
400




4
    REQUIRE(0 == decodeStr(str));
401
402
3
    str = encodeStr(10, 2);
403




4
    REQUIRE(10 == decodeStr(str));
404
405
3
    str = encodeStr(100, 3);
406




4
    REQUIRE(100 == decodeStr(str));
407
408
3
    str = encodeStr(1000, 4);
409




4
    REQUIRE(1000 == decodeStr(str));
410
1
}
411
412
3
TEST_CASE("stringuntils extractNameFromSprite 1", "")
413
{
414




8
    REQUIRE(extractNameFromSprite("").empty());
415




8
    REQUIRE("test" == extractNameFromSprite("test"));
416




8
    REQUIRE("test" == extractNameFromSprite("test.qwe"));
417




8
    REQUIRE("line" == extractNameFromSprite("test/line.zzz"));
418




8
    REQUIRE("line" == extractNameFromSprite("test\\line.zzz"));
419




8
    REQUIRE("line" == extractNameFromSprite("test/test2\\line.zzz"));
420




8
    REQUIRE("line" == extractNameFromSprite("test\\test2/line.zzz"));
421
1
}
422
423
3
TEST_CASE("stringuntils removeSpriteIndex 1", "")
424
{
425




8
    REQUIRE(removeSpriteIndex("").empty());
426




8
    REQUIRE("test" == removeSpriteIndex("test"));
427




8
    REQUIRE("test" == removeSpriteIndex("test[1]"));
428




8
    REQUIRE("line" == removeSpriteIndex("test/line[12]"));
429




8
    REQUIRE("line" == removeSpriteIndex("test\\line[12]"));
430




8
    REQUIRE("line" == removeSpriteIndex("test/test2\\line[12]"));
431




8
    REQUIRE("line" == removeSpriteIndex("test\\test2/line[1]"));
432
1
}
433
434
3
TEST_CASE("stringutils getSafeUtf8String 1", "")
435
{
436
    const char *str;
437
4
    str = getSafeUtf8String("");
438



4
    REQUIRE(str != nullptr);
439



4
    REQUIRE(strcmp("", str) == 0);
440



4
    REQUIRE(str[0] == '\0');
441



4
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
442
1
    delete [] str;
443
444
4
    str = getSafeUtf8String("test line");
445



4
    REQUIRE(str != nullptr);
446



4
    REQUIRE(strcmp("test line", str) == 0);
447



4
    REQUIRE(str[strlen("test line")] == '\0');
448



4
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
449
1
    delete [] str;
450
451
4
    str = getSafeUtf8String("1");
452



4
    REQUIRE(str != nullptr);
453



4
    REQUIRE(strcmp("1", str) == 0);
454



4
    REQUIRE(str[1] == '\0');
455



4
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
456
1
    delete [] str;
457
1
}
458
459
3
TEST_CASE("stringutils getSafeUtf8String 2", "")
460
{
461
    char *str;
462
463
4
    getSafeUtf8String("test", nullptr);
464
465
1
    str = new char[65535];
466
4
    getSafeUtf8String("", str);
467



4
    REQUIRE(str != nullptr);
468



4
    REQUIRE(strcmp("", str) == 0);
469



4
    REQUIRE(str[0] == '\0');
470



4
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
471
1
    delete [] str;
472
473
1
    str = new char[65535];
474
4
    getSafeUtf8String("test line", str);
475



4
    REQUIRE(str != nullptr);
476



4
    REQUIRE(strcmp("test line", str) == 0);
477



4
    REQUIRE(str[strlen("test line")] == '\0');
478



4
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
479
1
    delete [] str;
480
481
1
    str = new char[65535];
482
4
    getSafeUtf8String("1", str);
483



4
    REQUIRE(str != nullptr);
484



4
    REQUIRE(strcmp("1", str) == 0);
485



4
    REQUIRE(str[1] == '\0');
486



4
    REQUIRE(str[UTF8_MAX_SIZE - 1] == '\0');
487
1
    delete [] str;
488
489
1
    str = new char[65535];
490
1
    char *data1 = new char[65510];
491
1
    memset(data1, 'a', 65510);
492
1
    data1[65509] = '\0';
493
1
    char *data2 = new char[65510];
494
1
    memset(data2, 'a', 65500);
495
1
    data2[65500] = '\0';
496
4
    getSafeUtf8String(data1, str);
497



4
    REQUIRE(str != nullptr);
498



4
    REQUIRE(strcmp(data2, str) == 0);
499



4
    REQUIRE(str[65500] == '\0');
500
1
    delete [] data1;
501
1
    delete [] data2;
502
1
    delete [] str;
503
1
}
504
505
3
TEST_CASE("stringuntils getFileName 1", "")
506
{
507




8
    REQUIRE(getFileName("").empty());
508




8
    REQUIRE("file" == getFileName("file"));
509




8
    REQUIRE("file" == getFileName("test/file1\\file"));
510




8
    REQUIRE("file" == getFileName("test\\file1/file"));
511




8
    REQUIRE(getFileName("file/").empty());
512




8
    REQUIRE("file" == getFileName("/file"));
513
1
}
514
515
3
TEST_CASE("stringuntils getFileDir 1", "")
516
{
517




8
    REQUIRE(getFileDir("").empty());
518




8
    REQUIRE("file" == getFileDir("file"));
519




8
    REQUIRE("test/file1" == getFileDir("test/file1\\file"));
520




8
    REQUIRE("test\\file1" == getFileDir("test\\file1/file"));
521




8
    REQUIRE("file" == getFileDir("file/"));
522




8
    REQUIRE(getFileDir("/file").empty());
523
1
}
524
525
3
TEST_CASE("stringuntils replaceAll 1", "")
526
{
527
2
    std::string str1;
528
2
    std::string str2;
529
1
    std::string str3;
530
531




4
    REQUIRE(replaceAll(str1, str2, str3).empty());
532
533
1
    str1 = "this is test line";
534
1
    str2 = "";
535
    str3 = "";
536




4
    REQUIRE("this is test line" == replaceAll(str1, str2, str3));
537
538
1
    str1 = "this is test line";
539
1
    str2 = "is ";
540
    str3 = "";
541




4
    REQUIRE("thtest line" == replaceAll(str1, str2, str3));
542
543
1
    str1 = "this is test line";
544
1
    str2 = "";
545
    str3 = "1";
546




4
    REQUIRE("this is test line" == replaceAll(str1, str2, str3));
547
1
}
548
549
3
TEST_CASE("stringuntils replaceRecursiveAll 1", "")
550
{
551
2
    std::string str;
552
1
    str = "";
553

4
    replaceRecursiveAll(str, "line", '.');
554



4
    REQUIRE(str.empty());
555
1
    str = "test line";
556

4
    replaceRecursiveAll(str, "line", '.');
557



4
    REQUIRE(str == "test .");
558
1
    str = "11112222";
559

4
    replaceRecursiveAll(str, "11", '1');
560



4
    REQUIRE(str == "12222");
561
1
    str = "122221";
562

4
    replaceRecursiveAll(str, "11", '1');
563



4
    REQUIRE(str == "122221");
564
1
    str = "1222211";
565

4
    replaceRecursiveAll(str, "11", '1');
566



4
    REQUIRE(str == "122221");
567
1
    str = "11112222";
568

4
    replaceRecursiveAll(str, "112", '1');
569



4
    REQUIRE(str == "111222");
570
1
    str = "111122224";
571

4
    replaceRecursiveAll(str, "112", '1');
572



4
    REQUIRE(str == "1112224");
573
1
    str = "3111122224";
574

4
    replaceRecursiveAll(str, "112", '1');
575



4
    REQUIRE(str == "31112224");
576
1
    str = "121212";
577

4
    replaceRecursiveAll(str, "12", '1');
578



4
    REQUIRE(str == "111");
579
1
    str = "1121212";
580

4
    replaceRecursiveAll(str, "12", '1');
581



4
    REQUIRE(str == "1111");
582
1
    str = "11212122";
583

4
    replaceRecursiveAll(str, "12", '1');
584



4
    REQUIRE(str == "1111");
585
1
    str = "112121222";
586

4
    replaceRecursiveAll(str, "12", '1');
587



4
    REQUIRE(str == "1111");
588
1
    str = "112211221122";
589

4
    replaceRecursiveAll(str, "12", '1');
590



4
    REQUIRE(str == "111111");
591
1
}
592
593
3
TEST_CASE("stringuntils getBoolFromString 1", "")
594
{
595




6
    REQUIRE(getBoolFromString("true"));
596




6
    REQUIRE(getBoolFromString("yes"));
597




6
    REQUIRE(getBoolFromString("on"));
598




6
    REQUIRE(!getBoolFromString("false"));
599




6
    REQUIRE(!getBoolFromString("no"));
600




6
    REQUIRE(!getBoolFromString("off"));
601




6
    REQUIRE(getBoolFromString("1"));
602




6
    REQUIRE(!getBoolFromString("0"));
603




6
    REQUIRE(getBoolFromString("2"));
604
605




6
    REQUIRE(getBoolFromString(" true"));
606




6
    REQUIRE(getBoolFromString("yes "));
607




6
    REQUIRE(getBoolFromString(" on"));
608




6
    REQUIRE(!getBoolFromString("false "));
609




6
    REQUIRE(!getBoolFromString(" no"));
610




6
    REQUIRE(!getBoolFromString("off "));
611




6
    REQUIRE(getBoolFromString(" 1"));
612




6
    REQUIRE(!getBoolFromString("0 "));
613




6
    REQUIRE(getBoolFromString(" 2"));
614
615




6
    REQUIRE(getBoolFromString("tRue "));
616




6
    REQUIRE(getBoolFromString(" Yes"));
617




6
    REQUIRE(getBoolFromString("ON "));
618




6
    REQUIRE(!getBoolFromString(" fALse"));
619




6
    REQUIRE(!getBoolFromString("nO "));
620




6
    REQUIRE(!getBoolFromString(" oFF"));
621
1
}
622
623
3
TEST_CASE("stringuntils parseBoolean 1", "")
624
{
625




7
    REQUIRE(parseBoolean("true") == 1);
626




7
    REQUIRE(parseBoolean("yes") == 1);
627




7
    REQUIRE(parseBoolean("on") == 1);
628




7
    REQUIRE(parseBoolean("false") == 0);
629




7
    REQUIRE(parseBoolean("no") == 0);
630




7
    REQUIRE(parseBoolean("off") == 0);
631




7
    REQUIRE(parseBoolean("1") == 1);
632




7
    REQUIRE(parseBoolean("0") == 0);
633




7
    REQUIRE(parseBoolean("2") == -1);
634




7
    REQUIRE(parseBoolean("test") == -1);
635




7
    REQUIRE(parseBoolean("") == -1);
636
637




7
    REQUIRE(parseBoolean("true ") == 1);
638




7
    REQUIRE(parseBoolean(" yes") == 1);
639




7
    REQUIRE(parseBoolean("on ") == 1);
640




7
    REQUIRE(parseBoolean(" false") == 0);
641




7
    REQUIRE(parseBoolean("no ") == 0);
642




7
    REQUIRE(parseBoolean(" off") == 0);
643




7
    REQUIRE(parseBoolean("1 ") == 1);
644




7
    REQUIRE(parseBoolean(" 0") == 0);
645




7
    REQUIRE(parseBoolean("2 ") == -1);
646




7
    REQUIRE(parseBoolean(" test") == -1);
647




7
    REQUIRE(parseBoolean(" ") == -1);
648
649




7
    REQUIRE(parseBoolean(" tRue") == 1);
650




7
    REQUIRE(parseBoolean("Yes ") == 1);
651




7
    REQUIRE(parseBoolean(" ON") == 1);
652




7
    REQUIRE(parseBoolean("FaLse ") == 0);
653




7
    REQUIRE(parseBoolean(" nO") == 0);
654




7
    REQUIRE(parseBoolean("oFf ") == 0);
655




7
    REQUIRE(parseBoolean(" tEst") == -1);
656
1
}
657
658
3
TEST_CASE("stringuntils splitToIntSet 1", "")
659
{
660
2
    std::set<int> tokens;
661

4
    splitToIntSet(tokens, "", ',');
662



5
    REQUIRE(tokens.empty() == true);
663
664
1
    tokens.clear();
665

4
    splitToIntSet(tokens, "10z,aa,-1", ',');
666



5
    REQUIRE(tokens.size() == 3);
667



6
    REQUIRE(tokens.find(10) != tokens.end());
668



6
    REQUIRE(tokens.find(0) != tokens.end());
669



6
    REQUIRE(tokens.find(-1) != tokens.end());
670
671
1
    tokens.clear();
672

4
    splitToIntSet(tokens, "10,2,30", ',');
673



5
    REQUIRE(tokens.size() == 3);
674



6
    REQUIRE(tokens.find(10) != tokens.end());
675



6
    REQUIRE(tokens.find(2) != tokens.end());
676



6
    REQUIRE(tokens.find(30) != tokens.end());
677
678
1
    tokens.clear();
679

4
    splitToIntSet(tokens, "10,2,30,", ',');
680



5
    REQUIRE(tokens.size() == 3);
681



6
    REQUIRE(tokens.find(10) != tokens.end());
682



6
    REQUIRE(tokens.find(2) != tokens.end());
683



6
    REQUIRE(tokens.find(30) != tokens.end());
684
685
1
    tokens.clear();
686

4
    splitToIntSet(tokens, "10,2;30", ',');
687



5
    REQUIRE(tokens.size() == 2);
688



6
    REQUIRE(tokens.find(10) != tokens.end());
689



6
    REQUIRE(tokens.find(2) != tokens.end());
690
691
1
    tokens.clear();
692

4
    splitToIntSet(tokens, "10;20;30", ';');
693



5
    REQUIRE(tokens.size() == 3);
694



6
    REQUIRE(tokens.find(10) != tokens.end());
695



6
    REQUIRE(tokens.find(20) != tokens.end());
696



6
    REQUIRE(tokens.find(30) != tokens.end());
697
1
}
698
699
3
TEST_CASE("stringuntils splitToIntList 1", "")
700
{
701
2
    std::list<int> tokens;
702

6
    tokens = splitToIntList("", ',');
703



5
    REQUIRE(tokens.empty() == true);
704
705
1
    tokens.clear();
706

6
    tokens = splitToIntList("10z,a,-1", ',');
707



5
    REQUIRE(tokens.size() == 3);
708



5
    REQUIRE(tokens.front() == 10);
709
1
    tokens.pop_front();
710



5
    REQUIRE(tokens.front() == 0);
711
1
    tokens.pop_front();
712



5
    REQUIRE(tokens.front() == -1);
713
1
    tokens.pop_front();
714
715
1
    tokens.clear();
716

6
    tokens = splitToIntList("10,2,30", ',');
717



5
    REQUIRE(tokens.size() == 3);
718



5
    REQUIRE(tokens.front() == 10);
719
1
    tokens.pop_front();
720



5
    REQUIRE(tokens.front() == 2);
721
1
    tokens.pop_front();
722



5
    REQUIRE(tokens.front() == 30);
723
1
    tokens.pop_front();
724
725
1
    tokens.clear();
726

6
    tokens = splitToIntList("10,2,30,", ',');
727



5
    REQUIRE(tokens.size() == 3);
728



5
    REQUIRE(tokens.front() == 10);
729
1
    tokens.pop_front();
730



5
    REQUIRE(tokens.front() == 2);
731
1
    tokens.pop_front();
732



5
    REQUIRE(tokens.front() == 30);
733
1
    tokens.pop_front();
734
735
1
    tokens.clear();
736

6
    tokens = splitToIntList("10,2;30", ',');
737



5
    REQUIRE(tokens.size() == 2);
738



5
    REQUIRE(tokens.front() == 10);
739
1
    tokens.pop_front();
740



5
    REQUIRE(tokens.front() == 2);
741
1
    tokens.pop_front();
742
743
1
    tokens.clear();
744

6
    tokens = splitToIntList("10;20;30", ';');
745



5
    REQUIRE(tokens.size() == 3);
746



5
    REQUIRE(tokens.front() == 10);
747
1
    tokens.pop_front();
748



5
    REQUIRE(tokens.front() == 20);
749
1
    tokens.pop_front();
750



5
    REQUIRE(tokens.front() == 30);
751
1
    tokens.pop_front();
752
1
}
753
754
3
TEST_CASE("stringuntils splitToStringSet 1", "")
755
{
756
2
    std::set<std::string> tokens;
757

4
    splitToStringSet(tokens, "", ',');
758



5
    REQUIRE(tokens.empty() == true);
759
760
1
    tokens.clear();
761

4
    splitToStringSet(tokens, "10q,2w,30e", ',');
762



5
    REQUIRE(tokens.size() == 3);
763




9
    REQUIRE(tokens.find("10q") != tokens.end());
764




9
    REQUIRE(tokens.find("2w") != tokens.end());
765




9
    REQUIRE(tokens.find("30e") != tokens.end());
766
767
1
    tokens.clear();
768

4
    splitToStringSet(tokens, "10q,2w,30e,", ',');
769



5
    REQUIRE(tokens.size() == 3);
770




9
    REQUIRE(tokens.find("10q") != tokens.end());
771




9
    REQUIRE(tokens.find("2w") != tokens.end());
772




9
    REQUIRE(tokens.find("30e") != tokens.end());
773
774
1
    tokens.clear();
775

4
    splitToStringSet(tokens, "10q,,30e", ',');
776



5
    REQUIRE(tokens.size() == 2);
777




9
    REQUIRE(tokens.find("10q") != tokens.end());
778




9
    REQUIRE(tokens.find("30e") != tokens.end());
779
780
1
    tokens.clear();
781

4
    splitToStringSet(tokens, "10q,2w,30e,", ',');
782



5
    REQUIRE(tokens.size() == 3);
783




9
    REQUIRE(tokens.find("10q") != tokens.end());
784




9
    REQUIRE(tokens.find("2w") != tokens.end());
785




9
    REQUIRE(tokens.find("30e") != tokens.end());
786
787
1
    tokens.clear();
788

4
    splitToStringSet(tokens, "10w,2w;30e", ',');
789



5
    REQUIRE(tokens.size() == 2);
790




9
    REQUIRE(tokens.find("10w") != tokens.end());
791




9
    REQUIRE(tokens.find("2w;30e") != tokens.end());
792
793
1
    tokens.clear();
794

4
    splitToStringSet(tokens, "10q;20w;30e", ';');
795



5
    REQUIRE(tokens.size() == 3);
796




9
    REQUIRE(tokens.find("10q") != tokens.end());
797




9
    REQUIRE(tokens.find("20w") != tokens.end());
798




9
    REQUIRE(tokens.find("30e") != tokens.end());
799
1
}
800
801
3
TEST_CASE("stringuntils splitToIntVector 1", "")
802
{
803
2
    STD_VECTOR<int> tokens;
804

4
    splitToIntVector(tokens, "", ',');
805



5
    REQUIRE(tokens.empty() == true);
806
807
1
    tokens.clear();
808

4
    splitToIntVector(tokens, "10,2,30", ',');
809



5
    REQUIRE(tokens.size() == 3);
810



4
    REQUIRE(tokens[0] == 10);
811



5
    REQUIRE(tokens[1] == 2);
812



5
    REQUIRE(tokens[2] == 30);
813
814
1
    tokens.clear();
815

4
    splitToIntVector(tokens, "10,2a,z30", ',');
816



5
    REQUIRE(tokens.size() == 3);
817



4
    REQUIRE(tokens[0] == 10);
818



5
    REQUIRE(tokens[1] == 2);
819



5
    REQUIRE(tokens[2] == 0);
820
821
1
    tokens.clear();
822

4
    splitToIntVector(tokens, "10,2,30,", ',');
823



5
    REQUIRE(tokens.size() == 3);
824



4
    REQUIRE(tokens[0] == 10);
825



5
    REQUIRE(tokens[1] == 2);
826



5
    REQUIRE(tokens[2] == 30);
827
828
1
    tokens.clear();
829

4
    splitToIntVector(tokens, "10,,30", ',');
830



5
    REQUIRE(tokens.size() == 2);
831



4
    REQUIRE(tokens[0] == 10);
832



5
    REQUIRE(tokens[1] == 30);
833
834
1
    tokens.clear();
835

4
    splitToIntVector(tokens, "10,2;30", ',');
836



5
    REQUIRE(tokens.size() == 2);
837



4
    REQUIRE(tokens[0] == 10);
838



5
    REQUIRE(tokens[1] == 2);
839
840
1
    tokens.clear();
841

4
    splitToIntVector(tokens, "10;20;30", ';');
842



5
    REQUIRE(tokens.size() == 3);
843



4
    REQUIRE(tokens[0] == 10);
844



5
    REQUIRE(tokens[1] == 20);
845



5
    REQUIRE(tokens[2] == 30);
846
1
}
847
848
3
TEST_CASE("stringuntils splitToStringVector 1", "")
849
{
850
2
    STD_VECTOR<std::string> tokens;
851

4
    splitToStringVector(tokens, "", ',');
852



5
    REQUIRE(tokens.empty() == true);
853
854
1
    tokens.clear();
855

4
    splitToStringVector(tokens, "t,line,zz", ',');
856



5
    REQUIRE(tokens.size() == 3);
857



4
    REQUIRE(tokens[0] == "t");
858



5
    REQUIRE(tokens[1] == "line");
859



5
    REQUIRE(tokens[2] == "zz");
860
861
1
    tokens.clear();
862

4
    splitToStringVector(tokens, "t,line,zz,", ',');
863



5
    REQUIRE(tokens.size() == 3);
864



4
    REQUIRE(tokens[0] == "t");
865



5
    REQUIRE(tokens[1] == "line");
866



5
    REQUIRE(tokens[2] == "zz");
867
868
1
    tokens.clear();
869

4
    splitToStringVector(tokens, "t,,zz", ',');
870



5
    REQUIRE(tokens.size() == 2);
871



4
    REQUIRE(tokens[0] == "t");
872



5
    REQUIRE(tokens[1] == "zz");
873
874
1
    tokens.clear();
875

4
    splitToStringVector(tokens, "10,a2;30", ',');
876



5
    REQUIRE(tokens.size() == 2);
877



4
    REQUIRE(tokens[0] == "10");
878



5
    REQUIRE(tokens[1] == "a2;30");
879
880
1
    tokens.clear();
881

4
    splitToStringVector(tokens, "a10;b;3line", ';');
882



5
    REQUIRE(tokens.size() == 3);
883



4
    REQUIRE(tokens[0] == "a10");
884



5
    REQUIRE(tokens[1] == "b");
885



5
    REQUIRE(tokens[2] == "3line");
886
1
}
887
888
3
TEST_CASE("stringuntils replaceSpecialChars 1", "")
889
{
890
2
    std::string str;
891
892
1
    str = "";
893
1
    replaceSpecialChars(str);
894



4
    REQUIRE(str.empty());
895
896
1
    str = "test";
897
1
    replaceSpecialChars(str);
898



4
    REQUIRE("test" == str);
899
900
1
    str = "&";
901
1
    replaceSpecialChars(str);
902



4
    REQUIRE("&" == str);
903
904
1
    str = "&1";
905
1
    replaceSpecialChars(str);
906



4
    REQUIRE("&1" == str);
907
908
1
    str = "&33";
909
1
    replaceSpecialChars(str);
910



4
    REQUIRE("&33" == str);
911
912
1
    str = "&33;";
913
1
    replaceSpecialChars(str);
914



4
    REQUIRE("!" == str);
915
916
1
    str = "&33z;";
917
1
    replaceSpecialChars(str);
918



4
    REQUIRE("&33z;" == str);
919
920
1
    str = "1&33;";
921
1
    replaceSpecialChars(str);
922



4
    REQUIRE("1!" == str);
923
924
1
    str = "&33;2";
925
1
    replaceSpecialChars(str);
926



4
    REQUIRE("!2" == str);
927
928
1
    str = "&33;&";
929
1
    replaceSpecialChars(str);
930



4
    REQUIRE("!&" == str);
931
932
1
    str = "test line&33;";
933
1
    replaceSpecialChars(str);
934



4
    REQUIRE("test line!" == str);
935
1
}
936
937
3
TEST_CASE("stringuntils normalize 1", "")
938
{
939




8
    REQUIRE(normalize("").empty());
940




8
    REQUIRE(normalize("test") == "test");
941




8
    REQUIRE(normalize("Test") == "test");
942




8
    REQUIRE(normalize(" test line") == "test line");
943




8
    REQUIRE(normalize("test line ") == "test line");
944




8
    REQUIRE(normalize(" tEst line") == "test line");
945




8
    REQUIRE(normalize("test lIne ") == "test line");
946
1
}
947
948
3
TEST_CASE("stringuntils combineDye 1", "")
949
{
950




11
    REQUIRE(combineDye("", "").empty());
951




11
    REQUIRE("test" == combineDye("test", ""));
952




11
    REQUIRE("|line" == combineDye("", "line"));
953




11
    REQUIRE("test|line" == combineDye("test", "line"));
954




11
    REQUIRE("|line" == combineDye("|w", "line"));
955




11
    REQUIRE("aaa|line" == combineDye("aaa|w", "line"));
956




11
    REQUIRE("test|line" == combineDye("test|w", "line"));
957
1
}
958
959
3
TEST_CASE("stringuntils combineDye 2", "")
960
{
961




11
    REQUIRE(combineDye2("", "").empty());
962




11
    REQUIRE("test" == combineDye2("test", ""));
963




11
    REQUIRE("test" == combineDye2("test", "W"));
964




11
    REQUIRE(combineDye2("", "line").empty());
965




11
    REQUIRE("test.xml" == combineDye2("test.xml", "123"));
966




11
    REQUIRE("test.xml|#43413d,59544f,7a706c" ==
967
        combineDye2("test.xml|#43413d,59544f,7a706c", ""));
968




11
    REQUIRE("test.xml|#43413d,59544f,7a706c:W;" ==
969
        combineDye2("test.xml|#43413d,59544f,7a706c", "W"));
970




11
    REQUIRE("test.xml|#43413d,59544f,7a706c:W;#123456:B;" ==
971
        combineDye2("test.xml|#43413d,59544f,7a706c;#123456", "W;B"));
972
1
}
973
974
3
TEST_CASE("stringuntils combineDye 3", "")
975
{
976




11
    REQUIRE(combineDye3("", "").empty());
977




11
    REQUIRE("test" == combineDye3("test", ""));
978




11
    REQUIRE(combineDye3("", "line").empty());
979




11
    REQUIRE("test.xml|123" == combineDye3("test.xml", "123"));
980




11
    REQUIRE("test.xml|#43413d,59544f,7a706c" ==
981
        combineDye3("test.xml|#43413d,59544f,7a706c", ""));
982




11
    REQUIRE("test.xml|#43413d,59544f,7a706c:W;" ==
983
        combineDye3("test.xml|#43413d,59544f,7a706c", "W"));
984




11
    REQUIRE("test.xml|#43413d,59544f,7a706c:W;#123456:B;" ==
985
        combineDye3("test.xml|#43413d,59544f,7a706c;#123456", "W;B"));
986
1
}
987
988
3
TEST_CASE("stringuntils packList 1", "")
989
{
990
1
    std::list <std::string> list;
991




5
    REQUIRE(packList(list).empty());
992
993
2
    list.push_back(std::string());
994




5
    REQUIRE("|" == packList(list));
995
996
1
    list.clear();
997

4
    list.push_back("test");
998




5
    REQUIRE("test" == packList(list));
999
1000

4
    list.push_back("line");
1001




5
    REQUIRE("test|line" == packList(list));
1002
1003

4
    list.push_back("2");
1004




5
    REQUIRE("test|line|2" == packList(list));
1005
1006
1
    list.clear();
1007

4
    list.push_back("|test");
1008

4
    list.push_back("line");
1009




5
    REQUIRE("|test|line" == packList(list));
1010
1
}
1011
1012
3
TEST_CASE("stringuntils stringToHexPath 1", "")
1013
{
1014
2
    std::string str;
1015
1016
    str = "";
1017




5
    REQUIRE(stringToHexPath(str).empty());
1018
1019
    str = "a";
1020




5
    REQUIRE("%61/" == stringToHexPath(str));
1021
1022
    str = "ab";
1023




5
    REQUIRE("%61/%62" == stringToHexPath(str));
1024
1025
    str = "abc";
1026




5
    REQUIRE("%61/%62%63" == stringToHexPath(str));
1027
1028
    str = "abcd";
1029




5
    REQUIRE("%61/%62%63%64" == stringToHexPath(str));
1030
1
}
1031
1032
3
TEST_CASE("stringuntils deleteCharLeft 1", "")
1033
{
1034
2
    std::string str;
1035
1
    unsigned int pos = 0;
1036
1037
1
    str = "";
1038
1
    deleteCharLeft(str, nullptr);
1039



4
    REQUIRE(str.empty());
1040
1041
1
    str = "test line";
1042
1
    pos = 4;
1043
1
    deleteCharLeft(str, &pos);
1044



4
    REQUIRE("tes line" == str);
1045
1046
1
    str = "тест line";
1047
1
    pos = 8;
1048
1
    deleteCharLeft(str, &pos);
1049



4
    REQUIRE("тес line" == str);
1050
1051
1
    str = "test line\x0";
1052
1
    pos = 4;
1053
1
    deleteCharLeft(str, &pos);
1054



4
    REQUIRE("tes line\x0" == str);
1055
1
}
1056
1057
3
TEST_CASE("stringuntils findLast 1", "")
1058
{
1059
2
    std::string str;
1060
1061
    str = "";
1062




6
    REQUIRE(findLast(str, ""));
1063
1064
    str = "test line";
1065




6
    REQUIRE(findLast(str, "line"));
1066
1067
    str = "test line";
1068




6
    REQUIRE(!findLast(str, "lin"));
1069
1
}
1070
1071
3
TEST_CASE("stringuntils findFirst 1", "")
1072
{
1073
2
    std::string str;
1074
1075
    str = "";
1076




6
    REQUIRE(findFirst(str, ""));
1077
1078
    str = "test line";
1079




6
    REQUIRE(findFirst(str, "test"));
1080
1081
    str = "test";
1082




7
    REQUIRE(findFirst(str, "test line") == false);
1083
1084
    str = "test line";
1085




7
    REQUIRE(findFirst(str, "est") == false);
1086
1
}
1087
1088
3
TEST_CASE("stringuntils findCutLast 1", "")
1089
{
1090
2
    std::string str;
1091
1092
    str = "";
1093




6
    REQUIRE(findCutLast(str, ""));
1094



4
    REQUIRE(str.empty());
1095
1096
    str = "test line";
1097




6
    REQUIRE(findCutLast(str, "line"));
1098



4
    REQUIRE("test " == str);
1099
1100
    str = "test line";
1101




7
    REQUIRE(findCutLast(str, "lin") == false);
1102



4
    REQUIRE("test line" == str);
1103
1104
    str = "test";
1105




7
    REQUIRE(findCutLast(str, "test line") == false);
1106



4
    REQUIRE("test" == str);
1107
1
}
1108
1109
3
TEST_CASE("stringuntils CutLast 1", "")
1110
{
1111
2
    std::string str;
1112
1113
1
    str = "";
1114

4
    cutLast(str, "");
1115



4
    REQUIRE(str.empty());
1116
1117
1
    str = "test line";
1118

4
    cutLast(str, "line");
1119



4
    REQUIRE("test " == str);
1120
1121
1
    str = "test line";
1122

4
    cutLast(str, "lin");
1123



4
    REQUIRE("test line" == str);
1124
1125
1
    str = "test";
1126

4
    cutLast(str, "test line");
1127



4
    REQUIRE("test" == str);
1128
1
}
1129
1130
3
TEST_CASE("stringuntils findCutFirst 1", "")
1131
{
1132
2
    std::string str;
1133
1134
    str = "";
1135




6
    REQUIRE(findCutFirst(str, ""));
1136



4
    REQUIRE(str.empty());
1137
1138
    str = "test line";
1139




6
    REQUIRE(findCutFirst(str, "test"));
1140



4
    REQUIRE(" line" == str);
1141
1142
    str = "test line";
1143




7
    REQUIRE(findCutFirst(str, "est") == false);
1144



4
    REQUIRE("test line" == str);
1145
1146
    str = "test";
1147




7
    REQUIRE(findCutFirst(str, "test line") == false);
1148



4
    REQUIRE("test" == str);
1149
1
}
1150
1151
3
TEST_CASE("stringuntils cutFirst 1", "")
1152
{
1153
2
    std::string str;
1154
1155
1
    str = "";
1156

4
    cutFirst(str, "");
1157



4
    REQUIRE(str.empty());
1158
1159
1
    str = "test line";
1160

4
    cutFirst(str, "test");
1161



4
    REQUIRE(" line" == str);
1162
1163
1
    str = "test line";
1164

4
    cutFirst(str, "est");
1165



4
    REQUIRE("test line" == str);
1166
1167
1
    str = "test";
1168

4
    cutFirst(str, "test line");
1169



4
    REQUIRE("test" == str);
1170
1
}
1171
1172
3
TEST_CASE("stringuntils removeProtocol 1", "")
1173
{
1174
2
    std::string str;
1175
1176
    str = "";
1177




4
    REQUIRE(removeProtocol(str).empty());
1178
1179
    str = "http://";
1180




4
    REQUIRE(removeProtocol(str).empty());
1181
1182
    str = "http://test";
1183




4
    REQUIRE("test" == removeProtocol(str));
1184
1
}
1185
1186
3
TEST_CASE("stringuntils strStartWith 1", "")
1187
{
1188




9
    REQUIRE(strStartWith("", ""));
1189




9
    REQUIRE(!strStartWith("", "1"));
1190




9
    REQUIRE(strStartWith("test line", "test"));
1191




9
    REQUIRE(strStartWith("test line", "test line"));
1192




9
    REQUIRE(!strStartWith("test line", "est"));
1193
1
}
1194
1195
3
TEST_CASE("stringuntils encodeLinkText", "")
1196
{
1197
2
    std::string str;
1198
1199

5
    str = encodeLinkText("test line");
1200



4
    REQUIRE(str == "test line");
1201

5
    str = encodeLinkText("test|line");
1202



4
    REQUIRE(str == "test\342\235\230line");
1203

5
    str = encodeLinkText("test||line");
1204



4
    REQUIRE(str == "test\342\235\230\342\235\230line");
1205
1
}
1206
1207
3
TEST_CASE("stringuntils decodeLinkText", "")
1208
{
1209
2
    std::string str;
1210
1211

5
    str = encodeLinkText("test|line");
1212



4
    REQUIRE(str == "test\342\235\230line");
1213
3
    str = decodeLinkText(str);
1214



4
    REQUIRE(str == "test|line");
1215
1
}
1216
1217
3
TEST_CASE("stringuntils isDigit", "")
1218
{
1219




6
    REQUIRE_FALSE(isDigit(""));
1220




6
    REQUIRE(isDigit("1"));
1221




6
    REQUIRE(isDigit("123"));
1222




6
    REQUIRE_FALSE(isDigit("+123"));
1223




6
    REQUIRE_FALSE(isDigit("-123"));
1224




6
    REQUIRE_FALSE(isDigit("1.23"));
1225




6
    REQUIRE_FALSE(isDigit("12-34"));
1226
1
}
1227
1228
3
TEST_CASE("stringuntils findAny", "")
1229
{
1230




10
    REQUIRE(findAny("test line", ",", 0) == std::string::npos);
1231




10
    REQUIRE(findAny("test line", " ", 0) == 4U);
1232




10
    REQUIRE(findAny("test, line", ", ", 0) == 4U);
1233




10
    REQUIRE(findAny("test ,line", ", ", 0) == 4U);
1234




10
    REQUIRE(findAny("test, line", " ,", 2) == 4U);
1235




10
    REQUIRE(findAny("test ,line", " ,", 3) == 4U);
1236




10
    REQUIRE(findAny("\"one\",,two, tree", ",", 5) == 5U);
1237
1
}
1238
1239
3
TEST_CASE("stringuntils escapeString", "")
1240
{
1241




8
    REQUIRE(escapeString("") == "\"\"");
1242




8
    REQUIRE(escapeString("1") == "\"1\"");
1243




8
    REQUIRE(escapeString(" ") == "\" \"");
1244




8
    REQUIRE(escapeString("\"") == "\"\\\"\"");
1245




8
    REQUIRE(escapeString("123") == "\"123\"");
1246




8
    REQUIRE(escapeString("12\"3") == "\"12\\\"3\"");
1247




8
    REQUIRE(escapeString("12\"\"3") == "\"12\\\"\\\"3\"");
1248




8
    REQUIRE(escapeString("\"123\"") == "\"\\\"123\\\"\"");
1249




8
    REQUIRE(escapeString("\\") == "\"\\\"");
1250




8
    REQUIRE(escapeString("12\\3") == "\"12\\3\"");
1251
1
}
1252
1253
3
TEST_CASE("stringuntils sanitizePath", "")
1254
{
1255
2
    std::string path;
1256
4
    const std::string sep = dirSeparator;
1257
1
    path = "";
1258
1
    sanitizePath(path);
1259



4
    REQUIRE(path.empty());
1260
1
    path = "/";
1261
1
    sanitizePath(path);
1262



4
    REQUIRE(path == dirSeparator);
1263
1
    path = "/\\";
1264
1
    sanitizePath(path);
1265



4
    REQUIRE(path == dirSeparator);
1266
1
    path = "\\/";
1267
1
    sanitizePath(path);
1268



4
    REQUIRE(path == dirSeparator);
1269
1
    path = "//";
1270
1
    sanitizePath(path);
1271



4
    REQUIRE(path == dirSeparator);
1272
1
    path = "///";
1273
1
    sanitizePath(path);
1274



4
    REQUIRE(path == dirSeparator);
1275
1
    path = "//\\/";
1276
1
    sanitizePath(path);
1277



4
    REQUIRE(path == dirSeparator);
1278
1
    path = "///\\";
1279
1
    sanitizePath(path);
1280



4
    REQUIRE(path == dirSeparator);
1281
1
    path = "\\";
1282
1
    sanitizePath(path);
1283



4
    REQUIRE(path == dirSeparator);
1284
1
    path = "\\\\";
1285
1
    sanitizePath(path);
1286



4
    REQUIRE(path == dirSeparator);
1287
1
    path = "\\/\\";
1288
1
    sanitizePath(path);
1289



4
    REQUIRE(path == dirSeparator);
1290
1
    path = "\\\\/";
1291
1
    sanitizePath(path);
1292



4
    REQUIRE(path == dirSeparator);
1293
1
    path = "test";
1294
1
    sanitizePath(path);
1295



4
    REQUIRE(path == "test");
1296
1
    path = "./test";
1297
1
    sanitizePath(path);
1298




6
    REQUIRE(path == "." + sep + "test");
1299
1
    path = "test line";
1300
1
    sanitizePath(path);
1301



4
    REQUIRE(path == "test line");
1302
1
    path = "dir/test";
1303
1
    sanitizePath(path);
1304




6
    REQUIRE(path == "dir" + sep + "test");
1305
1
    path = "/dir/test";
1306
1
    sanitizePath(path);
1307





7
    REQUIRE(path == sep + "dir" + sep + "test");
1308
1
    path = "dir//test";
1309
1
    sanitizePath(path);
1310




6
    REQUIRE(path == "dir" + sep + "test");
1311
1
    path = "dir///test";
1312
1
    sanitizePath(path);
1313




6
    REQUIRE(path == "dir" + sep + "test");
1314
1
    path = "dir///\\test";
1315
1
    sanitizePath(path);
1316




6
    REQUIRE(path == "dir" + sep + "test");
1317
1
    path = "dir/\\//test";
1318
1
    sanitizePath(path);
1319




6
    REQUIRE(path == "dir" + sep + "test");
1320
1
    path = "dir\\test";
1321
1
    sanitizePath(path);
1322




6
    REQUIRE(path == "dir" + sep + "test");
1323
1
    path = "dir/test/";
1324
1
    sanitizePath(path);
1325





7
    REQUIRE(path == "dir" + sep + "test" + sep);
1326
1
    path = "dir/test\\";
1327
1
    sanitizePath(path);
1328





7
    REQUIRE(path == "dir" + sep + "test" + sep);
1329
1
    path = "/very\\long/dir\\with\\sepa/ra/tors";
1330
1
    sanitizePath(path);
1331










17
    REQUIRE(path == sep + "very" + sep + "long" + sep + \
1332
        "dir" + sep + "with" + sep + "sepa" + sep + "ra" + sep + "tors");
1333
1
    path = "/very\\long/dir\\\\with\\sepa//ra/tors";
1334
1
    sanitizePath(path);
1335










17
    REQUIRE(path == sep + "very" + sep + "long" + sep + \
1336
        "dir" + sep + "with" + sep + "sepa" + sep + "ra" + sep + "tors");
1337
1
}
1338
1339
3
TEST_CASE("stringuntils pathJoin1", "")
1340
{
1341
4
    const std::string sep = dirSeparator;
1342
1343





11
    REQUIRE(pathJoin("", "") == sep);
1344




10
    REQUIRE(pathJoin(sep, "") == sep);
1345




8
    REQUIRE(pathJoin("", sep) == sep);
1346




7
    REQUIRE(pathJoin(sep, sep) == sep);
1347






13
    REQUIRE(pathJoin("dir1", "dir2") == "dir1" + sep + "dir2");
1348






11
    REQUIRE(pathJoin("dir1" + sep, "dir2") == "dir1" + sep + "dir2");
1349






11
    REQUIRE(pathJoin("dir1", sep + "dir2") == "dir1" + sep + "dir2");
1350






9
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2") == "dir1" + sep + "dir2");
1351









18
    REQUIRE(pathJoin("dir1" + sep + "dir2" + sep + "dir3", "dir4") ==
1352
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1353









16
    REQUIRE(pathJoin("dir1" + sep + "dir2" + sep, "dir3" + sep + "dir4") ==
1354
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1355









15
    REQUIRE(pathJoin("dir1" + sep + "dir2", "dir3" + sep + "dir4") ==
1356
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1357









16
    REQUIRE(pathJoin("dir1" + sep + "dir2", sep + "dir3" + sep + "dir4") ==
1358
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4");
1359
1
}
1360
1361
3
TEST_CASE("stringuntils pathJoin2", "")
1362
{
1363
4
    const std::string sep = dirSeparator;
1364
1365





14
    REQUIRE(pathJoin("", "", "") == sep);
1366





13
    REQUIRE(pathJoin(sep, "", "") == sep);
1367





11
    REQUIRE(pathJoin("", sep, "") == sep);
1368





11
    REQUIRE(pathJoin("", "", sep) == sep);
1369




10
    REQUIRE(pathJoin(sep, sep, "") == sep);
1370




10
    REQUIRE(pathJoin(sep, "", sep) == sep);
1371




8
    REQUIRE(pathJoin("", sep, sep) == sep);
1372




7
    REQUIRE(pathJoin(sep, sep, sep) == sep);
1373
1374







18
    REQUIRE(pathJoin("dir1", "dir2", "dir3") ==
1375
        "dir1" + sep + "dir2" + sep + "dir3");
1376







16
    REQUIRE(pathJoin("dir1" + sep, "dir2", "dir3") ==
1377
        "dir1" + sep + "dir2" + sep + "dir3");
1378







16
    REQUIRE(pathJoin("dir1", sep + "dir2", "dir3") ==
1379
        "dir1" + sep + "dir2" + sep + "dir3");
1380







16
    REQUIRE(pathJoin("dir1", "dir2" + sep, "dir3") ==
1381
        "dir1" + sep + "dir2" + sep + "dir3");
1382







16
    REQUIRE(pathJoin("dir1", "dir2", sep + "dir3") ==
1383
        "dir1" + sep + "dir2" + sep + "dir3");
1384








17
    REQUIRE(pathJoin("dir1", "dir2", "dir3" + sep) ==
1385
        "dir1" + sep + "dir2" + sep + "dir3" + sep);
1386







14
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2", "dir3") ==
1387
        "dir1" + sep + "dir2" + sep + "dir3");
1388







14
    REQUIRE(pathJoin("dir1" + sep, "dir2" + sep, "dir3") ==
1389
        "dir1" + sep + "dir2" + sep + "dir3");
1390







14
    REQUIRE(pathJoin("dir1" + sep, "dir2", sep + "dir3") ==
1391
        "dir1" + sep + "dir2" + sep + "dir3");
1392








15
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2" + sep, "dir3") ==
1393
        "dir1" + sep + "dir2" + sep + "dir3");
1394







12
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2", sep + "dir3") ==
1395
        "dir1" + sep + "dir2" + sep + "dir3");
1396








15
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2" + sep, "dir3") ==
1397
        "dir1" + sep + "dir2" + sep + "dir3");
1398








13
    REQUIRE(pathJoin("dir1" + sep, sep + "dir2" + sep, sep + "dir3") ==
1399
        "dir1" + sep + "dir2" + sep + "dir3");
1400











23
    REQUIRE(pathJoin("dir1" + sep + "dir2" + sep + "dir3", "dir4", "dir5") ==
1401
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4" + sep + "dir5");
1402











21
    REQUIRE(pathJoin("dir1" + sep + "dir2" + sep,
1403
        "dir3" + sep + "dir4",
1404
        "dir5") ==
1405
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4" + sep + "dir5");
1406











21
    REQUIRE(pathJoin("dir1" + sep + "dir2",
1407
        "dir3",
1408
        sep + "dir4" + sep + "dir5") ==
1409
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4" + sep + "dir5");
1410











19
    REQUIRE(pathJoin("dir1" + sep + "dir2",
1411
        sep + "dir3" + sep + "dir4",
1412
        sep + "dir5") ==
1413
        "dir1" + sep + "dir2" + sep + "dir3" + sep + "dir4" + sep + "dir5");
1414
1
}
1415
1416
3
TEST_CASE("stringuntils urlJoin", "")
1417
{
1418




11
    REQUIRE(urlJoin("", "") == "/");
1419




11
    REQUIRE(urlJoin("/", "") == "/");
1420




11
    REQUIRE(urlJoin("", "/") == "/");
1421




11
    REQUIRE(urlJoin("/", "/") == "/");
1422




11
    REQUIRE(urlJoin("dir1", "dir2") == "dir1/dir2");
1423