Import Upstream version 20180207
[hcoop/debian/mlton.git] / regression / textio.2.sml
CommitLineData
7f918cf1
CE
1(* Notice: This test will not be passed on platforms like Win32!
2 (due to behind-the-scenes CR/LF <=> LF conversions). *)
3
4val filename = OS.FileSys.tmpName ()
5
6fun 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
37val _ = testRange (0, 256)
38val _ = print "basic test of writing and reading back all characters done\n"
39val _ = List.tabulate(256, fn i => List.tabulate(257, fn i2 => testRange (i, i2)))
40val _ = print "test of writing files of all possible characters in strings of lengths 0-256 finished\n"
41val _ = List.tabulate(6, fn i => List.tabulate(5000, fn i2 => testRange (i, i2)))
42
43val _ = print "test finished\n"