summaryrefslogtreecommitdiff
path: root/tests/structs/gvalue.vala
blob: c17c9d9c9fa3fb2f8c8292ac75611cb9afac1ea1 (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
void test_value () {
	Value v1 = 1;
	assert (v1.get_int() == 1);

	string s = "hello";
	Value v2 = s;
	assert (v2.get_string () == s);
}

void test_value_array () {
	int[] iarray = {1,2,3,4,5};
	Value[] viarray = {1,2,3,4,5};
	assert (viarray.length == iarray.length);
	for (int i = 0; i < viarray.length; i++) {
		assert (viarray[i].get_int () == iarray[i]);
	}

	string[] sarray = { "hello", "vala", "world" };
	Value[] vsarray = { "hello", "vala", "world" };
	assert (vsarray.length == sarray.length);
	for (int i = 0; i < vsarray.length; i++) {
		assert (vsarray[i].get_string () == sarray[i]);
	}
}

void test_nullable_value () {
	Value? v1 = 1;
	assert (v1.get_int() == 1);

	string s = "hello";
	Value? v2 = s;
	assert (v2.get_string () == s);
}

void test_nullable_value_array () {
	int[] iarray = {1,2,3,4,5};
	Value?[] viarray = {1,2,3,4,5};
	assert (viarray.length == iarray.length);
	for (int i = 0; i < viarray.length; i++) {
		assert (viarray[i].get_int () == iarray[i]);
	}

	string[] sarray = { "hello", "vala", "world" };
	Value?[] vsarray = { "hello", "vala", "world" };
	assert (vsarray.length == sarray.length);
	for (int i = 0; i < vsarray.length; i++) {
		assert (vsarray[i].get_string () == sarray[i]);
	}
}

void take_value (Value v) {
}

bool make_bool () {
	return true;
}

void main () {
	test_value ();
	test_value_array ();
	test_nullable_value ();
	test_nullable_value_array ();
	take_value (make_bool ());
}