| 1 |
(* Notice: This test will not be passed on platforms like Win32! |
| 2 |
(due to behind-the-scenes CR/LF <=> LF conversions). *) |
| 3 |
|
| 4 |
val filename = OS.FileSys.tmpName () |
| 5 |
|
| 6 |
fun testRange (start, length) = |
| 7 |
let |
| 8 |
val allChars = CharVector.tabulate(length, fn i => chr ((i + start) mod 256)) |
| 9 |
|
| 10 |
val outStr = TextIO.openOut filename |
| 11 |
val _ = TextIO.output (outStr, allChars) |
| 12 |
val _ = TextIO.closeOut outStr |
| 13 |
|
| 14 |
val inStr = TextIO.openIn filename |
| 15 |
val readChars = TextIO.inputAll inStr |
| 16 |
val _ = TextIO.closeIn inStr |
| 17 |
|
| 18 |
val _ = OS.FileSys.remove filename |
| 19 |
|
| 20 |
fun testCharF (c, cnt) = |
| 21 |
let |
| 22 |
val readC = CharVector.sub(readChars, cnt) |
| 23 |
val _ = if c = readC then |
| 24 |
() |
| 25 |
else |
| 26 |
print ("Error at index: " ^ (Int.toString cnt) ^ ": " ^ |
| 27 |
(Char.toString c) ^ " <> " ^ (Char.toString readC) ^ "\n") |
| 28 |
in |
| 29 |
cnt + 1 |
| 30 |
end |
| 31 |
|
| 32 |
val _ = CharVector.foldl testCharF 0 allChars |
| 33 |
in |
| 34 |
() |
| 35 |
end |
| 36 |
|
| 37 |
val _ = testRange (0, 256) |
| 38 |
val _ = print "basic test of writing and reading back all characters done\n" |
| 39 |
val _ = List.tabulate(256, fn i => List.tabulate(257, fn i2 => testRange (i, i2))) |
| 40 |
val _ = print "test of writing files of all possible characters in strings of lengths 0-256 finished\n" |
| 41 |
val _ = List.tabulate(6, fn i => List.tabulate(5000, fn i2 => testRange (i, i2))) |
| 42 |
|
| 43 |
val _ = print "test finished\n" |