summaryrefslogtreecommitdiffstats
path: root/tests/unicode.test
blob: 6ee91c8289b8015e479b8b0ae686cb9127cb888e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# This file tests the tclUnicode.c file. 
#
# 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) 1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: unicode.test,v 1.2 1999/06/08 02:59:30 hershey Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    source [file join [pwd] [file dirname [info script]] defs.tcl]
}

# Some tests require the testobj command

set ::tcltest::testConfig(testobj) \
	[expr {[info commands testobj] != {}}]

test unicode-1.1 {TclGetUniCharFromObj with byte-size chars} {
    string index "abcdefghi" 0
} "a"
test unicode-1.2 {TclGetUniCharFromObj with byte-size chars} {
    string index "abcdefghi" 3
} "d"
test unicode-1.3 {TclGetUniCharFromObj with byte-size chars} {
    string index "abcdefghi" end
} "i"
test unicode-1.4 {TclGetUniCharFromObj with mixed width chars} {
    string index "ïa¿b®c®¿dï" 0
} "ï"
test unicode-1.5 {TclGetUniCharFromObj} {
    string index "ïa¿b®c®¿dï" 4
} "®"
test unicode-1.6 {TclGetUniCharFromObj} {
    string index "ïa¿b®cï¿d®" end
} "®"

test unicode-2.1 {TclGetUnicodeLengthFromObj with byte-size chars} {
    string length "" 
} 0
test unicode-2.2 {TclGetUnicodeLengthFromObj with byte-size chars} {
    string length "a"
} 1
test unicode-2.3 {TclGetUnicodeLengthFromObj with byte-size chars} {
    string length "abcdef"
} 6
test unicode-2.4 {TclGetUnicodeLengthFromObj with mixed width chars} {
    string length "®" 
} 1
test unicode-2.5 {TclGetUnicodeLengthFromObj with mixed width chars} {
    string length "○○" 
} 6
test unicode-2.6 {TclGetUnicodeLengthFromObj with mixed width chars} {
    string length "ïa¿b®cï¿d®" 
} 10

test unicode-3.1 {TclGetRangeFromObj with all byte-size chars} {testobj} {
    set x "abcdef"
    list [testobj objtype $x] [set y [string range $x 1 end-1]] \
	    [testobj objtype $x] [testobj objtype $y]
} {none bcde unicode none}

test unicode-3.2 {TclGetRangeFromObj with some mixed width chars} {testobj} {
    set x "abcïïdef"
    list [testobj objtype $x] [set y [string range $x 1 end-1]] \
	    [testobj objtype $x] [testobj objtype $y]
} {none bcïïde unicode unicode}

test unicode-4.1 {UpdateStringOfUnicode} {testobj} {
    set x 2345
    list [string index $x end] [testobj objtype $x] [incr x] \
	    [testobj objtype $x]
} {5 unicode 2346 int}

test unicode-5.1 {SetUnicodeFromAny called with non-unicode obj} {testobj} {
    set x 2345
    list [incr x] [testobj objtype $x] [string index $x end] \
	    [testobj objtype $x]
} {2346 int 6 unicode}

test unicode-5.2 {SetUnicodeFromAny called with unicode obj} {testobj} {
    set x "abcdef"
    list [string length $x] [testobj objtype $x] \
	    [string length $x] [testobj objtype $x]
} {6 unicode 6 unicode}

test unicode-6.1 {DupUnicodeInternalRep, mixed width chars} {testobj} {
    set x abcï¿®ghi
    string length $x
    set y $x
    list [testobj objtype $x] [testobj objtype $y] [append x "®¿ï"] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode unicode abcï¿®ghi®¿ï abcï¿®ghi unicode unicode}

test unicode-6.2 {DupUnicodeInternalRep, mixed width chars} {testobj} {
    set x abcï¿®ghi
    set y $x
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x "®¿ï"] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode unicode abcï¿®ghi®¿ï abcï¿®ghi unicode unicode}

test unicode-6.3 {DupUnicodeInternalRep, all byte-size chars} {testobj} {
    set x abcdefghi
    string length $x
    set y $x
    list [testobj objtype $x] [testobj objtype $y] [append x jkl] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode unicode abcdefghijkl abcdefghi unicode unicode}

test unicode-6.4 {DupUnicodeInternalRep, all byte-size chars} {testobj} {
    set x abcdefghi
    set y $x
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x jkl] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode unicode abcdefghijkl abcdefghi unicode unicode}

test unicode-7.1 {TclAppendObjToUnicodeObj, mixed src & dest} {testobj} {
    set x abcï¿®ghi
    set y ®¿ï
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode none abcï¿®ghi®¿ï ®¿ï unicode unicode}

test unicode-7.2 {TclAppendObjToUnicodeObj, mixed src & dest} {testobj} {
    set x abcï¿®ghi
    string length $x
    list [testobj objtype $x] [append x $x] [testobj objtype $x] \
	    [append x $x] [testobj objtype $x]
} {unicode abcï¿®ghiabcï¿®ghi unicode\
abcï¿®ghiabcï¿®ghiabcï¿®ghiabcï¿®ghi\
unicode}

test unicode-7.3 {TclAppendObjToUnicodeObj, mixed src & 1-byte dest} {testobj} {
    set x abcdefghi
    set y ®¿ï
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode none abcdefghi®¿ï ®¿ï string unicode}

test unicode-7.4 {TclAppendObjToUnicodeObj, 1-byte src & dest} {testobj} {
    set x abcdefghi
    set y jkl
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode none abcdefghijkl jkl unicode unicode}

test unicode-7.5 {TclAppendObjToUnicodeObj, 1-byte src & dest} {testobj} {
    set x abcdefghi
    string length $x
    list [testobj objtype $x] [append x $x] [testobj objtype $x] \
	    [append x $x] [testobj objtype $x]
} {unicode abcdefghiabcdefghi unicode abcdefghiabcdefghiabcdefghiabcdefghi\
unicode}

test unicode-7.6 {TclAppendObjToUnicodeObj, 1-byte src & mixed dest} {testobj} {
    set x abcï¿®ghi
    set y jkl
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode none abcï¿®ghijkl jkl unicode unicode}

test unicode-7.7 {TclAppendObjToUnicodeObj, integer src & dest} {testobj} {
    set x [expr {4 * 5}]
    set y [expr {4 + 5}]
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [testobj objtype $x] [append x $y] [testobj objtype $x] \
	    [testobj objtype $y]
} {int int 209 string 2099 string int}

test unicode-7.8 {TclAppendObjToUnicodeObj, integer src & dest} {testobj} {
    set x [expr {4 * 5}]
    list [testobj objtype $x] [append x $x] [testobj objtype $x] \
	    [append x $x] [testobj objtype $x]
} {int 2020 string 20202020 unicode}

test unicode-7.9 {TclAppendObjToUnicodeObj, integer src & 1-byte dest} {testobj} {
    set x abcdefghi
    set y [expr {4 + 5}]
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode int abcdefghi9 9 string int}

test unicode-7.10 {TclAppendObjToUnicodeObj, integer src & mixed dest} {testobj} {
    set x abcï¿®ghi
    set y [expr {4 + 5}]
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode int abcï¿®ghi9 9 unicode int}

# cleanup
::tcltest::cleanupTests
return