From 60da252a9a971781bf6ac7eef8b61ca6711082cc Mon Sep 17 00:00:00 2001 From: sof Date: Tue, 21 Sep 1999 09:01:38 +0000 Subject: [PATCH] [project @ 1999-09-21 09:01:38 by sof] Reg. tests for h{Set,Get}Posn + hSeek --- ghc/tests/lib/should_run/io001.hs | 73 +++++++++++++++++++++++++++++++++++++ ghc/tests/lib/should_run/io002.hs | 25 +++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 ghc/tests/lib/should_run/io001.hs create mode 100644 ghc/tests/lib/should_run/io002.hs diff --git a/ghc/tests/lib/should_run/io001.hs b/ghc/tests/lib/should_run/io001.hs new file mode 100644 index 0000000..9606a2c --- /dev/null +++ b/ghc/tests/lib/should_run/io001.hs @@ -0,0 +1,73 @@ +-- !!! Testing hGetPosn and hSetPosn +module Main(main) where + +import IO +import IOExts + +getPos :: HandlePosn -> HandlePosition +getPos (HandlePosn _ x) = x + +getPosnAndPrint h = do + x <- hGetPosn h + v <- hGetChar h + putStrLn ("At position: " ++ show (getPos x) ++ ", found: " ++ show v) + return x + +recordDoAndRepos h a = do + x <- getPosnAndPrint h + a + hSetPosn x + getPosnAndPrint h + return () + +recordDoAndRepos2 h a = do + x <- getPosnAndPrint h + a + hSeek h AbsoluteSeek (getPos x) + getPosnAndPrint h + return () + +recordDoAndRepos3 h a = do + x <- getPosnAndPrint h + a + hSeek h SeekFromEnd (negate (getPos x + 1)) + getPosnAndPrint h + return () + +main :: IO () +main = do + h <- openFile "io001.hs" ReadMode + recordDoAndRepos h $ + recordDoAndRepos h $ + recordDoAndRepos h $ + recordDoAndRepos h $ + recordDoAndRepos h $ + putStrLn "" + hClose h + putStrLn "" + h <- openFileEx "io001.hs" (BinaryMode ReadMode) + recordDoAndRepos h $ + recordDoAndRepos h $ + recordDoAndRepos h $ + recordDoAndRepos h $ + recordDoAndRepos h $ + putStrLn "" + hClose h + putStrLn "\nUsing hSeek/AbsoluteSeek: " + h <- openFile "io001.hs" ReadMode + recordDoAndRepos2 h $ + recordDoAndRepos2 h $ + recordDoAndRepos2 h $ + recordDoAndRepos2 h $ + recordDoAndRepos2 h $ + putStrLn "" + + hClose h + putStrLn "\nUsing hSeek/SeekFromEnd: " + h <- openFile "io001.hs" ReadMode + recordDoAndRepos3 h $ + recordDoAndRepos3 h $ + recordDoAndRepos3 h $ + recordDoAndRepos3 h $ + recordDoAndRepos3 h $ + putStrLn "" diff --git a/ghc/tests/lib/should_run/io002.hs b/ghc/tests/lib/should_run/io002.hs new file mode 100644 index 0000000..17d8639 --- /dev/null +++ b/ghc/tests/lib/should_run/io002.hs @@ -0,0 +1,25 @@ +-- !!! Testing hSeek +module Main(main) where + +import IO +import IOExts +import Directory + +main :: IO () +main = do + h <- openFile "tst-seek" WriteMode + hPutStrLn h "test string1" + -- seek to EOF should be cool.. + hSeek h SeekFromEnd 0 + hPutStr h "test string2" + -- seek past EOF should now be cool.. + hSeek h SeekFromEnd 3 + hPutStr h "test string3" + hSeek h AbsoluteSeek 13 + hPutStr h "test string4" + x <- hTell h + print x + hClose h + ls <- readFile "tst-seek" + putStrLn ls + removeFile "tst-seek" -- 1.7.10.4