Debian Codegraph @

vendored-meson/meson/test cases/common/188 dict/meson.build

raw
1 project('dict test', 'c')
2
3 dict = {'foo' : 'bar',
4 'baz' : 'foo',
5 'foo bar': 'baz'}
6
7 exe = executable('prog', sources : ['prog.c'])
8
9 i = 0
10
11 foreach key, value : dict
12 test('dict test @0@'.format(key), exe,
13 args : [dict[key], value])
14 i += 1
15 endforeach
16
17 assert(i == 3, 'There should be three elements in that dictionary')
18
19 empty_dict = {}
20
21 foreach key, value : empty_dict
22 assert(false, 'This dict should be empty')
23 endforeach
24
25 d1 = empty_dict + {'a' : 'b'}
26 assert(d1 == {'a' : 'b'}, 'dict addition is not working')
27
28 d2 = d1 + {'a' : 'b2', 'c' : 'd'}
29 assert(d2 == {'a' : 'b2', 'c' : 'd'}, 'dict addition is not working')
30 assert(d1 == {'a' : 'b'}, 'dict should be immutable')
31
32 d3 = d2
33 d3 += {'e' : 'f'}
34 assert(d3 == {'a' : 'b2', 'c' : 'd', 'e' : 'f'}, 'dict plusassign is not working')
35 assert(d2 == {'a' : 'b2', 'c' : 'd'}, 'dict should be immutable')
36
37 dict1 = {}
38
39 # A variable to be used as a key
40 testkey1 = 'myKey1'
41 testkey2 = 'myKey2'
42
43 # Add new entry using the variable
44 dict1 += {testkey1 : 'myValue'}
45 dict1 += {testkey2 : 42}
46
47 # Test that the stored values are correct
48 assert(dict1[testkey1] == 'myValue',
49 'Incorrect string value retrieved from dictionary - variable key')
50 assert(dict1['myKey1'] == 'myValue',
51 'Incorrect string value retrieved from dictionary - literal key')
52 assert(dict1[testkey2] == 42,
53 'Incorrect int value retrieved from dictionary - variable key')
54 assert(dict1['myKey2'] == 42,
55 'Incorrect int value retrieved from dictionary - literal key')
56
57 d = {testkey1 : 1}
58 assert(d[testkey1] == 1,
59 'Incorrect int value retrieved from dictionary - variable key')
60 assert(d['myKey1'] == 1,
61 'Incorrect int value retrieved from dictionary - literal key')
62
63 d = {'1' / '2' : 1, join_paths('a', 'b') : 2}
64 k1 = '1' / '2'
65 k2 = join_paths('a', 'b')
66 assert(d[k1] == 1, 'Incorrect expression evaluation in dictionary key')
67 assert(d[k2] == 2, 'Incorrect expression evaluation in dictionary key')
68
69 d = {'a' + 'b' : 1}
70 assert(d['a' + 'b'] == 1, 'Incorrect expression evaluation in dictionary key')
71 assert(d['ab'] == 1, 'Incorrect expression evaluation in dictionary key')
72
73 # Complex types
74 d = {
75 'sanity': 1,
76 'host': host_machine,
77 'meson': meson,
78 }
79
80 assert(d['sanity'] == 1)
81 assert(not is_disabler(d['meson']))
82 assert(not is_disabler(d['host']))