update for 0.4.0 release
[vala-lang.git] / tests / strings.vala
blob95ba30562225da4fa45370031bb10fd86776465d
1 using GLib;
3 class Maman.Foo : Object {
5 const string[] array_field = {"1", "2"};
7 /* Does not work, because of bug 516287
8 static const public string s1_field = "1" + "2";
9 static const string s2_field = "1" + "2";
12 static void test_string_initializers () {
13 /* Does not work yet. bug 530623
14 // Local constant
15 const string s1 = "1";
16 assert (s1 == "1");
19 /* Does not work yet. bug 530623 and bug 516287
20 // Local constant with string concatenation
21 const string s2 = "1" + "2";
22 assert (s2 == "12");
25 // string array
26 string[] array1 = {"1", "2"};
28 assert (array1[0] == "1");
29 assert (array1[1] == "2");
30 assert (array1.length == 2);
32 // string array field
33 assert (array_field[0] == "1");
34 assert (array_field[1] == "2");
35 assert (array_field.length == 2);
37 /* Does not work, because of bug 516287
38 // const field string with concatenation
39 assert (s1_field == "12");
40 assert (s2_field == "12");
43 static void test_string_operators () {
44 // string == operator compares content not reference
45 string s1 = "string";
46 string s2 = "string";
47 bool eq = (s1 == s2);
48 assert (eq);
50 // allow null string comparison
51 s1 = null;
52 s2 = null;
53 eq = (s1 == s2);
54 assert (eq);
57 static int main (string[] args) {
58 stdout.printf ("String Test: 1");
60 stdout.printf (" 2" + " 3");
62 string s = " 4";
63 s += " 5";
64 stdout.printf ("%s", s);
66 string t = " 5 6 7 8".substring (2, 4);
67 stdout.printf ("%s", t);
69 stdout.printf (" 8\n");
71 test_string_operators ();
72 test_string_initializers ();
74 return 0;