aboutsummaryrefslogtreecommitdiff
path: root/tests/dict.test
blob: abccdb3ab96a1c3e434f87f38a9a79ce895d1e60 (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
package require testing

section "basic dict"

test dict-1.1 "Basic dict" {
	set d [dict create]
	dict set d fruit apple
	dict set d car holden
	#puts "d=$d"
	#puts "d(fruit)=$d(fruit)"
	dict get $d car
} {holden}

catch {unset d}

test dict-2.1 "Dict via reference" {
	set d [dict create]
	dict set d fruit apple
	dict set d car holden

	# now create a dictionary reference
	set dref [ref $d dict]
	dict get [getref $dref] car
} {holden}

test dict-2.2 "Modify dict via reference" {
	# Get the value out of the refernence
	set d [getref $dref]
	# Modify it
	dict set d car toyota
	# And put the new value back
	setref $dref $d
	# Finally check it
	dict get [getref $dref] car
} {toyota}

test dict-2.3 "Modify dict via reference - one line" {
	# Get the value out of the refernence
	set d [getref $dref]
	setref $dref [dict set d car toyota]
	# Finally check it
	dict get [getref $dref] car
} {toyota}

testreport