# -*- 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