[project @ 1998-08-05 17:16:04 by sof]
authorsof <unknown>
Wed, 5 Aug 1998 17:16:05 +0000 (17:16 +0000)
committersof <unknown>
Wed, 5 Aug 1998 17:16:05 +0000 (17:16 +0000)
Dynamic library test cases

ghc/tests/lib/should_run/dynamic001.hs [new file with mode: 0644]
ghc/tests/lib/should_run/dynamic001.stdout [new file with mode: 0644]

diff --git a/ghc/tests/lib/should_run/dynamic001.hs b/ghc/tests/lib/should_run/dynamic001.hs
new file mode 100644 (file)
index 0000000..8126cbe
--- /dev/null
@@ -0,0 +1,107 @@
+--!!! Dynamic library tests
+module Main(main) where
+
+import Dynamic
+
+main :: IO ()
+main = do
+   test   "toDyn"   toDyn_list
+   testIO "fromDyn" fromDyn_test
+
+toDyn_list :: [Dynamic]
+toDyn_list =
+    [ toDyn (1::Int)
+    , toDyn ('a')
+    , toDyn False
+    , toDyn ((-1.0)::Float)
+    , toDyn (0.0::Double)
+    , toDyn (1394::Integer)
+    , toDyn (print "hello")
+    , toDyn toDyn_list
+    , toDyn ([]::[Int])
+    , toDyn (Nothing  :: Maybe Int)
+    , toDyn ((Just 2) :: Maybe Int)
+    , toDyn ((Just 2) :: Maybe Int)
+    , toDyn ((Left 3) :: Either Int Bool)
+    , toDyn ((Right 3) :: Either Char Int)
+    , toDyn ()
+    , toDyn LT
+    , toDyn ((),2::Int)
+    , toDyn ((),2::Int,'a')
+    , toDyn ((),2::Int,'a',1.0::Double)
+    , toDyn ((),2::Int,'a',1.0::Double,Nothing::Maybe Bool)
+    , toDyn ((+) :: Int -> Int -> Int)
+    , toDyn ((+) :: Integer -> Integer -> Integer)
+    , toDyn ((++) :: [Char] -> [Char] -> [Char])
+    ]
+
+-- Testing the conversion from Dynamic values:
+fromDyn_test :: IO ()
+fromDyn_test = do
+   print (fromDyn (toDyn (1::Int)) (0::Int))
+   print (fromDyn (toDyn ('a'::Char)) (0::Int))
+   print (fromDyn (toDyn 'a') 'b')
+   print (fromDyn (toDyn (1::Float)) (0::Float))
+   print (fromDyn (toDyn (2::Float)) (0::Int))
+   print (fromDyn (toDyn (3::Double)) (0::Double))
+   print (fromDyn (toDyn (4::Double)) (0::Int))
+   print (fromDyn (toDyn (5::Integer)) (0::Integer))
+   print (fromDyn (toDyn (6::Integer)) False)
+   print (fromDyn (toDyn [1,3,5::Integer]) ([]::[Integer]))
+   print (fromDyn (toDyn (Just True)) (Nothing::Maybe Bool))
+   print (fromDyn (toDyn (Left True::Either Bool Bool)) (Right False :: Either Bool Bool))
+   print (fromDyn (toDyn LT) GT)
+   print (fromDyn (toDyn ((+1)::Int->Int)) False)
+   print (fromDyn (toDyn ((+1)::Int->Int)) ((+2)::Int->Int))
+   print (fromDyn (toDyn ((++)::[Int]->[Int]->[Int])) ((undefined)::[Int]->[Int]->[Int]))
+
+    
+-- Misc test utilities:
+test :: Show a => String -> [a] -> IO ()
+test str ls = do
+  putStrLn ("*** Testing: " ++ str ++ " ***")
+  putStrLn (showListLn ls)
+
+testIO :: String -> IO () -> IO ()
+testIO str tst = do
+  putStrLn ("*** Testing: " ++ str ++ " ***")
+  tst
+
+
+-- showListLn presents a list in a diff-friendly format.
+-- showListLn [a1,..an]
+--  =>
+--      [ a1
+--      , a2
+--      ..
+--      , an
+--      ]
+--   
+showListLn :: Show a => [a] -> String
+showListLn [] = ""
+showListLn ls = '[' : ' ' : go ls
+ where
+   go    [x] = show x ++ "\n]"
+   go (x:xs) = show x ++ '\n':',':' ':go xs
+
+{-
+test8 = toDyn (mkAppTy listTc)
+test9 :: Float
+test9 = fromDyn test8 0
+
+printf :: String -> [Dynamic] -> IO ()
+printf str args = putStr (decode str args)
+ where
+  decode [] [] = []
+  decode ('%':'n':cs) (d:ds) =
+    (\ v -> show v++decode cs ds) (fromDyn  d (0::Int))
+  decode ('%':'c':cs) (d:ds) =
+    (\ v -> show v++decode cs ds) (fromDyn  d ('\0'))
+  decode ('%':'b':cs) (d:ds) =
+    (\ v -> show v++decode cs ds) (fromDyn  d (False::Bool))
+  decode (x:xs) ds = x:decode xs ds
+
+test10 :: IO ()
+test10 = printf "%n = %c, that much is %b\n" [toDyn (3::Int),toDyn 'a', toDyn False]
+
+-}
diff --git a/ghc/tests/lib/should_run/dynamic001.stdout b/ghc/tests/lib/should_run/dynamic001.stdout
new file mode 100644 (file)
index 0000000..6116074
--- /dev/null
@@ -0,0 +1,42 @@
+*** Testing: toDyn ***
+[ <<Int>>
+, <<Char>>
+, <<Bool>>
+, <<Float>>
+, <<Double>>
+, <<Integer>>
+, <<IO ()>>
+, <<[Dynamic]>>
+, <<[Int]>>
+, <<Maybe Int>>
+, <<Maybe Int>>
+, <<Maybe Int>>
+, <<Maybe Int Int>>
+, <<Maybe Char Char>>
+, <<()>>
+, <<Ordering>>
+, <<((),Int)>>
+, <<((),Int,Char)>>
+, <<((),Int,Char,Double)>>
+, <<((),Int,Char,Double,(Maybe Bool))>>
+, <<Int -> Int -> Int>>
+, <<Integer -> Integer -> Integer>>
+, <<[Char] -> [Char] -> [Char]>>
+]
+*** Testing: fromDyn ***
+1
+0
+'a'
+1.0
+0
+3.0
+0
+5
+False
+[1,3,5]
+Just True
+Left True
+LT
+False
+<<function>>
+<<function>>