stringcomp.test

来自「tcl是工具命令语言」· TEST 代码 · 共 720 行 · 第 1/2 页

TEST
720
字号
test string-5.19 {string index, bytearray object out of bounds} {    proc foo {} {string index [binary format I* {0x50515253 0x52}] -1}    foo} {}test string-5.20 {string index, bytearray object out of bounds} {    proc foo {} {string index [binary format I* {0x50515253 0x52}] 20}    foo} {}proc largest_int {} {    # This will give us what the largest valid int on this machine is,    # so we can test for overflow properly below on >32 bit systems    set int 1    set exp 7; # assume we get at least 8 bits    while {$int > 0} { set int [expr {1 << [incr exp]}] }    return [expr {$int-1}]}## string is## not yet bccatch {rename largest_int {}}## string last## not yet bc## string length## not yet bctest string-8.1 {string bytelength} {    proc foo {} {string bytelength}    list [catch {foo} msg] $msg} {1 {wrong # args: should be "string bytelength string"}}test string-8.2 {string bytelength} {    proc foo {} {string bytelength a b}    list [catch {foo} msg] $msg} {1 {wrong # args: should be "string bytelength string"}}test string-8.3 {string bytelength} {    proc foo {} {string bytelength "\u00c7"}    foo} 2test string-8.4 {string bytelength} {    proc foo {} {string b ""}    foo} 0## string length##test string-9.1 {string length} {    proc foo {} {string length}    list [catch {foo} msg] $msg} {1 {wrong # args: should be "string length string"}}test string-9.2 {string length} {    proc foo {} {string length a b}    list [catch {foo} msg] $msg} {1 {wrong # args: should be "string length string"}}test string-9.3 {string length} {    proc foo {} {string length "a little string"}    foo} 15test string-9.4 {string length} {    proc foo {} {string le ""}    foo} 0test string-9.5 {string length, unicode} {    proc foo {} {string le "abcd\u7266"}    foo} 5test string-9.6 {string length, bytearray object} {    proc foo {} {string length [binary format a5 foo]}    foo} 5test string-9.7 {string length, bytearray object} {    proc foo {} {string length [binary format I* {0x50515253 0x52}]}    foo} 8## string map## not yet bc## string match##test string-11.1 {string match, too few args} {    proc foo {} {string match a}    list [catch {foo} msg] $msg} {1 {wrong # args: should be "string match ?-nocase? pattern string"}}test string-11.2 {string match, too many args} {    proc foo {} {string match a b c d}    list [catch {foo} msg] $msg} {1 {wrong # args: should be "string match ?-nocase? pattern string"}}test string-11.3 {string match} {    proc foo {} {string match abc abc}    foo} 1test string-11.4 {string match} {    proc foo {} {string mat abc abd}    foo} 0test string-11.5 {string match} {    proc foo {} {string match ab*c abc}    foo} 1test string-11.6 {string match} {    proc foo {} {string match ab**c abc}    foo} 1test string-11.7 {string match} {    proc foo {} {string match ab* abcdef}    foo} 1test string-11.8 {string match} {    proc foo {} {string match *c abc}    foo} 1test string-11.9 {string match} {    proc foo {} {string match *3*6*9 0123456789}    foo} 1test string-11.10 {string match} {    proc foo {} {string match *3*6*9 01234567890}    foo} 0test string-11.11 {string match} {    proc foo {} {string match a?c abc}    foo} 1test string-11.12 {string match} {    proc foo {} {string match a??c abc}    foo} 0test string-11.13 {string match} {    proc foo {} {string match ?1??4???8? 0123456789}    foo} 1test string-11.14 {string match} {    proc foo {} {string match {[abc]bc} abc}    foo} 1test string-11.15 {string match} {    proc foo {} {string match {a[abc]c} abc}    foo} 1test string-11.16 {string match} {    proc foo {} {string match {a[xyz]c} abc}    foo} 0test string-11.17 {string match} {    proc foo {} {string match {12[2-7]45} 12345}    foo} 1test string-11.18 {string match} {    proc foo {} {string match {12[ab2-4cd]45} 12345}    foo} 1test string-11.19 {string match} {    proc foo {} {string match {12[ab2-4cd]45} 12b45}    foo} 1test string-11.20 {string match} {    proc foo {} {string match {12[ab2-4cd]45} 12d45}    foo} 1test string-11.21 {string match} {    proc foo {} {string match {12[ab2-4cd]45} 12145}    foo} 0test string-11.22 {string match} {    proc foo {} {string match {12[ab2-4cd]45} 12545}    foo} 0test string-11.23 {string match} {    proc foo {} {string match {a\*b} a*b}    foo} 1test string-11.24 {string match} {    proc foo {} {string match {a\*b} ab}    foo} 0test string-11.25 {string match} {    proc foo {} {string match {a\*\?\[\]\\\x} "a*?\[\]\\x"}    foo} 1test string-11.26 {string match} {    proc foo {} {string match ** ""}    foo} 1test string-11.27 {string match} {    proc foo {} {string match *. ""}    foo} 0test string-11.28 {string match} {    proc foo {} {string match "" ""}    foo} 1test string-11.29 {string match} {    proc foo {} {string match \[a a}    foo} 1test string-11.30 {string match, bad args} {    proc foo {} {string match - b c}    list [catch {foo} msg] $msg} {1 {bad option "-": must be -nocase}}test string-11.31 {string match case} {    proc foo {} {string match a A}    foo} 0test string-11.32 {string match nocase} {    proc foo {} {string match -n a A}    foo} 1test string-11.33 {string match nocase} {    proc foo {} {string match -nocase a\334 A\374}    foo} 1test string-11.34 {string match nocase} {    proc foo {} {string match -nocase a*f ABCDEf}    foo} 1test string-11.35 {string match case, false hope} {    # This is true because '_' lies between the A-Z and a-z ranges    proc foo {} {string match {[A-z]} _}    foo} 1test string-11.36 {string match nocase range} {    # This is false because although '_' lies between the A-Z and a-z ranges,    # we lower case the end points before checking the ranges.    proc foo {} {string match -nocase {[A-z]} _}    foo} 0test string-11.37 {string match nocase} {    proc foo {} {string match -nocase {[A-fh-Z]} g}    foo} 0test string-11.38 {string match case, reverse range} {    proc foo {} {string match {[A-fh-Z]} g}    foo} 1test string-11.39 {string match, *\ case} {    proc foo {} {string match {*\abc} abc}    foo} 1test string-11.40 {string match, *special case} {    proc foo {} {string match {*[ab]} abc}    foo} 0test string-11.41 {string match, *special case} {    proc foo {} {string match {*[ab]*} abc}    foo} 1test string-11.42 {string match, *special case} {    proc foo {} {string match "*\\" "\\"}    foo} 0test string-11.43 {string match, *special case} {    proc foo {} {string match "*\\\\" "\\"}    foo} 1test string-11.44 {string match, *special case} {    proc foo {} {string match "*???" "12345"}    foo} 1test string-11.45 {string match, *special case} {    proc foo {} {string match "*???" "12"}    foo} 0test string-11.46 {string match, *special case} {    proc foo {} {string match "*\\*" "abc*"}    foo} 1test string-11.47 {string match, *special case} {    proc foo {} {string match "*\\*" "*"}    foo} 1test string-11.48 {string match, *special case} {    proc foo {} {string match "*\\*" "*abc"}    foo} 0test string-11.49 {string match, *special case} {    proc foo {} {string match "?\\*" "a*"}    foo} 1test string-11.50 {string match, *special case} {    proc foo {} {string match "\\" "\\"}    foo} 0test string-11.51 {string match; *, -nocase and UTF-8} {    proc foo {} {string match -nocase [binary format I 717316707] \	    [binary format I 2028036707]}    foo} 1test string-11.52 {string match, null char in string} {    proc foo {} {	set ptn "*abc*"	foreach elem [list "\u0000@abc" "@abc" "\u0000@abc\u0000" "blahabcblah"] {	    lappend out [string match $ptn $elem]	}	set out    }    foo} {1 1 1 1}test string-11.53 {string match, null char in pattern} {    proc foo {} {	set out ""	foreach {ptn elem} [list \		"*\u0000abc\u0000"  "\u0000abc\u0000" \		"*\u0000abc\u0000"  "\u0000abc\u0000ef" \		"*\u0000abc\u0000*" "\u0000abc\u0000ef" \		"*\u0000abc\u0000"  "@\u0000abc\u0000ef" \		"*\u0000abc\u0000*"  "@\u0000abc\u0000ef" \		] {	    lappend out [string match $ptn $elem]	}	set out    }    foo} {1 0 1 0 1}test string-11.54 {string match, failure} {    proc foo {} {	set longString ""	for {set i 0} {$i < 10} {incr i} {	    append longString "abcdefghijklmnopqrstuvwxy\u0000z01234567890123"	}	list [string match *cba* $longString] \		[string match *a*l*\u0000* $longString] \		[string match *a*l*\u0000*123 $longString] \		[string match *a*l*\u0000*123* $longString] \		[string match *a*l*\u0000*cba* $longString] \		[string match *===* $longString]    }    foo} {0 1 1 1 0 0}## string range## not yet bc## string repeat## not yet bc## string replace## not yet bc## string tolower## not yet bc## string toupper## not yet bc## string totitle## not yet bc## string trim*## not yet bc## string word*## not yet bc# cleanup::tcltest::cleanupTestsreturn

⌨️ 快捷键说明

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