blob: 95ba30562225da4fa45370031bb10fd86776465d (
plain)
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
|
using GLib;
class Maman.Foo : Object {
const string[] array_field = {"1", "2"};
/* Does not work, because of bug 516287
static const public string s1_field = "1" + "2";
static const string s2_field = "1" + "2";
*/
static void test_string_initializers () {
/* Does not work yet. bug 530623
// Local constant
const string s1 = "1";
assert (s1 == "1");
*/
/* Does not work yet. bug 530623 and bug 516287
// Local constant with string concatenation
const string s2 = "1" + "2";
assert (s2 == "12");
*/
// string array
string[] array1 = {"1", "2"};
assert (array1[0] == "1");
assert (array1[1] == "2");
assert (array1.length == 2);
// string array field
assert (array_field[0] == "1");
assert (array_field[1] == "2");
assert (array_field.length == 2);
/* Does not work, because of bug 516287
// const field string with concatenation
assert (s1_field == "12");
assert (s2_field == "12");
*/
}
static void test_string_operators () {
// string == operator compares content not reference
string s1 = "string";
string s2 = "string";
bool eq = (s1 == s2);
assert (eq);
// allow null string comparison
s1 = null;
s2 = null;
eq = (s1 == s2);
assert (eq);
}
static int main (string[] args) {
stdout.printf ("String Test: 1");
stdout.printf (" 2" + " 3");
string s = " 4";
s += " 5";
stdout.printf ("%s", s);
string t = " 5 6 7 8".substring (2, 4);
stdout.printf ("%s", t);
stdout.printf (" 8\n");
test_string_operators ();
test_string_initializers ();
return 0;
}
}
|