Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | val filename = OS.FileSys.tmpName () |
2 | ||
3 | fun testRange (start, length) = | |
4 | let | |
5 | val allChars = Word8Vector.tabulate(length, fn i => Word8.fromInt ((i + start) mod 256)) | |
6 | ||
7 | val outStr = BinIO.openOut filename | |
8 | val _ = BinIO.output (outStr, allChars) | |
9 | val _ = BinIO.closeOut outStr | |
10 | ||
11 | val inStr = BinIO.openIn filename | |
12 | val readChars = BinIO.inputAll inStr | |
13 | val _ = BinIO.closeIn inStr | |
14 | ||
15 | val _ = OS.FileSys.remove filename | |
16 | ||
17 | fun testCharF (c, cnt) = | |
18 | let | |
19 | val readC = Word8Vector.sub(readChars, cnt) | |
20 | val _ = if c = readC then | |
21 | () | |
22 | else | |
23 | print ("Error at index: " ^ (Int.toString cnt) ^ ": " ^ | |
24 | (Word8.toString c) ^ " <> " ^ (Word8.toString readC) ^ "\n") | |
25 | in | |
26 | cnt + 1 | |
27 | end | |
28 | ||
29 | val _ = Word8Vector.foldl testCharF 0 allChars | |
30 | in | |
31 | () | |
32 | end | |
33 | ||
34 | val _ = testRange (0, 256) | |
35 | val _ = print "basic test of writing and reading back all characters done\n" | |
36 | val _ = List.tabulate(256, fn i => List.tabulate(257, fn i2 => testRange (i, i2))) | |
37 | val _ = print "test of writing files of all possible characters in strings of lengths 0-256 finished\n" | |
38 | val _ = List.tabulate(6, fn i => List.tabulate(5000, fn i2 => testRange (i, i2))) | |
39 | ||
40 | val _ = print "test finished\n" |