File: inifile.test

package info (click to toggle)
tcllib 1.16-dfsg-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 50,040 kB
  • ctags: 18,603
  • sloc: tcl: 156,708; ansic: 14,098; sh: 10,783; xml: 1,766; yacc: 1,114; pascal: 551; makefile: 89; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (160 lines) | stat: -rw-r--r-- 3,780 bytes parent folder | download | duplicates (4)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# -*- tcl -*-
# Tests for module 'inifile'

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.2
testsNeedTcltest 1.0

testing {
    useLocal ini.tcl inifile
}

#---------------------------------------------------------------------

set inifile [localPath ini.tcl]
set testini [localPath test.ini]

#---------------------------------------------------------------------

test inifile-1.1 {ini::open} {
    set res [ini::open $testini r]
    ini::close $res
    set res
} {ini0}

test inifile-1.2 {ini::sections} {
    set hdl [ini::open $testini r]
    set res [ini::sections $hdl]
    ini::close $hdl
    set res
} {emptysection section1 \{test section2}

test inifile-1.3 {ini::keys} {
    set hdl [ini::open $testini r]
    set res [ini::keys $hdl section1]
    ini::close $hdl
    set res
} {testkey key}

test inifile-1.4 {ini::keys} {
    set hdl [ini::open $testini r]
    set res [ini::keys $hdl \{test]
    ini::close $hdl
    set res
} {\}key}

test inifile-1.5 {ini::get} {
    set hdl [ini::open $testini r]
    set res [ini::get $hdl section1]
    ini::close $hdl
    set res
} {testkey hi key value}

test inifile-1.6 {ini::get} {
    set hdl [ini::open $testini r]
    set res [ini::get $hdl \{test]
    ini::close $hdl
    set res
} {\}key {$blah}}

test inifile-1.7 {ini::value} {
    set hdl [ini::open $testini r]
    set res [ini::value $hdl section1 key]
    ini::close $hdl
    set res
} {value}

test inifile-1.8 {ini::value} {
    set hdl [ini::open $testini r]
    set res [ini::value $hdl \{test \}key]
    ini::close $hdl
    set res
} {$blah}

test inifile-1.9 {ini::exists} {
    set hdl [ini::open $testini r]
    set res [ini::exists $hdl section1]
    ini::close $hdl
    set res
} {1}

test inifile-1.10 {ini::exists} {
    set hdl [ini::open $testini r]
    set res [ini::exists $hdl section]
    ini::close $hdl
    set res
} {0}

test inifile-1.11 {ini::exists} {
    set hdl [ini::open $testini r]
    set res [ini::exists $hdl section1 testkey]
    ini::close $hdl
    set res
} {1}

test inifile-1.12 {ini:::exists} {
    set hdl [ini::open $testini r]
    set res [ini::exists $hdl section1 blah]
    ini::close $hdl
    set res
} {0}

test inifile-1.13 {ini:::exists} {
    set hdl [ini::open $testini r]
    set res [ini::exists $hdl \{test]
    ini::close $hdl
    set res
} {1}

test inifile-1.14 {ini:::exists} {
    set hdl [ini::open $testini r]
    set res [ini::exists $hdl \{test \}key]
    ini::close $hdl
    set res
} {1}

# Tests for bug #1281136 --
set N 0
foreach name {nexthandle commentchar} {
    test inifile-2.$N {bug 1281136 - collision with global variable names} {
        set script {list [catch {
            array set ::%var {}
            source %file
        } err] $err}
        regsub {%file} $script $inifile script
        regsub {%var} $script $name script
        interp create slave0
        set r [slave0 eval $script]
        interp delete slave0
        set r
    } {0 {}}
    incr N
}
foreach name {data comments sections} {
    test inifile-2.$N {bug 1281136 - collision with global variable names} {
        set script {list [catch {
            ::set ::%var 0
            source %file
            set res [ini::open %testini r]
            ini::close $res
        } err] $err}
        foreach {s v} [list %file $inifile %var $name %testini $testini] {
            regsub $s $script $v script
        }
        interp create slave0
        set r [slave0 eval $script]
        interp delete slave0
        set r
    } {0 {}}
    incr N
}

#---------------------------------------------------------------------
# Clean up

testsuiteCleanup