Debian Codegraph @

src/test/01-Basic/198-string-replace.ck

raw
1 // testing string.replace( from, to )
2 // added 1.5.1.3 (nshaheed)
3
4 // Replace something
5 "Hello, world!" => string replaced;
6 replaced.replace("world", "Chuck");
7
8 if (replaced != "Hello, Chuck!") {
9 <<< "Expected \"Hello, Chuck!\", got", replaced >>>;
10 me.exit();
11 }
12
13 // Replace multiple
14 "Hello, the world! Hello, the world! Hello, the world! Hello, the world!" => replaced;
15 replaced.replace("world", "Chuck");
16
17 if (replaced != "Hello, the Chuck! Hello, the Chuck! Hello, the Chuck! Hello, the Chuck!") {
18 <<< "Expected \"Hello, the Chuck! Hello, the Chuck! Hello, the Chuck! Hello, the Chuck!\", got", replaced >>>;
19 me.exit();
20 }
21
22 // Replacement to empty string
23 "Replace me!" => replaced;
24 replaced.replace("me", "");
25
26 if (replaced != "Replace !") {
27 <<< "Expected \"Replace !\", got", replaced >>>;
28 me.exit();
29 }
30
31 // Replacement from empty string
32 "Replace me!" => replaced;
33 replaced.replace("", "me");
34
35 if (replaced != "Replace me!") {
36 <<< "Expected \"Replace me!\", got", replaced >>>;
37 me.exit();
38 }
39
40 // No match
41 "No replacement here!" => replaced;
42 replaced.replace("ChucK", "NotChucK");
43
44 if (replaced != "No replacement here!") {
45 <<< "Expected \"No replacement here!\", got", replaced >>>;
46 me.exit();
47 }
48
49 // done
50 <<< "success" >>>;