codegen: Drop unnecessary comma expressions when boxing values
[vala-lang.git] / tests / basic-types / arrays.vala
blobff32f2da881875f4758262a5d34936afe0a474cd
1 void test_integer_array () {
2 // declaration and initialization
3 int[] a = { 42 };
4 assert (a.length == 1);
5 assert (a[0] == 42);
7 // assignment
8 a = { 42, 23 };
9 assert (a.length == 2);
10 assert (a[0] == 42);
11 assert (a[1] == 23);
13 // access
14 int[] b = a;
15 assert (b.length == 2);
16 assert (b[0] == 42);
17 assert (b[1] == 23);
19 // +
20 a += 11;
21 assert (a.length == 3);
22 assert (a[0] == 42);
23 assert (a[1] == 23);
24 assert (a[2] == 11);
25 assert (b.length == 2);
26 assert (b[0] == 42);
27 assert (b[1] == 23);
29 // slices
30 int[] c = a[1:3];
31 assert (c.length == 2);
32 assert (c[0] == 23);
33 assert (c[1] == 11);
35 // in expressions
36 assert (23 in a);
37 assert (!(-1 in a));
40 void test_string_array () {
41 // declaration and initialization
42 string[] a = { "hello" };
43 assert (a.length == 1);
44 assert (a[0] == "hello");
46 // assignment
47 a = { "hello", "world" };
48 assert (a.length == 2);
49 assert (a[0] == "hello");
50 assert (a[1] == "world");
52 // access
53 string[] b = a;
54 assert (b.length == 2);
55 assert (b[0] == "hello");
56 assert (b[1] == "world");
59 int[] pass_helper (int[] a, out int[] b) {
60 b = a;
61 return { 42, 23 };
64 void test_array_pass () {
65 int[] a, b;
66 a = pass_helper ({ 42 }, out b);
67 assert (a.length == 2);
68 assert (a[0] == 42);
69 assert (a[1] == 23);
70 assert (b.length == 1);
71 assert (b[0] == 42);
74 void main () {
75 test_integer_array ();
76 test_string_array ();
77 test_array_pass ();