Fix some more tests on Win64
[packages/base.git] / tests / hTell001.hs
1 -- !!! Testing hGetPosn and hSetPosn
2 module Main(main) where
3
4 import System.IO
5
6 getPosnAndPrint h = do
7 x <- hTell h
8 v <- hGetChar h
9 putStrLn ("At position: " ++ show x ++ ", found: " ++ show v)
10 return x
11
12 recordDoAndRepos h a = do
13 x <- getPosnAndPrint h
14 a
15 hSeek h AbsoluteSeek x
16 getPosnAndPrint h
17 return ()
18
19 recordDoAndRepos2 h a = do
20 x <- getPosnAndPrint h
21 a
22 hSeek h AbsoluteSeek x
23 getPosnAndPrint h
24 return ()
25
26 recordDoAndRepos3 h a = do
27 x <- getPosnAndPrint h
28 a
29 hSeek h SeekFromEnd (negate (x + 1))
30 getPosnAndPrint h
31 return ()
32
33 file = "hTell001.hs"
34
35 main :: IO ()
36 main = do
37 h <- openBinaryFile file ReadMode
38 recordDoAndRepos h $
39 recordDoAndRepos h $
40 recordDoAndRepos h $
41 recordDoAndRepos h $
42 recordDoAndRepos h $
43 putStrLn ""
44 hClose h
45 putStrLn "\nUsing hSeek/AbsoluteSeek: "
46 h <- openBinaryFile file ReadMode
47 recordDoAndRepos2 h $
48 recordDoAndRepos2 h $
49 recordDoAndRepos2 h $
50 recordDoAndRepos2 h $
51 recordDoAndRepos2 h $
52 putStrLn ""
53
54 hClose h
55 putStrLn "\nUsing hSeek/SeekFromEnd: "
56 putStrLn "(Don't worry if you're seeing differing numbers here, it might be down to '\\n' vs '\\r\\n')"
57 h <- openBinaryFile file ReadMode
58 recordDoAndRepos3 h $
59 recordDoAndRepos3 h $
60 recordDoAndRepos3 h $
61 recordDoAndRepos3 h $
62 recordDoAndRepos3 h $
63 putStrLn ""