# Commands covered: scan # # This file contains a collection of tests for one or more of the Tcl # built-in commands. Sourcing this file into Tcl runs the tests and # generates output for errors. No output means no errors were found. # # Copyright 1991 Regents of the University of California # Permission to use, copy, modify, and distribute this # software and its documentation for any purpose and without # fee is hereby granted, provided that this copyright notice # appears in all copies. The University of California makes no # representations about the suitability of this software for any # purpose. It is provided "as is" without express or implied # warranty. # # $Header: /a/cvs/386BSD/ports/tcl/tests/scan.test,v 1.1.1.1 1993/08/09 10:57:46 alm Exp $ (Berkeley) if {[string compare test [info procs test]] == 1} then {source defs} test scan-1.1 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "-20 1476 \n33 0" "%d %d %d %d" a b c d } 4 test scan-1.2 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "-20 1476 \n33 0" "%d %d %d %d" a b c d set a } -20 test scan-1.3 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "-20 1476 \n33 0" "%d %d %d %d" a b c d set b } 1476 test scan-1.4 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "-20 1476 \n33 0" "%d %d %d %d" a b c d set c } 33 test scan-1.5 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "-20 1476 \n33 0" "%d %d %d %d" a b c d set d } 0 test scan-1.6 {integer scanning} { set a {}; set b {}; set c {} scan "-45 16 7890 +10" "%2d %*d %10d %d" a b c } 3 test scan-1.7 {integer scanning} { set a {}; set b {}; set c {} scan "-45 16 7890 +10" "%2d %*d %10d %d" a b c set a } -4 test scan-1.8 {integer scanning} { set a {}; set b {}; set c {} scan "-45 16 7890 +10" "%2d %*d %10d %d" a b c set b } 16 test scan-1.9 {integer scanning} { set a {}; set b {}; set c {} scan "-45 16 7890 +10" "%2d %*d %10d %d" a b c set c } 7890 # Capitalized format specifiers don't work on some systems, so # only run the following tests at Berkeley. if $atBerkeley { test scan-1.10 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "-45 16 +10 987" "%D %d %D %d" a b c d } 4 test scan-1.11 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "-45 16 +10 987" "%D %d %D %d" a b c d set a } -45 test scan-1.12 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "-45 16 +10 987" "%D %d%D %d" a b c d set b } 16 test scan-1.13 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "-45 16 +10 987" "%D %d %D %d" a b c d set c } 10 test scan-1.14 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "-45 16 +10 987" "%D %d %D %d" a b c d set d } 987 test scan-1.15 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "14 1ab 62 10" "%d %x %O %x" a b c d } 4 test scan-1.16 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "14 1ab 62 10" "%d %x %O %x" a b c d set a } 14 test scan-1.17 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "14 1ab 62 10" "%d %x %O %x" a b c d set b } 427 test scan-1.18 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "14 1ab 62 10" "%d %x %O %x" a b c d set c } 50 test scan-1.19 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "14 1ab 62 10" "%d %x %O %x" a b c d set d } 16 test scan-1.20 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "12345670 1234567890ab cdefg" "%o %o %x %X" a b c d } 4 } test scan-1.21 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "12345670 1234567890ab cdefg" "%o %o %x %X" a b c d set a } 2739128 test scan-1.22 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "12345670 1234567890ab cdefg" "%o %o %x %X" a b c d set b } 342391 test scan-1.23 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "12345670 1234567890ab cdefg" "%o %o %x %X" a b c d set c } 561323 test scan-1.24 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "12345670 1234567890ab cdefg" "%o %o %x %X" a b c d set d } 52719 test scan-1.25 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "ab123-24642" "%2x %3x %3o %2o" a b c d } 4 test scan-1.26 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "ab123-24642" "%2x %3x %3o %2o" a b c d set a } 171 test scan-1.27 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "ab123-24642" "%2x %3x %3o %2o" a b c d set b } 291 test scan-1.28 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "ab123-24642" "%2x %3x %3o %2o" a b c d set c } -20 test scan-1.29 {integer scanning} { set a {}; set b {} scan "ab123-24642" "%2x %3x %3o %2o" a b c d set d } 52 test scan-1.30 {integer scanning} { set a {}; set b {} scan "1234567 234 567 " "%*3x %x %*o %4o" a b } 2 test scan-1.31 {integer scanning} { set a {}; set b {} scan "1234567 234 567 " "%*3x %x %*o %4o" a b set a } 17767 test scan-1.32 {integer scanning} { set a {}; set b {} scan "a 1234" "%d %d" a b } 0 test scan-1.33 {integer scanning} { set a {} scan "a 1234" "%d %d" a b set a } {} test scan-1.34 {integer scanning} { set a {}; set b {}; set c {}; set d {}; scan "12345678" "%2d %2d %2d %2d" a b c d } 4 test scan-1.35 {integer scanning} { set a {}; set b {}; set c {}; set d {}; scan "12345678" "%2d %2d %2d %2d" a b c d set a } 12 test scan-1.36 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "12345678" "%2d %2d %2d %2d" a b c d set b } 34 test scan-1.37 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "12345678" "%2d %2d %2d %2d" a b c d set c } 56 test scan-1.38 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "12345678" "%2d %2d %2d %2d" a b c d set d } 78 test scan-1.39 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "1 2 " "%d %d %d %d" a b c d } 2 test scan-1.40 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "1 2 " "%d %d %d %d" a b c d set a } 1 test scan-1.41 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "1 2 " "%d %d %d %d" a b c d set b } 2 test scan-1.42 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "1 2 " "%d %d %d %d" a b c d } 2 test scan-1.43 {integer scanning} { set a {}; set b {}; set c {}; set d {} scan "1 2 " "%d %d %d %d" a b c d set d } {} test scan-2.1 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "2.1 -3.0e8 .99962 a" "%f%f%f%f" a b c d } 3 test scan-2.2 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "2.1 -3.0e8 .99962 a" "%f%f%f%f" a b c d set a } 2.1 test scan-2.3 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "2.1 -3.0e8 .99962 a" "%f%f%f%f" a b c d set b } -3e+08 test scan-2.4 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "2.1 -3.0e8 .99962 a" "%f%f%f%f" a b c d set c } 0.99962 test scan-2.5 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "2.1 -3.0e8 .99962 a" "%f%f%f%f" a b c d set d } {} test scan-2.6 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "-1.2345 +8.2 9" "%3e %3f %f %f" a b c d } 4 test scan-2.7 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "-1.2345 +8.2 9" "%3e %3f %f %f" a b c d set a } -1 test scan-2.8 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "-1.2345 +8.2 9" "%3e %3f %f %f" a b c d set b } 234 test scan-2.9 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "-1.2345 +8.2 9" "%3e %3f %f %f" a b c d set c } 5 test scan-2.10 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "-1.2345 +8.2 9" "%3e %3f %f %f" a b c d set d } 8.2 test scan-2.11 {floating-point scanning} { set a {}; set b {}; set c {} scan "1e00004 332E-4 3e+4" "%f %*2e %f %f" a b c } 3 test scan-2.12 {floating-point scanning} { set a {}; set b {}; set c {} scan "1e00004 332E-4 3e+4" "%f %*2e %f %f" a b c set a } 10000 test scan-2.13 {floating-point scanning} { set a {}; set b {}; set c {} scan "1e00004 332E-4 3e+4" "%f %*2e %f %f" a b c set c } 30000 if $atBerkeley { test scan-2.14 {floating-point scanning} { set a {}; set b {}; set c {} scan "1. 47.6 2.e2 3.e-" "%f %*f %f %f" a b c } 3 } test scan-2.15 {floating-point scanning} { set a {}; set b {}; set c {} scan "1. 47.6 2.e2 3.e-" "%f %*f %f %f" a b c set a } 1 test scan-2.16 {floating-point scanning} { set a {}; set b {}; set c {} scan "1. 47.6 2.e2 3.e-" "%f %*f %f %f" a b c set b } 200 if $atBerkeley { test scan-2.17 {floating-point scanning} { set a {}; set b {}; set c {} scan "1. 47.6 2.e2 3.e-" "%f %*f %f %f" a b c set c } 3 test scan-2.18 {floating-point scanning} { set a {}; set b {} scan "1.eabc" "%f %x" a b } 2 test scan-2.19 {floating-point scanning} { set a {}; set b {} scan "1.eabc" "%f %x" a b set a } 1 } test scan-2.20 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d } 4 test scan-2.21 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d set a } 4.6 test scan-2.22 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d set b } 99999.7 test scan-2.23 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d set c } 87.643 test scan-2.24 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d set d } 118 test scan-2.25 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d } 4 test scan-2.26 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d set a } 1.2345 test scan-2.27 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d set b } 0.697 test scan-2.28 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d set c } 124 test scan-2.29 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d set d } 5e-05 test scan-2.30 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6abc" "%f %f %f %f" a b c d } 1 test scan-2.31 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6abc" "%f %f %f %f" a b c d set a } 4.6 test scan-2.32 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6abc" "%f %f %f %f" a b c d set b } {} test scan-2.33 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6abc" "%f %f %f %f" a b c d set c } {} test scan-2.34 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6abc" "%f %f %f %f" a b c d set d } {} test scan-2.35 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6 5.2" "%f %f %f %f" a b c d } 2 test scan-2.36 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6 5.2" "%f %f %f %f" a b c d set a } 4.6 test scan-2.37 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6 5.2" "%f %f %f %f" a b c d set b } 5.2 test scan-2.38 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6 5.2" "%f %f %f %f" a b c d set c } {} test scan-2.39 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} scan "4.6 5.2" "%f %f %f %f" a b c d set d } {} test scan-3.1 {string and character scanning} { set a {}; set b {}; set c {}; set d {} scan "abc defghijk dum " "%s %3s %20s %s" a b c d } 4 test scan-3.2 {string and character scanning} { set a {}; set b {}; set c {}; set d {} scan "abc defghijk dum " "%s %3s %20s %s" a b c d set a } abc test scan-3.3 {string and character scanning} { set a {}; set b {}; set c {}; set d {} scan "abc defghijk dum " "%s %3s %20s %s" a b c d set b } def test scan-3.4 {string and character scanning} { set a {}; set b {}; set c {}; set d {} scan "abc defghijk dum " "%s %3s %20s %s" a b c d set c } ghijk test scan-3.5 {string and character scanning} { set a {}; set b {}; set c {}; set d {} scan "abc defghijk dum " "%s %3s %20s %s" a b c d set d } dum test scan-3.6 {string and character scanning} { set a {}; set b {}; set c {}; set d {} scan "a bcdef" "%c%c%1s %s" a b c d } 4 test scan-3.7 {string and character scanning} { set a {}; set b {}; set c {}; set d {} scan "a bcdef" "%c%c%1s %s" a b c d set a } 97 test scan-3.8 {string and character scanning} { set a {}; set b {}; set c {}; set d {} scan "a bcdef" "%c%c%1s %s" a b c d set b } 32 test scan-3.9 {string and character scanning} { set a {}; set b {}; set c {}; set d {} scan "a bcdef" "%c%c%1s %s" a b c d set c } b test scan-3.10 {string and character scanning} { set a {}; set b {}; set c {}; set d {} scan "a bcdef" "%c%c%1s %s" a b c d set d } cdef test scan-3.11 {string and character scanning} { set a {}; set b {}; set c {} scan "123456 test " "%*c%*s %s %s %s" a b c } 1 test scan-3.12 {string and character scanning} { set a {}; set b {}; set c {} scan "123456 test " "%*c%*s %s %s %s" a b c set a } test test scan-3.13 {string and character scanning} { set a {}; set b {}; set c {} scan "123456 test " "%*c%*s %s %s %s" a b c set b } {} test scan-3.14 {string and character scanning} { set a {}; set b {}; set c {} scan "123456 test " "%*c%*s %s %s %s" a b c set c } {} test scan-3.15 {string and character scanning} { set a {}; set b {}; set c {}; set d scan "ababcd01234 f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d } 4 test scan-3.16 {string and character scanning} { set a {}; set b {}; set c {}; set d scan "ababcd01234 f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d set a } abab test scan-3.17 {string and character scanning} { set a {}; set b {}; set c {}; set d scan "ababcd01234 f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d set b } cd test scan-3.18 {string and character scanning} { set a {}; set b {}; set c {}; set d scan "ababcd01234 f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d set c } {01234 } test scan-3.19 {string and character scanning} { set a {}; set b {}; set c {}; set d scan "ababcd01234 f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d set d } {f 12345} test scan-3.20 {string and character scanning} { set a {}; set b {}; set c {} scan "aaaaaabc aaabcdefg + + XYZQR" {%*4[a] %s %*4[a]%s%*4[ +]%c} a b c } 3 test scan-3.21 {string and character scanning} { set a {}; set b {}; set c {} scan "aaaaaabc aaabcdefg + + XYZQR" {%*4[a] %s %*4[a]%s%*4[ +]%c} a b c set a } aabc test scan-3.22 {string and character scanning} { set a {}; set b {}; set c {} scan "aaaaaabc aaabcdefg + + XYZQR" {%*4[a] %s %*4[a]%s%*4[ +]%c} a b c set b } bcdefg test scan-3.23 {string and character scanning} { set a {}; set b {}; set c {} scan "aaaaaabc aaabcdefg + + XYZQR" {%*4[a] %s %*4[a]%s%*4[ +]%c} a b c set c } 43 test scan-4.1 {error conditions} { catch {scan a} } 1 test scan-4.2 {error conditions} { catch {scan a} msg set msg } {wrong # args: should be "scan string format ?varName varName ...?"} test scan-4.3 {error conditions} { catch {scan "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21" "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d" a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21} } 1 test scan-4.4 {error conditions} { catch {scan "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21" "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d" a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21} msg set msg } {too many fields to scan} test scan-4.5 {error conditions} { catch {scan a %z} } 1 test scan-4.6 {error conditions} { catch {scan a %z} msg set msg } {bad scan conversion character "z"} test scan-4.7 {error conditions} { catch {scan a "%d %d" a} } 1 test scan-4.8 {error conditions} { catch {scan a "%d %d" a} msg set msg } {different numbers of variable names and field specifiers} test scan-4.9 {error conditions} { catch {scan a "%d %d" a b c} } 1 test scan-4.10 {error conditions} { catch {scan a "%d %d" a b c} msg set msg } {different numbers of variable names and field specifiers} test scan-4.11 {error conditions} { set a {}; set b {}; set c {}; set d {} expr {[scan " a" " a %d %d %d %d" a b c d] <= 0} } 1 test scan-4.12 {error conditions} { set a {}; set b {}; set c {}; set d {} scan " a" " a %d %d %d %d" a b c d set a } {} test scan-4.13 {error conditions} { set a {}; set b {}; set c {}; set d {} scan " a" " a %d %d %d %d" a b c d set b } {} test scan-4.14 {error conditions} { set a {}; set b {}; set c {}; set d {} scan " a" " a %d %d %d %d" a b c d set c } {} test scan-4.15 {error conditions} { set a {}; set b {}; set c {}; set d {} scan " a" " a %d %d %d %d" a b c d set d } {} test scan-4.16 {error conditions} { set a {}; set b {}; set c {}; set d {} scan "1 2" "%d %d %d %d" a b c d } 2 test scan-4.17 {error conditions} { set a {}; set b {}; set c {}; set d {} scan "1 2" "%d %d %d %d" a b c d set a } 1 test scan-4.18 {error conditions} { set a {}; set b {}; set c {}; set d {} scan "1 2" "%d %d %d %d" a b c d set b } 2 test scan-4.19 {error conditions} { set a {}; set b {}; set c {}; set d {} scan "1 2" "%d %d %d %d" a b c d set c } {} test scan-4.20 {error conditions} { set a {}; set b {}; set c {}; set d {} scan "1 2" "%d %d %d %d" a b c d set d } {} test scan-4.21 {error conditions} { catch {unset a} set a(0) 44 list [catch {scan 44 %d a} msg] $msg } {1 {couldn't set variable "a"}} test scan-4.22 {error conditions} { catch {unset a} set a(0) 44 list [catch {scan 44 %c a} msg] $msg } {1 {couldn't set variable "a"}} test scan-4.23 {error conditions} { catch {unset a} set a(0) 44 list [catch {scan 44 %s a} msg] $msg } {1 {couldn't set variable "a"}} test scan-4.24 {error conditions} { catch {unset a} set a(0) 44 list [catch {scan 44 %f a} msg] $msg } {1 {couldn't set variable "a"}} test scan-4.25 {error conditions} { catch {unset a} set a(0) 44 list [catch {scan 44 %f a} msg] $msg } {1 {couldn't set variable "a"}} catch {unset a} test scan-4.26 {error conditions} { list [catch {scan 44 %2c a} msg] $msg } {1 {field width may not be specified in %c conversion}} test scan-5.1 {lots of arguments} { scan "10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200" "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d" a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 } 20 test scan-5.2 {lots of arguments} { scan "10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200" "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d" a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 set a20 } 200