⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 format.test

📁 tcl是工具命令语言
💻 TEST
📖 第 1 页 / 共 2 页
字号:
# Commands covered:  format## 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 (c) 1991-1994 The Regents of the University of California.# Copyright (c) 1994-1998 Sun Microsystems, Inc.## See the file "license.terms" for information on usage and redistribution# of this file, and for a DISCLAIMER OF ALL WARRANTIES.## RCS: @(#) $Id: format.test,v 1.11 2002/06/22 04:19:47 dgp Exp $if {[lsearch [namespace children] ::tcltest] == -1} {    package require tcltest 2    namespace import -force ::tcltest::*}# The following code is needed because some versions of SCO Unix have# a round-off error in sprintf which would cause some of the tests to# fail.  Someday I hope this code shouldn't be necessary (code added# 9/9/91).set ::tcltest::testConstraints(roundOffBug) \	[expr {"[format %7.1e  68.514]" != "6.8e+01"}]test format-1.1 {integer formatting} {    format "%*d %d %d %d" 6 34 16923 -12 -1} {    34 16923 -12 -1}test format-1.2 {integer formatting} {nonPortable} {    format "%4d %4d %4d %4d %d %#x %#X" 6 34 16923 -12 -1 14 12} {   6   34 16923  -12 -1 0xe 0XC}# %u output depends on word length, so this test is not portable.test format-1.3 {integer formatting} {nonPortable} {    format "%4u %4u %4u %4u %d %#o" 6 34 16923 -12 -1 0} {   6   34 16923 4294967284 -1 0}test format-1.4 {integer formatting} {    format "%-4d %-4i %-4d %-4ld" 6 34 16923 -12 -1} {6    34   16923 -12 }test format-1.5 {integer formatting} {    format "%04d %04d %04d %04i" 6 34 16923 -12 -1} {0006 0034 16923 -012}test format-1.6 {integer formatting} {    format "%00*d" 6 34} {000034}# Printing negative numbers in hex or octal format depends on word# length, so these tests are not portable.test format-1.7 {integer formatting} {nonPortable} {    format "%4x %4x %4x %4x" 6 34 16923 -12 -1} {   6   22 421b fffffff4}test format-1.8 {integer formatting} {nonPortable} {    format "%#x %#X %#X %#x" 6 34 16923 -12 -1} {0x6 0X22 0X421B 0xfffffff4}test format-1.9 {integer formatting} {nonPortable} {    format "%#20x %#20x %#20x %#20x" 6 34 16923 -12 -1} {                 0x6                 0x22               0x421b           0xfffffff4}test format-1.10 {integer formatting} {nonPortable} {    format "%-#20x %-#20x %-#20x %-#20x" 6 34 16923 -12 -1} {0x6                  0x22                 0x421b               0xfffffff4          }test format-1.11 {integer formatting} {nonPortable} {    format "%-#20o %#-20o %#-20o %#-20o" 6 34 16923 -12 -1} {06                   042                  041033               037777777764        }test format-2.1 {string formatting} {    format "%s %s %c %s" abcd {This is a very long test string.} 120 x} {abcd This is a very long test string. x x}test format-2.2 {string formatting} {    format "%20s %20s %20c %20s" abcd {This is a very long test string.} 120 x} {                abcd This is a very long test string.                    x                    x}test format-2.3 {string formatting} {    format "%.10s %.10s %c %.10s" abcd {This is a very long test string.} 120 x} {abcd This is a  x x}test format-2.4 {string formatting} {    format "%s %s %% %c %s" abcd {This is a very long test string.} 120 x} {abcd This is a very long test string. % x x}test format-2.5 {string formatting, embedded nulls} {    format "%10s" abc\0def} "   abc\0def"test format-2.6 {string formatting, international chars} {    format "%10s" abc\ufeffdef} "   abc\ufeffdef"test format-2.6 {string formatting, international chars} {    format "%.5s" abc\ufeffdef} "abc\ufeffd"test format-2.7 {string formatting, international chars} {    format "foo\ufeffbar%s" baz} "foo\ufeffbarbaz"test format-2.8 {string formatting, width} {    format "a%5sa" f} "a    fa"test format-2.8 {string formatting, width} {    format "a%-5sa" f} "af    a"test format-2.8 {string formatting, width} {    format "a%2sa" foo} "afooa"test format-2.8 {string formatting, width} {    format "a%0sa" foo} "afooa"test format-2.8 {string formatting, precision} {    format "a%.2sa" foobarbaz} "afoa"test format-2.8 {string formatting, precision} {    format "a%.sa" foobarbaz} "aa"test format-2.8 {string formatting, precision} {    list [catch {format "a%.-2sa" foobarbaz} msg] $msg} {1 {bad field specifier "-"}}test format-2.8 {string formatting, width and precision} {    format "a%5.2sa" foobarbaz} "a   foa"test format-2.8 {string formatting, width and precision} {    format "a%5.7sa" foobarbaz} "afoobarba"test format-3.1 {Tcl_FormatObjCmd: character formatting} {    format "|%c|%0c|%-1c|%1c|%-6c|%6c|%*c|%*c|" 65 65 65 65 65 65 3 65 -4 65} "|A|A|A|A|A     |     A|  A|A   |"test format-3.2 {Tcl_FormatObjCmd: international character formatting} {    format "|%c|%0c|%-1c|%1c|%-6c|%6c|%*c|%*c|" 0xa2 0x4e4e 0x25a 0xc3 0xff08 0 3 0x6575 -4 0x4e4f} "|\ua2|\u4e4e|\u25a|\uc3|\uff08     |     \0|  \u6575|\u4e4f   |"test format-4.1 {e and f formats} {eformat} {    format "%e %e %e %e" 34.2e12 68.514 -.125 -16000. .000053} {3.420000e+13 6.851400e+01 -1.250000e-01 -1.600000e+04}test format-4.2 {e and f formats} {eformat} {    format "%20e %20e %20e %20e" 34.2e12 68.514 -.125 -16000. .000053} {        3.420000e+13         6.851400e+01        -1.250000e-01        -1.600000e+04}test format-4.3 {e and f formats} {eformat roundOffBug} {    format "%.1e %.1e %.1e %.1e" 34.2e12 68.514 -.126 -16000. .000053} {3.4e+13 6.9e+01 -1.3e-01 -1.6e+04}test format-4.4 {e and f formats} {eformat roundOffBug} {    format "%020e %020e %020e %020e" 34.2e12 68.514 -.126 -16000. .000053} {000000003.420000e+13 000000006.851400e+01 -00000001.260000e-01 -00000001.600000e+04}test format-4.5 {e and f formats} {eformat roundOffBug} {    format "%7.1e %7.1e %7.1e %7.1e" 34.2e12 68.514 -.126 -16000. .000053} {3.4e+13 6.9e+01 -1.3e-01 -1.6e+04}test format-4.6 {e and f formats roundOffBug} {    format "%f %f %f %f" 34.2e12 68.514 -.125 -16000. .000053} {34200000000000.000000 68.514000 -0.125000 -16000.000000}test format-4.7 {e and f formats} {nonPortable} {    format "%.4f %.4f %.4f %.4f %.4f" 34.2e12 68.514 -.125 -16000. .000053} {34200000000000.0000 68.5140 -0.1250 -16000.0000 0.0001}test format-4.8 {e and f formats} {eformat} {    format "%.4e %.5e %.6e" -9.99996 -9.99996 9.99996} {-1.0000e+01 -9.99996e+00 9.999960e+00}test format-4.9 {e and f formats} {    format "%.4f %.5f %.6f" -9.99996 -9.99996 9.99996} {-10.0000 -9.99996 9.999960}test format-4.10 {e and f formats} {    format "%20f %-20f %020f" -9.99996 -9.99996 9.99996} {           -9.999960 -9.999960            0000000000009.999960}test format-4.11 {e and f formats} {    format "%-020f %020f" -9.99996 -9.99996 9.99996} {-9.999960            -000000000009.999960}test format-4.12 {e and f formats} {eformat} {    format "%.0e %#.0e" -9.99996 -9.99996 9.99996} {-1e+01 -1.e+01}test format-4.13 {e and f formats} {    format "%.0f %#.0f" -9.99996 -9.99996 9.99996} {-10 -10.}test format-4.14 {e and f formats} {    format "%.4f %.5f %.6f" -9.99996 -9.99996 9.99996} {-10.0000 -9.99996 9.999960}test format-4.15 {e and f formats} {    format "%3.0f %3.0f %3.0f %3.0f" 1.0 1.1 1.01 1.001} {  1   1   1   1}test format-4.16 {e and f formats} {    format "%3.1f %3.1f %3.1f %3.1f" 0.0 0.1 0.01 0.001} {0.0 0.1 0.0 0.0}test format-5.1 {g-format} {eformat} {    format "%.3g" 12341.0} {1.23e+04}test format-5.2 {g-format} {eformat} {    format "%.3G" 1234.12345} {1.23E+03}test format-5.3 {g-format} {    format "%.3g" 123.412345} {123}test format-5.4 {g-format} {    format "%.3g" 12.3412345} {12.3}test format-5.5 {g-format} {    format "%.3g" 1.23412345} {1.23}test format-5.6 {g-format} {    format "%.3g" 1.23412345} {1.23}test format-5.7 {g-format} {    format "%.3g" .123412345} {0.123}test format-5.8 {g-format} {    format "%.3g" .012341} {0.0123}test format-5.9 {g-format} {    format "%.3g" .0012341} {0.00123}test format-5.10 {g-format} {    format "%.3g" .00012341} {0.000123}test format-5.11 {g-format} {eformat} {    format "%.3g" .00001234} {1.23e-05}test format-5.12 {g-format} {eformat} {    format "%.4g" 9999.6} {1e+04}test format-5.13 {g-format} {    format "%.4g" 999.96} {1000}test format-5.14 {g-format} {    format "%.3g" 1.0} {1}test format-5.15 {g-format} {    format "%.3g" .1} {0.1}test format-5.16 {g-format} {    format "%.3g" .01} {0.01}test format-5.17 {g-format} {    format "%.3g" .001} {0.001}test format-5.18 {g-format} {eformat} {    format "%.3g" .00001} {1e-05}test format-5.19 {g-format} {eformat} {    format "%#.3g" 1234.0} {1.23e+03}test format-5.20 {g-format} {eformat} {    format "%#.3G" 9999.5} {1.00E+04}test format-6.1 {floating-point zeroes} {eformat} {    format "%e %f %g" 0.0 0.0 0.0 0.0} {0.000000e+00 0.000000 0}test format-6.2 {floating-point zeroes} {eformat} {    format "%.4e %.4f %.4g" 0.0 0.0 0.0 0.0} {0.0000e+00 0.0000 0}test format-6.3 {floating-point zeroes} {eformat} {    format "%#.4e %#.4f %#.4g" 0.0 0.0 0.0 0.0} {0.0000e+00 0.0000 0.000}test format-6.4 {floating-point zeroes} {eformat} {    format "%.0e %.0f %.0g" 0.0 0.0 0.0 0.0} {0e+00 0 0}test format-6.5 {floating-point zeroes} {eformat} {    format "%#.0e %#.0f %#.0g" 0.0 0.0 0.0 0.0} {0.e+00 0. 0.}test format-6.6 {floating-point zeroes} {    format "%3.0f %3.0f %3.0f %3.0f" 0.0 0.0 0.0 0.0} {  0   0   0   0}test format-6.7 {floating-point zeroes} {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -