[project @ 1999-09-21 09:01:38 by sof]
authorsof <unknown>
Tue, 21 Sep 1999 09:01:38 +0000 (09:01 +0000)
committersof <unknown>
Tue, 21 Sep 1999 09:01:38 +0000 (09:01 +0000)
Reg. tests for h{Set,Get}Posn + hSeek

ghc/tests/lib/should_run/io001.hs [new file with mode: 0644]
ghc/tests/lib/should_run/io002.hs [new file with mode: 0644]

diff --git a/ghc/tests/lib/should_run/io001.hs b/ghc/tests/lib/should_run/io001.hs
new file mode 100644 (file)
index 0000000..9606a2c
--- /dev/null
@@ -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 (file)
index 0000000..17d8639
--- /dev/null
@@ -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"