home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tcl7.0b1 / tests / scan.test < prev    next >
Encoding:
Text File  |  1993-06-03  |  21.2 KB  |  694 lines

  1. # Commands covered:  scan
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/scan.test,v 1.14 93/06/03 10:35:48 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. test scan-1.1 {integer scanning} {
  32.     set a {}; set b {}; set c {}; set d {}
  33.     scan "-20 1476 \n33 0" "%d %d %d %d" a b c d
  34. } 4
  35. test scan-1.2 {integer scanning} {
  36.     set a {}; set b {}; set c {}; set d {}
  37.     scan "-20 1476 \n33 0" "%d %d %d %d" a b c d
  38.     set a
  39. } -20
  40. test scan-1.3 {integer scanning} {
  41.     set a {}; set b {}; set c {}; set d {}
  42.     scan "-20 1476 \n33 0" "%d %d %d %d" a b c d
  43.     set b
  44. } 1476
  45. test scan-1.4 {integer scanning} {
  46.     set a {}; set b {}; set c {}; set d {}
  47.     scan "-20 1476 \n33 0" "%d %d %d %d" a b c d
  48.     set c
  49. } 33
  50. test scan-1.5 {integer scanning} {
  51.     set a {}; set b {}; set c {}; set d {}
  52.     scan "-20 1476 \n33 0" "%d %d %d %d" a b c d
  53.     set d
  54. } 0
  55. test scan-1.6 {integer scanning} {
  56.     set a {}; set b {}; set c {}
  57.     scan "-45 16 7890 +10" "%2d %*d %10d %d" a b c
  58. } 3
  59. test scan-1.7 {integer scanning} {
  60.     set a {}; set b {}; set c {}
  61.     scan "-45 16 7890 +10" "%2d %*d %10d %d" a b c
  62.     set a
  63. } -4
  64. test scan-1.8 {integer scanning} {
  65.     set a {}; set b {}; set c {}
  66.     scan "-45 16 7890 +10" "%2d %*d %10d %d" a b c
  67.     set b
  68. } 16
  69. test scan-1.9 {integer scanning} {
  70.     set a {}; set b {}; set c {}
  71.     scan "-45 16 7890 +10" "%2d %*d %10d %d" a b c
  72.     set c
  73. } 7890
  74.  
  75. # Capitalized format specifiers don't work on some systems, so
  76. # only run the following tests at Berkeley.
  77.  
  78. if $atBerkeley {
  79.     test scan-1.10 {integer scanning} {
  80.     set a {}; set b {}; set c {}; set d {}
  81.     scan "-45 16 +10 987" "%D %d %D %d" a b c d
  82.     } 4
  83.     test scan-1.11 {integer scanning} {
  84.     set a {}; set b {}; set c {}; set d {}
  85.     scan "-45 16 +10 987" "%D %d %D %d" a b c d
  86.     set a
  87.     } -45
  88.     test scan-1.12 {integer scanning} {
  89.     set a {}; set b {}; set c {}; set d {}
  90.     scan "-45 16 +10 987" "%D %d%D %d" a b c d
  91.     set b
  92.     } 16
  93.     test scan-1.13 {integer scanning} {
  94.     set a {}; set b {}; set c {}; set d {}
  95.     scan "-45 16 +10 987" "%D %d %D %d" a b c d
  96.     set c
  97.     } 10
  98.     test scan-1.14 {integer scanning} {
  99.     set a {}; set b {}; set c {}; set d {}
  100.     scan "-45 16 +10 987" "%D %d %D %d" a b c d
  101.     set d
  102.     } 987
  103.     test scan-1.15 {integer scanning} {
  104.     set a {}; set b {}; set c {}; set d {}
  105.     scan "14 1ab 62 10" "%d %x %O %x" a b c d
  106.     } 4
  107.     test scan-1.16 {integer scanning} {
  108.     set a {}; set b {}; set c {}; set d {}
  109.     scan "14 1ab 62 10" "%d %x %O %x" a b c d
  110.     set a
  111.     } 14
  112.     test scan-1.17 {integer scanning} {
  113.     set a {}; set b {}; set c {}; set d {}
  114.     scan "14 1ab 62 10" "%d %x %O %x" a b c d
  115.     set b
  116.     } 427
  117.     test scan-1.18 {integer scanning} {
  118.     set a {}; set b {}; set c {}; set d {}
  119.     scan "14 1ab 62 10" "%d %x %O %x" a b c d
  120.     set c
  121.     } 50
  122.     test scan-1.19 {integer scanning} {
  123.     set a {}; set b {}; set c {}; set d {}
  124.     scan "14 1ab 62 10" "%d %x %O %x" a b c d
  125.     set d
  126.     } 16
  127.     test scan-1.20 {integer scanning} {
  128.     set a {}; set b {}; set c {}; set d {}
  129.     scan "12345670 1234567890ab cdefg" "%o     %o %x %X" a b c d
  130.     } 4
  131. }
  132. test scan-1.21 {integer scanning} {
  133.     set a {}; set b {}; set c {}; set d {}
  134.     scan "12345670 1234567890ab cdefg" "%o     %o %x %X" a b c d
  135.     set a
  136. } 2739128
  137. test scan-1.22 {integer scanning} {
  138.     set a {}; set b {}; set c {}; set d {}
  139.     scan "12345670 1234567890ab cdefg" "%o     %o %x %X" a b c d
  140.     set b
  141. } 342391
  142. test scan-1.23 {integer scanning} {
  143.     set a {}; set b {}; set c {}; set d {}
  144.     scan "12345670 1234567890ab cdefg" "%o     %o %x %X" a b c d
  145.     set c
  146. } 561323
  147. test scan-1.24 {integer scanning} {
  148.     set a {}; set b {}; set c {}; set d {}
  149.     scan "12345670 1234567890ab cdefg" "%o     %o %x %X" a b c d
  150.     set d
  151. } 52719
  152. test scan-1.25 {integer scanning} {
  153.     set a {}; set b {}; set c {}; set d {}
  154.     scan "ab123-24642" "%2x %3x %3o %2o" a b c d
  155. } 4
  156. test scan-1.26 {integer scanning} {
  157.     set a {}; set b {}; set c {}; set d {}
  158.     scan "ab123-24642" "%2x %3x %3o %2o" a b c d
  159.     set a
  160. } 171
  161. test scan-1.27 {integer scanning} {
  162.     set a {}; set b {}; set c {}; set d {}
  163.     scan "ab123-24642" "%2x %3x %3o %2o" a b c d
  164.     set b
  165. } 291
  166. test scan-1.28 {integer scanning} {
  167.     set a {}; set b {}; set c {}; set d {}
  168.     scan "ab123-24642" "%2x %3x %3o %2o" a b c d
  169.     set c
  170. } -20
  171. test scan-1.29 {integer scanning} {
  172.     set a {}; set b {}
  173.     scan "ab123-24642" "%2x %3x %3o %2o" a b c d
  174.     set d
  175. } 52
  176. test scan-1.30 {integer scanning} {
  177.     set a {}; set b {}
  178.     scan "1234567 234 567  " "%*3x %x %*o %4o" a b
  179. } 2
  180. test scan-1.31 {integer scanning} {
  181.     set a {}; set b {}
  182.     scan "1234567 234 567  " "%*3x %x %*o %4o" a b
  183.     set a
  184. } 17767
  185. test scan-1.32 {integer scanning} {
  186.     set a {}; set b {}
  187.     scan "a    1234" "%d %d" a b
  188. } 0
  189. test scan-1.33 {integer scanning} {
  190.     set a {}
  191.     scan "a    1234" "%d %d" a b
  192.     set a
  193. } {}
  194. test scan-1.34 {integer scanning} {
  195.     set a {}; set b {}; set c {}; set d {};
  196.     scan "12345678" "%2d %2d %2d %2d" a b c d
  197. } 4
  198. test scan-1.35 {integer scanning} {
  199.     set a {}; set b {}; set c {}; set d {};
  200.     scan "12345678" "%2d %2d %2d %2d" a b c d
  201.     set a
  202. } 12
  203. test scan-1.36 {integer scanning} {
  204.     set a {}; set b {}; set c {}; set d {}
  205.     scan "12345678" "%2d %2d %2d %2d" a b c d
  206.     set b
  207. } 34
  208. test scan-1.37 {integer scanning} {
  209.     set a {}; set b {}; set c {}; set d {}
  210.     scan "12345678" "%2d %2d %2d %2d" a b c d
  211.     set c
  212. } 56
  213. test scan-1.38 {integer scanning} {
  214.     set a {}; set b {}; set c {}; set d {}
  215.     scan "12345678" "%2d %2d %2d %2d" a b c d
  216.     set d
  217. } 78
  218. test scan-1.39 {integer scanning} {
  219.     set a {}; set b {}; set c {}; set d {}
  220.     scan "1 2 " "%d %d %d %d" a b c d
  221. } 2
  222. test scan-1.40 {integer scanning} {
  223.     set a {}; set b {}; set c {}; set d {}
  224.     scan "1 2 " "%d %d %d %d" a b c d
  225.     set a
  226. } 1
  227. test scan-1.41 {integer scanning} {
  228.     set a {}; set b {}; set c {}; set d {}
  229.     scan "1 2 " "%d %d %d %d" a b c d
  230.     set b
  231. } 2
  232. test scan-1.42 {integer scanning} {
  233.     set a {}; set b {}; set c {}; set d {}
  234.     scan "1 2 " "%d %d %d %d" a b c d
  235. } 2
  236. test scan-1.43 {integer scanning} {
  237.     set a {}; set b {}; set c {}; set d {}
  238.     scan "1 2 " "%d %d %d %d" a b c d
  239.     set d
  240. } {}
  241.  
  242. test scan-2.1 {floating-point scanning} {
  243.     set a {}; set b {}; set c {}; set d {}
  244.     scan "2.1 -3.0e8 .99962 a" "%f%f%f%f" a b c d
  245. } 3
  246. test scan-2.2 {floating-point scanning} {
  247.     set a {}; set b {}; set c {}; set d {}
  248.     scan "2.1 -3.0e8 .99962 a" "%f%f%f%f" a b c d
  249.     set a
  250. } 2.1
  251. test scan-2.3 {floating-point scanning} {
  252.     set a {}; set b {}; set c {}; set d {}
  253.     scan "2.1 -3.0e8 .99962 a" "%f%f%f%f" a b c d
  254.     set b
  255. } -3e+08
  256. test scan-2.4 {floating-point scanning} {
  257.     set a {}; set b {}; set c {}; set d {}
  258.     scan "2.1 -3.0e8 .99962 a" "%f%f%f%f" a b c d
  259.     set c
  260. } 0.99962
  261. test scan-2.5 {floating-point scanning} {
  262.     set a {}; set b {}; set c {}; set d {}
  263.     scan "2.1 -3.0e8 .99962 a" "%f%f%f%f" a b c d
  264.     set d
  265. } {}
  266. test scan-2.6 {floating-point scanning} {
  267.     set a {}; set b {}; set c {}; set d {}
  268.     scan "-1.2345 +8.2 9" "%3e %3f %f %f" a b c d
  269. } 4
  270. test scan-2.7 {floating-point scanning} {
  271.     set a {}; set b {}; set c {}; set d {}
  272.     scan "-1.2345 +8.2 9" "%3e %3f %f %f" a b c d
  273.     set a
  274. } -1.0
  275. test scan-2.8 {floating-point scanning} {
  276.     set a {}; set b {}; set c {}; set d {}
  277.     scan "-1.2345 +8.2 9" "%3e %3f %f %f" a b c d
  278.     set b
  279. } 234.0
  280. test scan-2.9 {floating-point scanning} {
  281.     set a {}; set b {}; set c {}; set d {}
  282.     scan "-1.2345 +8.2 9" "%3e %3f %f %f" a b c d
  283.     set c
  284. } 5.0
  285. test scan-2.10 {floating-point scanning} {
  286.     set a {}; set b {}; set c {}; set d {}
  287.     scan "-1.2345 +8.2 9" "%3e %3f %f %f" a b c d
  288.     set d
  289. } 8.2
  290. test scan-2.11 {floating-point scanning} {
  291.     set a {}; set b {}; set c {}
  292.     scan "1e00004 332E-4 3e+4" "%f %*2e %f %f" a b c
  293. } 3
  294. test scan-2.12 {floating-point scanning} {
  295.     set a {}; set b {}; set c {}
  296.     scan "1e00004 332E-4 3e+4" "%f %*2e %f %f" a b c
  297.     set a
  298. } 10000.0
  299. test scan-2.13 {floating-point scanning} {
  300.     set a {}; set b {}; set c {}
  301.     scan "1e00004 332E-4 3e+4" "%f %*2e %f %f" a b c
  302.     set c
  303. } 30000.0
  304. if $atBerkeley {
  305.     test scan-2.14 {floating-point scanning} {
  306.     set a {}; set b {}; set c {}
  307.     scan "1. 47.6 2.e2 3.e-" "%f %*f %f %f" a b c
  308.     } 3
  309. }
  310. test scan-2.15 {floating-point scanning} {
  311.     set a {}; set b {}; set c {}
  312.     scan "1. 47.6 2.e2 3.e-" "%f %*f %f %f" a b c
  313.     set a
  314. } 1.0
  315. test scan-2.16 {floating-point scanning} {
  316.     set a {}; set b {}; set c {}
  317.     scan "1. 47.6 2.e2 3.e-" "%f %*f %f %f" a b c
  318.     set b
  319. } 200.0
  320. if $atBerkeley {
  321.     test scan-2.17 {floating-point scanning} {
  322.     set a {}; set b {}; set c {}
  323.     scan "1. 47.6 2.e2 3.e-" "%f %*f %f %f" a b c
  324.     set c
  325.     } 3.0
  326.     test scan-2.18 {floating-point scanning} {
  327.     set a {}; set b {}
  328.     scan "1.eabc" "%f %x" a b
  329.     } 2
  330.     test scan-2.19 {floating-point scanning} {
  331.     set a {}; set b {}
  332.     scan "1.eabc" "%f %x" a b
  333.     set a
  334.     } 1.0
  335. }
  336. test scan-2.20 {floating-point scanning} {
  337.     set a {}; set b {}; set c {}; set d {}
  338.     scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d
  339. } 4
  340. test scan-2.21 {floating-point scanning} {
  341.     set a {}; set b {}; set c {}; set d {}
  342.     scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d
  343.     set a
  344. } 4.6
  345. test scan-2.22 {floating-point scanning} {
  346.     set a {}; set b {}; set c {}; set d {}
  347.     scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d
  348.     set b
  349. } 99999.7
  350. test scan-2.23 {floating-point scanning} {
  351.     set a {}; set b {}; set c {}; set d {}
  352.     scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d
  353.     set c
  354. } 87.643
  355. test scan-2.24 {floating-point scanning} {
  356.     set a {}; set b {}; set c {}; set d {}
  357.     scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d
  358.     set d
  359. } 118.0
  360. test scan-2.25 {floating-point scanning} {
  361.     set a {}; set b {}; set c {}; set d {}
  362.     scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d
  363. } 4
  364. test scan-2.26 {floating-point scanning} {
  365.     set a {}; set b {}; set c {}; set d {}
  366.     scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d
  367.     set a
  368. } 1.2345
  369. test scan-2.27 {floating-point scanning} {
  370.     set a {}; set b {}; set c {}; set d {}
  371.     scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d
  372.     set b
  373. } 0.697
  374. test scan-2.28 {floating-point scanning} {
  375.     set a {}; set b {}; set c {}; set d {}
  376.     scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d
  377.     set c
  378. } 124.0
  379. test scan-2.29 {floating-point scanning} {
  380.     set a {}; set b {}; set c {}; set d {}
  381.     scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d
  382.     set d
  383. } 5e-05
  384. test scan-2.30 {floating-point scanning} {
  385.     set a {}; set b {}; set c {}; set d {}
  386.     scan "4.6abc" "%f %f %f %f" a b c d
  387. } 1
  388. test scan-2.31 {floating-point scanning} {
  389.     set a {}; set b {}; set c {}; set d {}
  390.     scan "4.6abc" "%f %f %f %f" a b c d
  391.     set a
  392. } 4.6
  393. test scan-2.32 {floating-point scanning} {
  394.     set a {}; set b {}; set c {}; set d {}
  395.     scan "4.6abc" "%f %f %f %f" a b c d
  396.     set b
  397. } {}
  398. test scan-2.33 {floating-point scanning} {
  399.     set a {}; set b {}; set c {}; set d {}
  400.     scan "4.6abc" "%f %f %f %f" a b c d
  401.     set c
  402. } {}
  403. test scan-2.34 {floating-point scanning} {
  404.     set a {}; set b {}; set c {}; set d {}
  405.     scan "4.6abc" "%f %f %f %f" a b c d
  406.     set d
  407. } {}
  408. test scan-2.35 {floating-point scanning} {
  409.     set a {}; set b {}; set c {}; set d {}
  410.     scan "4.6 5.2" "%f %f %f %f" a b c d
  411. } 2
  412. test scan-2.36 {floating-point scanning} {
  413.     set a {}; set b {}; set c {}; set d {}
  414.     scan "4.6 5.2" "%f %f %f %f" a b c d
  415.     set a
  416. } 4.6
  417. test scan-2.37 {floating-point scanning} {
  418.     set a {}; set b {}; set c {}; set d {}
  419.     scan "4.6 5.2" "%f %f %f %f" a b c d
  420.     set b
  421. } 5.2
  422. test scan-2.38 {floating-point scanning} {
  423.     set a {}; set b {}; set c {}; set d {}
  424.     scan "4.6 5.2" "%f %f %f %f" a b c d
  425.     set c
  426. } {}
  427. test scan-2.39 {floating-point scanning} {
  428.     set a {}; set b {}; set c {}; set d {}
  429.     scan "4.6 5.2" "%f %f %f %f" a b c d
  430.     set d
  431. } {}
  432.  
  433. test scan-3.1 {string and character scanning} {
  434.     set a {}; set b {}; set c {}; set d {}
  435.     scan "abc defghijk dum " "%s %3s %20s %s" a b c d
  436. } 4
  437. test scan-3.2 {string and character scanning} {
  438.     set a {}; set b {}; set c {}; set d {}
  439.     scan "abc defghijk dum " "%s %3s %20s %s" a b c d
  440.     set a
  441. } abc
  442. test scan-3.3 {string and character scanning} {
  443.     set a {}; set b {}; set c {}; set d {}
  444.     scan "abc defghijk dum " "%s %3s %20s %s" a b c d
  445.     set b
  446. } def
  447. test scan-3.4 {string and character scanning} {
  448.     set a {}; set b {}; set c {}; set d {}
  449.     scan "abc defghijk dum " "%s %3s %20s %s" a b c d
  450.     set c
  451. } ghijk
  452. test scan-3.5 {string and character scanning} {
  453.     set a {}; set b {}; set c {}; set d {}
  454.     scan "abc defghijk dum " "%s %3s %20s %s" a b c d
  455.     set d
  456. } dum
  457. test scan-3.6 {string and character scanning} {
  458.     set a {}; set b {}; set c {}; set d {}
  459.     scan "a       bcdef" "%c%c%1s %s" a b c d
  460. } 4
  461. test scan-3.7 {string and character scanning} {
  462.     set a {}; set b {}; set c {}; set d {}
  463.     scan "a       bcdef" "%c%c%1s %s" a b c d
  464.     set a
  465. } 97
  466. test scan-3.8 {string and character scanning} {
  467.     set a {}; set b {}; set c {}; set d {}
  468.     scan "a       bcdef" "%c%c%1s %s" a b c d
  469.     set b
  470. } 32
  471. test scan-3.9 {string and character scanning} {
  472.     set a {}; set b {}; set c {}; set d {}
  473.     scan "a       bcdef" "%c%c%1s %s" a b c d
  474.     set c
  475. } b
  476. test scan-3.10 {string and character scanning} {
  477.     set a {}; set b {}; set c {}; set d {}
  478.     scan "a       bcdef" "%c%c%1s %s" a b c d
  479.     set d
  480. } cdef
  481. test scan-3.11 {string and character scanning} {
  482.     set a {}; set b {}; set c {}
  483.     scan "123456 test " "%*c%*s %s %s %s" a b c
  484. } 1
  485. test scan-3.12 {string and character scanning} {
  486.     set a {}; set b {}; set c {}
  487.     scan "123456 test " "%*c%*s %s %s %s" a b c
  488.     set a
  489. } test
  490. test scan-3.13 {string and character scanning} {
  491.     set a {}; set b {}; set c {}
  492.     scan "123456 test " "%*c%*s %s %s %s" a b c
  493.     set b
  494. } {}
  495. test scan-3.14 {string and character scanning} {
  496.     set a {}; set b {}; set c {}
  497.     scan "123456 test " "%*c%*s %s %s %s" a b c
  498.     set c
  499. } {}
  500. test scan-3.15 {string and character scanning} {
  501.     set a {}; set b {}; set c {}; set d
  502.     scan "ababcd01234  f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d
  503. } 4
  504. test scan-3.16 {string and character scanning} {
  505.     set a {}; set b {}; set c {}; set d
  506.     scan "ababcd01234  f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d
  507.     set a
  508. } abab
  509. test scan-3.17 {string and character scanning} {
  510.     set a {}; set b {}; set c {}; set d
  511.     scan "ababcd01234  f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d
  512.     set b
  513. } cd
  514. test scan-3.18 {string and character scanning} {
  515.     set a {}; set b {}; set c {}; set d
  516.     scan "ababcd01234  f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d
  517.     set c
  518. } {01234  }
  519. test scan-3.19 {string and character scanning} {
  520.     set a {}; set b {}; set c {}; set d
  521.     scan "ababcd01234  f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d
  522.     set d
  523. } {f 12345}
  524. test scan-3.20 {string and character scanning} {
  525.     set a {}; set b {}; set c {}
  526.     scan "aaaaaabc aaabcdefg  + +  XYZQR" {%*4[a] %s %*4[a]%s%*4[ +]%c} a b c
  527. } 3
  528. test scan-3.21 {string and character scanning} {
  529.     set a {}; set b {}; set c {}
  530.     scan "aaaaaabc aaabcdefg  + +  XYZQR" {%*4[a] %s %*4[a]%s%*4[ +]%c} a b c
  531.     set a
  532. } aabc
  533. test scan-3.22 {string and character scanning} {
  534.     set a {}; set b {}; set c {}
  535.     scan "aaaaaabc aaabcdefg  + +  XYZQR" {%*4[a] %s %*4[a]%s%*4[ +]%c} a b c
  536.     set b
  537. } bcdefg
  538. test scan-3.23 {string and character scanning} {
  539.     set a {}; set b {}; set c {}
  540.     scan "aaaaaabc aaabcdefg  + +  XYZQR" {%*4[a] %s %*4[a]%s%*4[ +]%c} a b c
  541.     set c
  542. } 43
  543.  
  544. test scan-4.1 {error conditions} {
  545.     catch {scan a}
  546. } 1
  547. test scan-4.2 {error conditions} {
  548.     catch {scan a} msg
  549.     set msg
  550. } {wrong # args: should be "scan string format ?varName varName ...?"}
  551. test scan-4.3 {error conditions} {
  552.     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}
  553. } 1
  554. test scan-4.4 {error conditions} {
  555.     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
  556.     set msg
  557. } {too many fields to scan}
  558. test scan-4.5 {error conditions} {
  559.     catch {scan a %z}
  560. } 1
  561. test scan-4.6 {error conditions} {
  562.     catch {scan a %z} msg
  563.     set msg
  564. } {bad scan conversion character "z"}
  565. test scan-4.7 {error conditions} {
  566.     catch {scan a "%d %d" a}
  567. } 1
  568. test scan-4.8 {error conditions} {
  569.     catch {scan a "%d %d" a} msg
  570.     set msg
  571. } {different numbers of variable names and field specifiers}
  572. test scan-4.9 {error conditions} {
  573.     catch {scan a "%d %d" a b c}
  574. } 1
  575. test scan-4.10 {error conditions} {
  576.     catch {scan a "%d %d" a b c} msg
  577.     set msg
  578. } {different numbers of variable names and field specifiers}
  579. test scan-4.11 {error conditions} {
  580.     set a {}; set b {}; set c {}; set d {}
  581.     expr {[scan "  a" " a %d %d %d %d" a b c d] <= 0}
  582. } 1
  583. test scan-4.12 {error conditions} {
  584.     set a {}; set b {}; set c {}; set d {}
  585.     scan "  a" " a %d %d %d %d" a b c d
  586.     set a
  587. } {}
  588. test scan-4.13 {error conditions} {
  589.     set a {}; set b {}; set c {}; set d {}
  590.     scan "  a" " a %d %d %d %d" a b c d
  591.     set b
  592. } {}
  593. test scan-4.14 {error conditions} {
  594.     set a {}; set b {}; set c {}; set d {}
  595.     scan "  a" " a %d %d %d %d" a b c d
  596.     set c
  597. } {}
  598. test scan-4.15 {error conditions} {
  599.     set a {}; set b {}; set c {}; set d {}
  600.     scan "  a" " a %d %d %d %d" a b c d
  601.     set d
  602. } {}
  603. test scan-4.16 {error conditions} {
  604.     set a {}; set b {}; set c {}; set d {}
  605.     scan "1 2" "%d %d %d %d" a b c d
  606. } 2
  607. test scan-4.17 {error conditions} {
  608.     set a {}; set b {}; set c {}; set d {}
  609.     scan "1 2" "%d %d %d %d" a b c d
  610.     set a
  611. } 1
  612. test scan-4.18 {error conditions} {
  613.     set a {}; set b {}; set c {}; set d {}
  614.     scan "1 2" "%d %d %d %d" a b c d
  615.     set b
  616. } 2
  617. test scan-4.19 {error conditions} {
  618.     set a {}; set b {}; set c {}; set d {}
  619.     scan "1 2" "%d %d %d %d" a b c d
  620.     set c
  621. } {}
  622. test scan-4.20 {error conditions} {
  623.     set a {}; set b {}; set c {}; set d {}
  624.     scan "1 2" "%d %d %d %d" a b c d
  625.     set d
  626. } {}
  627. test scan-4.21 {error conditions} {
  628.     catch {unset a}
  629.     set a(0) 44
  630.     list [catch {scan 44 %d a} msg] $msg
  631. } {1 {couldn't set variable "a"}}
  632. test scan-4.22 {error conditions} {
  633.     catch {unset a}
  634.     set a(0) 44
  635.     list [catch {scan 44 %c a} msg] $msg
  636. } {1 {couldn't set variable "a"}}
  637. test scan-4.23 {error conditions} {
  638.     catch {unset a}
  639.     set a(0) 44
  640.     list [catch {scan 44 %s a} msg] $msg
  641. } {1 {couldn't set variable "a"}}
  642. test scan-4.24 {error conditions} {
  643.     catch {unset a}
  644.     set a(0) 44
  645.     list [catch {scan 44 %f a} msg] $msg
  646. } {1 {couldn't set variable "a"}}
  647. test scan-4.25 {error conditions} {
  648.     catch {unset a}
  649.     set a(0) 44
  650.     list [catch {scan 44 %f a} msg] $msg
  651. } {1 {couldn't set variable "a"}}
  652. catch {unset a}
  653. test scan-4.26 {error conditions} {
  654.     list [catch {scan 44 %2c a} msg] $msg
  655. } {1 {field width may not be specified in %c conversion}}
  656.  
  657. test scan-5.1 {lots of arguments} {
  658.     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
  659. } 20
  660. test scan-5.2 {lots of arguments} {
  661.     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
  662.     set a20
  663. } 200
  664.  
  665. test scan-6.1 {miscellaneous tests} {
  666.     set a {}
  667.     list [scan ab16c ab%dc a] $a
  668. } {1 16}
  669. test scan-6.2 {miscellaneous tests} {
  670.     set a {}
  671.     list [scan ax16c ab%dc a] $a
  672. } {0 {}}
  673. test scan-6.3 {miscellaneous tests} {
  674.     set a {}
  675.     list [catch {scan ab%c114 ab%%c%d a} msg] $msg $a
  676. } {0 1 114}
  677. test scan-6.4 {miscellaneous tests} {
  678.     set a {}
  679.     list [catch {scan ab%c14 ab%%c%d a} msg] $msg $a
  680. } {0 1 14}
  681. test scan-6.5 {miscellaneous tests} {
  682.     catch {unset tcl_precision}
  683.     set a {}
  684.     scan 1.111122223333 %f a
  685.     set a
  686. } {1.11112}
  687. test scan-6.6 {miscellaneous tests} {
  688.     set tcl_precision 10
  689.     set a {}
  690.     scan 1.111122223333 %F a
  691.     unset tcl_precision
  692.     set a
  693. } {1.111122223}
  694.