From e9198f72c74919038c5b5c5f902f3b28b0679590 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 28 Mar 2024 21:12:46 +0000 Subject: Asciify string.test. tcltest::fileEncoding is thus no longer necessary (which would have performance effect for _all_ testcases) --- library/tcltest/tcltest.tcl | 50 ++------------------------------------------- tests/string.test | 16 +++++++-------- 2 files changed, 9 insertions(+), 57 deletions(-) diff --git a/library/tcltest/tcltest.tcl b/library/tcltest/tcltest.tcl index 1d31548..12b0976 100644 --- a/library/tcltest/tcltest.tcl +++ b/library/tcltest/tcltest.tcl @@ -2844,49 +2844,6 @@ proc tcltest::GetMatchingDirectories {rootdir} { return [lsort $matchDirs] } -# tcltest::fileEncoding -- -# -# checks the file contains BOM (or coding header) -# and returns -encoding utf-8 (or enconding), -# otherwise an empty list -# -# Typical header for coding: -# # -*- coding: utf-8 -*- -# -# For similarity with Tcl this will be also supported: -# # -encoding utf-8 ... -# #!/usr/bin/env tclsh -encoding utf-8 ... -# -# Arguments: -# name of the file to check encoding -# -# Results: -# -encoding utf-8, -encoding $enc or empty -# -# Side effects: -# None. - -proc tcltest::fileEncoding {name} { - variable fullutf - - set f [open $name rb] - try { - set buf [read $f 3] - # contains BOM? - if {$buf eq "\xEF\xBB\xBF"} { - return {-encoding utf-8} - } - # read 2 lines in header (may contain shebang and coding hereafter): - append buf [gets $f] \n [gets $f] - if {[regexp -line {^#+(?:!\S+(?: \S+){0,2})? [-\*\s]*(?:en)?coding:? ([\w\-]+)} $buf {} enc]} { - return [list -encoding $enc] - } - } finally { - close $f - } - return {} -} - # tcltest::runAllTests -- # # prints output and sources test files according to the match and @@ -2963,13 +2920,10 @@ proc tcltest::runAllTests { {shell ""} } { puts [outputChannel] $tail flush [outputChannel] - # get encoding of file (BOM or coding in header): - set fenc [fileEncoding $file] - if {[singleProcess]} { if {[catch { incr numTestFiles - uplevel 1 [list ::source {*}$fenc $file] + uplevel 1 [list ::source $file] } msg]} { puts [outputChannel] "Test file error: $msg" # append the name of the test to a list to be reported @@ -2993,7 +2947,7 @@ proc tcltest::runAllTests { {shell ""} } { } lappend childargv $opt $value } - set cmd [linsert $childargv 0 | $shell {*}$fenc $file] + set cmd [linsert $childargv 0 | $shell $file] if {[catch { incr numTestFiles set pipeFd [open $cmd "r"] diff --git a/tests/string.test b/tests/string.test index e03622d..6b66ebb 100644 --- a/tests/string.test +++ b/tests/string.test @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # Commands covered: string # # This file contains a collection of tests for one or more of the Tcl @@ -254,16 +252,16 @@ test string-3.15.$noComp {string equal with special index} { } {1 {expected integer but got "end-3"}} test string-3.16.$noComp {string equal, unicode} { - run {string equal ab牦 ab牧} + run {string equal ab\u7266 ab\u7267} } 0 test string-3.17.$noComp {string equal, unicode} { - run {string equal Ü Ü} + run {string equal \xDC \xDC} } 1 test string-3.18.$noComp {string equal, unicode} { - run {string equal Ü ü} + run {string equal \xDC \xFC} } 0 test string-3.19.$noComp {string equal, unicode} { - run {string equal ÜÜÜüü ÜÜÜÜÜ} + run {string equal \xDC\xDC\xDC\xFC\xFC \xDC\xDC\xDC\xDC\xDC} } 0 test string-3.20.$noComp {string equal, high bit} { # This test fails if the underlying comparison @@ -278,10 +276,10 @@ test string-3.21.$noComp {string equal -nocase} { run {string equal -nocase abcde Abdef} } 0 test string-3.22.$noComp {string equal, -nocase unicode} { - run {string equal -nocase Ü Ü} + run {string equal -nocase \xDC \xDC} } 1 test string-3.23.$noComp {string equal, -nocase unicode} { - run {string equal -nocase ÜÜÜüü ÜÜÜÜÜ} + run {string equal -nocase \xDC\xDC\xDC\xFC\xFC \xDC\xDC\xDC\xDC\xDC} } 1 test string-3.24.$noComp {string equal -nocase with length} { run {string equal -length 2 -nocase abcde Abxyz} @@ -298,7 +296,7 @@ test string-3.27.$noComp {string equal -nocase with excessive length} { test string-3.28.$noComp {string equal -len unicode} { # These are strings that are 6 BYTELENGTH long, but the length # shouldn't make a different because there are actually 3 CHARS long - run {string equal -len 5 ÜÜÜ ÜÜü} + run {string equal -len 5 \xDC\xDC\xDC \xDC\xDC\xFC} } 0 test string-3.29.$noComp {string equal -nocase with special index} { list [catch {run {string equal -nocase -length end-3 Abcde abxyz}} msg] $msg -- cgit v0.12