Fossil SCM
Make utf.test work with Tcl 9. Not sure if this is the best fix, but it does seem to work with 8.6 as well under assorted inputs.
Commit
ab45d34c9dd727cc609659cab15f8f50826c8efee958b0db121eb25288fe0575
Parent
098e61579f75d94…
1 file changed
+28
-6
+28
-6
| --- test/utf.test | ||
| +++ test/utf.test | ||
| @@ -285,30 +285,52 @@ | ||
| 285 | 285 | incr fn |
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | + | |
| 291 | +# Returns S converted to the encoding ENC. Tcl 9 refuses an unpaired | |
| 292 | +# surrogate unless the conversion uses the tcl8 profile, which Tcl 8 does | |
| 293 | +# not have. | |
| 294 | +proc convert_to {enc s} { | |
| 295 | + if {[package vsatisfies [package provide Tcl] 9-]} { | |
| 296 | + return [encoding convertto -profile tcl8 $enc $s] | |
| 297 | + } | |
| 298 | + return [encoding convertto $enc $s] | |
| 299 | +} | |
| 300 | + | |
| 301 | +# Returns the bytes that Tcl 8 writes for S to a channel in the binary | |
| 302 | +# encoding: the low byte of each UTF-16 unit. Tcl 9 does not have the | |
| 303 | +# binary encoding. | |
| 304 | +proc binary_bytes {s} { | |
| 305 | + if {![package vsatisfies [package provide Tcl] 9-]} { | |
| 306 | + return $s | |
| 307 | + } | |
| 308 | + set format [expr {$::tcl_platform(byteOrder) eq "littleEndian" ? "s*" : "S*"}] | |
| 309 | + binary scan [convert_to unicode $s] $format units | |
| 310 | + return [binary format c* $units] | |
| 311 | +} | |
| 290 | 312 | |
| 291 | 313 | proc createTestFiles {path num} { |
| 292 | 314 | set fn $num |
| 293 | 315 | for {set i 0} {$i < [array size ::bom]} {incr i} { |
| 294 | 316 | for {set j 0} {$j < [array size ::data]} {incr j} { |
| 295 | 317 | for {set k 0} {$k < [array size ::extraData]} {incr k} { |
| 296 | 318 | set f [open [file join $path utf-check-$fn-$i-$j-$k.jnk] \ |
| 297 | 319 | {WRONLY CREAT TRUNC}]; incr fn |
| 298 | - fconfigure $f -encoding binary -translation binary | |
| 320 | + fconfigure $f -translation binary | |
| 299 | 321 | puts -nonewline $f $::bom($i) |
| 300 | 322 | switch -exact $::enc($i) { |
| 301 | 323 | binary { |
| 302 | - puts -nonewline $f $::data($j) | |
| 324 | + puts -nonewline $f [binary_bytes $::data($j)] | |
| 303 | 325 | } |
| 304 | 326 | unicode-reverse { |
| 305 | - puts -nonewline $f [swap_byte_order \ | |
| 306 | - [encoding convertto unicode $::data($j)]] | |
| 327 | + puts -nonewline $f [binary_bytes \ | |
| 328 | + [swap_byte_order [convert_to unicode $::data($j)]]] | |
| 307 | 329 | } |
| 308 | 330 | default { |
| 309 | - puts -nonewline $f [encoding convertto $::enc($i) $::data($j)] | |
| 331 | + puts -nonewline $f [convert_to $::enc($i) $::data($j)] | |
| 310 | 332 | } |
| 311 | 333 | } |
| 312 | 334 | puts -nonewline $f $::extraData($k) |
| 313 | 335 | flush $f; close $f |
| 314 | 336 | } |
| @@ -326,11 +348,11 @@ | ||
| 326 | 348 | set f [open [file join $path utf-check.txt] {WRONLY CREAT APPEND}] |
| 327 | 349 | set fn $num |
| 328 | 350 | for {set i 0} {$i < [array size ::bom]} {incr i} { |
| 329 | 351 | for {set j 0} {$j < [array size ::data]} {incr j} { |
| 330 | 352 | for {set k 0} {$k < [array size ::extraData]} {incr k} { |
| 331 | - fconfigure $f -encoding binary -translation binary | |
| 353 | + fconfigure $f -translation binary | |
| 332 | 354 | set data \n\n |
| 333 | 355 | append data {utf-check $fn } |
| 334 | 356 | append data {utf-check-$fn-$i-$j-$k.jnk \\\n} |
| 335 | 357 | append data {{%OUT%}} |
| 336 | 358 | fossil test-looks-like-utf [file join $path utf-check-$fn-$i-$j-$k.jnk] |
| 337 | 359 |
| --- test/utf.test | |
| +++ test/utf.test | |
| @@ -285,30 +285,52 @@ | |
| 285 | incr fn |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | proc createTestFiles {path num} { |
| 292 | set fn $num |
| 293 | for {set i 0} {$i < [array size ::bom]} {incr i} { |
| 294 | for {set j 0} {$j < [array size ::data]} {incr j} { |
| 295 | for {set k 0} {$k < [array size ::extraData]} {incr k} { |
| 296 | set f [open [file join $path utf-check-$fn-$i-$j-$k.jnk] \ |
| 297 | {WRONLY CREAT TRUNC}]; incr fn |
| 298 | fconfigure $f -encoding binary -translation binary |
| 299 | puts -nonewline $f $::bom($i) |
| 300 | switch -exact $::enc($i) { |
| 301 | binary { |
| 302 | puts -nonewline $f $::data($j) |
| 303 | } |
| 304 | unicode-reverse { |
| 305 | puts -nonewline $f [swap_byte_order \ |
| 306 | [encoding convertto unicode $::data($j)]] |
| 307 | } |
| 308 | default { |
| 309 | puts -nonewline $f [encoding convertto $::enc($i) $::data($j)] |
| 310 | } |
| 311 | } |
| 312 | puts -nonewline $f $::extraData($k) |
| 313 | flush $f; close $f |
| 314 | } |
| @@ -326,11 +348,11 @@ | |
| 326 | set f [open [file join $path utf-check.txt] {WRONLY CREAT APPEND}] |
| 327 | set fn $num |
| 328 | for {set i 0} {$i < [array size ::bom]} {incr i} { |
| 329 | for {set j 0} {$j < [array size ::data]} {incr j} { |
| 330 | for {set k 0} {$k < [array size ::extraData]} {incr k} { |
| 331 | fconfigure $f -encoding binary -translation binary |
| 332 | set data \n\n |
| 333 | append data {utf-check $fn } |
| 334 | append data {utf-check-$fn-$i-$j-$k.jnk \\\n} |
| 335 | append data {{%OUT%}} |
| 336 | fossil test-looks-like-utf [file join $path utf-check-$fn-$i-$j-$k.jnk] |
| 337 |
| --- test/utf.test | |
| +++ test/utf.test | |
| @@ -285,30 +285,52 @@ | |
| 285 | incr fn |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | # Returns S converted to the encoding ENC. Tcl 9 refuses an unpaired |
| 292 | # surrogate unless the conversion uses the tcl8 profile, which Tcl 8 does |
| 293 | # not have. |
| 294 | proc convert_to {enc s} { |
| 295 | if {[package vsatisfies [package provide Tcl] 9-]} { |
| 296 | return [encoding convertto -profile tcl8 $enc $s] |
| 297 | } |
| 298 | return [encoding convertto $enc $s] |
| 299 | } |
| 300 | |
| 301 | # Returns the bytes that Tcl 8 writes for S to a channel in the binary |
| 302 | # encoding: the low byte of each UTF-16 unit. Tcl 9 does not have the |
| 303 | # binary encoding. |
| 304 | proc binary_bytes {s} { |
| 305 | if {![package vsatisfies [package provide Tcl] 9-]} { |
| 306 | return $s |
| 307 | } |
| 308 | set format [expr {$::tcl_platform(byteOrder) eq "littleEndian" ? "s*" : "S*"}] |
| 309 | binary scan [convert_to unicode $s] $format units |
| 310 | return [binary format c* $units] |
| 311 | } |
| 312 | |
| 313 | proc createTestFiles {path num} { |
| 314 | set fn $num |
| 315 | for {set i 0} {$i < [array size ::bom]} {incr i} { |
| 316 | for {set j 0} {$j < [array size ::data]} {incr j} { |
| 317 | for {set k 0} {$k < [array size ::extraData]} {incr k} { |
| 318 | set f [open [file join $path utf-check-$fn-$i-$j-$k.jnk] \ |
| 319 | {WRONLY CREAT TRUNC}]; incr fn |
| 320 | fconfigure $f -translation binary |
| 321 | puts -nonewline $f $::bom($i) |
| 322 | switch -exact $::enc($i) { |
| 323 | binary { |
| 324 | puts -nonewline $f [binary_bytes $::data($j)] |
| 325 | } |
| 326 | unicode-reverse { |
| 327 | puts -nonewline $f [binary_bytes \ |
| 328 | [swap_byte_order [convert_to unicode $::data($j)]]] |
| 329 | } |
| 330 | default { |
| 331 | puts -nonewline $f [convert_to $::enc($i) $::data($j)] |
| 332 | } |
| 333 | } |
| 334 | puts -nonewline $f $::extraData($k) |
| 335 | flush $f; close $f |
| 336 | } |
| @@ -326,11 +348,11 @@ | |
| 348 | set f [open [file join $path utf-check.txt] {WRONLY CREAT APPEND}] |
| 349 | set fn $num |
| 350 | for {set i 0} {$i < [array size ::bom]} {incr i} { |
| 351 | for {set j 0} {$j < [array size ::data]} {incr j} { |
| 352 | for {set k 0} {$k < [array size ::extraData]} {incr k} { |
| 353 | fconfigure $f -translation binary |
| 354 | set data \n\n |
| 355 | append data {utf-check $fn } |
| 356 | append data {utf-check-$fn-$i-$j-$k.jnk \\\n} |
| 357 | append data {{%OUT%}} |
| 358 | fossil test-looks-like-utf [file join $path utf-check-$fn-$i-$j-$k.jnk] |
| 359 |