1 (* Auxiliary functions for test cases
*)
5 fun check b
= if b
then "OK" else "WRONG";
6 fun check
' f
= (if f () then "OK" else "WRONG") (* handle _
=> "EXN" *);
8 fun range (from
, to
) p
=
11 (from
> to
) orelse (p from
) andalso (range (from
+1, to
) p
)
14 fun checkrange bounds
= check
o range bounds
;
16 fun tst0 s s
' = print (s ^
" \t" ^ s
' ^
"\n");
17 fun tst s b
= tst0
s (check b
);
18 fun tst
' s f
= tst0
s (check
' f
);
20 fun tstrange s bounds
= (tst s
) o range bounds
22 (* test
/widechar
.sml
-- test cases WideChar
, suitable for ASCII
23 PS
1994-12-10, 1995-05-11, 1995-11-10, 1996-09-30 *)
25 (*KILL
05/11/1997 10:55. tho
.:
29 val _
= print
"File widechar.sml: Testing structure WideChar...\n"
31 val test4
= tstrange
"test4" (0, WideChar
.maxOrd
)
32 (fn i
=> (WideChar
.ord
o WideChar
.chr
) i
= i
);
34 val test5
= tst0
"test5" ((WideChar
.chr ~
1 seq
"WRONG") handle Chr
=> "OK" | _
=> "WRONG")
36 val test6
= tst0
"test6" ((WideChar
.chr (WideChar
.maxOrd
+1) seq
"WRONG")
37 handle Chr
=> "OK" | _
=> "WRONG")
39 val test18
= tst
"test18" (not (WideChar
.contains
"" (WideChar
.chr
65))
40 andalso not (WideChar
.contains
"aBCDE" (WideChar
.chr
65))
41 andalso (WideChar
.contains
"ABCD" (WideChar
.chr
67))
42 andalso not (WideChar
.contains
"" #
"\000")
43 andalso not (WideChar
.contains
"" #
"\255")
44 andalso not (WideChar
.contains
"azAZ09" #
"\000")
45 andalso not (WideChar
.contains
"azAZ09" #
"\255"));
47 val test19
= tst
"test19" (WideChar
.notContains
"" (WideChar
.chr
65)
48 andalso WideChar
.notContains
"aBCDE" (WideChar
.chr
65)
49 andalso not (WideChar
.notContains
"ABCD" (WideChar
.chr
67))
50 andalso WideChar
.notContains
"" #
"\000"
51 andalso WideChar
.notContains
"" #
"\255"
52 andalso WideChar
.notContains
"azAZ09" #
"\000"
53 andalso WideChar
.notContains
"azAZ09" #
"\255");
55 val test20
= tst
"test20" (WideChar
.ord WideChar
.maxChar
= WideChar
.maxOrd
);
59 let val stop
= WideString
.size s
60 fun h i
= i
< stop
andalso (c
= WideString
.sub(s
, i
) orelse h(i
+1))
63 (* Check that
p(c
) = (mycontains s c
) for all characters
: *)
67 (p (WideChar
.chr n
) = mycontains
s (WideChar
.chr n
)) andalso h(n
+1)
70 fun checkset p s
= tst
' "checkset" (fn _
=> equivalent p s
);
72 val graphchars
: WideString
.string
73 = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\
74 \[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
76 val ascii
= "\^@\^A\^B\^C\^D\^E\^F\^G\^H\t\n\^K\^L\^M\^N\^O\^P\
77 \\^Q\^R\^S\^T\^U\^V\^W\^X\^Y\^Z\^[\^\\^]\^^\^_\
78 \ !\"#$%&'()*+,-./0123456789:;<=>?@\
79 \ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\127"
81 val lowerascii
= "\^@\^A\^B\^C\^D\^E\^F\^G\^H\t\n\^K\^L\^M\^N\^O\^P\
82 \\^Q\^R\^S\^T\^U\^V\^W\^X\^Y\^Z\^[\^\\^]\^^\^_\
83 \ !\"#$%&'()*+,-./0123456789:;<=>?@\
84 \abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\127"
86 val upperascii
= "\^@\^A\^B\^C\^D\^E\^F\^G\^H\t\n\^K\^L\^M\^N\^O\^P\
87 \\^Q\^R\^S\^T\^U\^V\^W\^X\^Y\^Z\^[\^\\^]\^^\^_\
88 \ !\"#$%&'()*+,-./0123456789:;<=>?@\
89 \ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~\127"
92 let fun h
0 res
= WideChar
.chr
0 :: res
93 | h n res
= h (n
-1) (WideChar
.chr n
:: res
)
100 checkset isLower
"abcdefghijklmnopqrstuvwxyz";
102 checkset isUpper
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
104 checkset isDigit
"0123456789";
106 checkset isAlpha
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
108 checkset isHexDigit
"0123456789abcdefABCDEF";
111 "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
113 checkset
isPrint (WideString
.^
(" ", graphchars
))
115 checkset isSpace
" \009\010\011\012\013";
117 checkset isGraph graphchars
119 checkset isAscii ascii
122 tst
' "test31" (fn _
=> map
toLower (WideString
.explode ascii
) =
123 WideString
.explode lowerascii
)
125 tst
' "test32" (fn _
=> map
toUpper (WideString
.explode ascii
) =
126 WideString
.explode upperascii
)
128 tst
' "test33" (fn _
=>
129 map
toUpper (WideString
.explode graphchars
)
130 seq map
toLower (WideString
.explode graphchars
)
134 tst
' "test34a" (fn _
=>
135 map
pred (List.drop(allchars
, 1)) = List.take(allchars
, 255));
136 val test34b
= tst0
"test34b" ((pred minChar seq
"WRONG")
137 handle Chr
=> "OK" | _
=> "WRONG")
139 tst
' "test35a" (fn _
=>
140 map
succ (List.take(allchars
, 255)) = List.drop(allchars
, 1));
141 val test35b
= tst0
"test35b" ((succ maxChar seq
"WRONG")
142 handle Chr
=> "OK" | _
=> "WRONG")
146 (* Test cases for SML character escape functions
. *)
149 let fun chk (arg
, res
) = WideChar
.toString arg
= res
150 in tst
' "test36" (fn _
=> List.all chk
174 let val chars
= List.tabulate(256, WideChar
.chr
)
175 fun chk c
= WideChar
.fromString(WideChar
.toString c
) = SOME c
176 in tst
' "test37" (fn _
=> List.all chk chars
) end
179 let fun chkFromString (arg
, res
) = WideChar
.fromString arg
= SOME res
203 ("\\u0000", #
"\000"),
204 ("\\u67ab", #
"\u67ab"),
205 ("\\U001067ab", #
"\U001067ab"),
206 ("\\U0010ffff", #
"\U0010ffff"),
207 ("\\ \t\n\n \\A", #
"A"),
208 ("\\ \t\n\n \\z", #
"z"),
209 ("\\ \t\n\n \\@", #
"@"),
210 ("\\ \t\n\n \\~", #
"~"),
211 ("\\ \t\n\n \\\\n", #
"\n"),
212 ("\\ \t\n\n \\\\t", #
"\t"),
213 ("\\ \t\n\n \\\\\\", #
"\\"),
214 ("\\ \t\n\n \\\\\"", #
"\""),
215 ("\\ \t\n\n \\\\^@", #
"\000"),
216 ("\\ \t\n\n \\\\^A", #
"\001"),
217 ("\\ \t\n\n \\\\^Z", #
"\026"),
218 ("\\ \t\n\n \\\\^_", #
"\031"),
219 ("\\ \t\n\n \\\\000", #
"\000"),
220 ("\\ \t\n\n \\\\097", #
"a"),
221 ("\\ \t\n\n \\\\255", #
"\255")]
223 tst
' "test38" (fn _
=> List.all chkFromString argResList
)
227 tst
' "test39" (fn _
=> List.all (fn arg
=> WideChar
.fromString arg
= NONE
)
243 "\\U00110000", (* outside the range
of Unicode
*)
248 (* Test cases for C
string escape functions
*)
251 let val chars
= List.tabulate(256, WideChar
.chr
)
252 in tst
' "test40" (fn _
=>
254 = List.map WideChar
.fromCString (List.map WideChar
.toCString chars
))
271 tst
' "test41" (fn _
=>
272 List.all (fn (arg
, res
) => WideChar
.toCString arg
= res
) argResList
)
276 let fun checkFromCStringSucc (arg
, res
) =
277 WideString
.str (valOf (WideChar
.fromCString arg
)) = res
309 ("\\x67ab", "\u67ab"),
310 ("\\u67ab", "\u67ab"),
311 ("\\uffff", "\uffff"),
312 ("\\U001067ab", "\U001067ab"),
313 ("\\U0010ffff", "\U0010ffff"),
314 ("\\x0000000a", "\010"),
315 ("\\x0000000a2", "\162"),
316 ("\\x0000000ag", "\010"),
317 ("\\x0000000A", "\010"),
318 ("\\x0000000A2", "\162"),
319 ("\\x0000000Ag", "\010"),
320 ("\\x00000000000000000000000000000000000000000000000000000000000000011+",
324 tst
' "test42" (fn _
=> List.all checkFromCStringSucc argResList
)
328 let fun checkFromCStringFail arg
= WideChar
.fromCString arg
= NONE
330 tst
' "test43" (fn _
=> List.all checkFromCStringFail
339 "\\U00110000", (* outside the range
of Unicode
*)