[project @ 1999-01-23 17:55:26 by sof]
authorsof <unknown>
Sat, 23 Jan 1999 17:55:29 +0000 (17:55 +0000)
committersof <unknown>
Sat, 23 Jan 1999 17:55:29 +0000 (17:55 +0000)
More Enum regression tests than you can shake a stick at.

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

diff --git a/ghc/tests/lib/should_run/enum01.hs b/ghc/tests/lib/should_run/enum01.hs
new file mode 100644 (file)
index 0000000..e983986
--- /dev/null
@@ -0,0 +1,500 @@
+-- !!! Testing the Prelude's Enum instances.
+module Main(main) where
+
+import Exception
+import Char
+
+main = do
+   -- Enum Int
+  putStrLn "Testing Enum Int: "
+  testEnumInt
+   -- Enum Integer
+  putStrLn "Testing Enum Integer: "
+  testEnumInteger
+   -- Enum Char
+  putStrLn "Testing Enum Char: "
+  testEnumChar
+   -- Enum ()
+  putStrLn "Testing Enum (): "
+  testEnumUnit
+   -- Enum Ordering
+  putStrLn "Testing Enum Ordering (derived): "
+  testEnumOrdering
+   -- Enum Bool
+  putStrLn "Testing Enum Bool: "
+  testEnumBool
+   -- Enum Rational
+  putStrLn "Testing Enum Rational: "
+  testEnumRational
+   -- Enum (Ratio Int)
+  putStrLn "Testing Enum (Ratio Int): "
+  testEnumRatioInt
+
+{- 
+  Here's the properties that's supposed to
+  hold for arithmetic sequences over Int:
+
+   - [e1..]    = [e1, (e1+1), (e1+2), ..., maxBound]
+
+   - [e1,e2..] = [e1, (e1+i), (e1+2*i), ... upper]
+                 where
+                 i = e2 - e1
+                 upper
+                  | i >  0 = maxBound
+                  | i <  0 = minBound
+                  | i == 0 = maxBound -- this really shouldn't matter (I feel.)
+   - [e1..e3] = [e1, (e1+i), (e1+2*i),..e3]
+                where
+                i
+                 | e3 >= e1 = 1
+                 | e3 <  e1 = (-1)
+    
+   - [e1,e2..e3] = res
+                   where
+                   i = e2 - e1
+                   
+                   res
+                    | i >= 0 && e3 <  e1 = []
+                    | i <  0 && e3 >= e1 = []  -- (*)
+                    | otherwise          = [e1, (e1+i), (e1 + 2*i), .. e3]
+
+   Note:
+     (*) - I think this instead should be (i < 0 && e3 > e1), since, as is,
+
+            [x,(x+1) ..x] = [x] 
+            [x,(x-1) ..x] = []
+
+           which does not look right, symmetrically speaking.
+
+
+   The same properties hold for other Prelude types that
+   are instances of Enum as well as being Bounded.
+   
+   For non-Bounded types (e.g., Float and Double), the properties are similar,
+   except that the boundary tests become slightly different, i.e., when an
+   element becomes greater than (e3 + i/2) (or less than (e3 + i/2) for negative
+   i.)
+
+  Q - does [(x::Double)..] have an upper bound? (ditto for Float.)
+
+  OK - on with the regression testing.
+-}
+
+#define printTest(x) (do{ putStr ( "    " ++ "x" ++ " = " ) ; print (x) })
+
+
+testEnumInt :: IO ()
+testEnumInt = do
+     -- succ
+  printTest ((succ (0::Int)))
+  printTest ((succ (minBound::Int)))
+  mayBomb   (printTest ((succ (maxBound::Int))))
+
+     -- pred
+  printTest (pred (1::Int))
+  printTest (pred (maxBound::Int))
+  mayBomb   (printTest (pred (minBound::Int))) 
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Int) [1,minBound,maxBound]))
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Int),minBound,maxBound]))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Int)..]))
+  printTest ((take 7 [((maxBound::Int)-5)..])) -- just in case it doesn't catch the upper bound..
+  
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Int),2..]))
+  printTest ((take 7 [(1::Int),7..]))
+  printTest ((take 7 [(1::Int),1..]))
+  printTest ((take 7 [(1::Int),0..]))
+  printTest ((take 7 [(5::Int),2..]))
+  let x = (minBound::Int) + 1
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (minBound::Int) + 5
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (maxBound::Int) - 5
+  printTest ((take 7 [x, (x+1) ..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Int) .. 5])))
+  printTest ((take 4 ([(1::Int) .. 1])))
+  printTest ((take 7 ([(1::Int) .. 0])))
+  printTest ((take 7 ([(5::Int) .. 0])))
+  printTest ((take 7 ([(maxBound-(5::Int)) .. maxBound])))
+  printTest ((take 7 ([(minBound+(5::Int)) .. minBound])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Int),4..1]))
+  printTest ((take 7 [(5::Int),3..1]))
+  printTest ((take 7 [(5::Int),3..2]))
+  printTest ((take 7 [(1::Int),2..1]))
+  printTest ((take 7 [(2::Int),1..2]))
+  printTest ((take 7 [(2::Int),1..1]))
+  printTest ((take 7 [(2::Int),3..1]))
+
+  let x = (maxBound::Int) - 4
+  printTest ((take 7 [x,(x+1)..maxBound]))
+  let x = (minBound::Int) + 5
+  printTest ((take 7 [x,(x-1)..minBound]))
+
+testEnumChar :: IO ()
+testEnumChar = do
+     -- succ
+  printTest ((succ 'a'))
+  printTest ((succ (minBound::Char)))
+  mayBomb (printTest ((succ (maxBound::Char))))
+
+     -- pred
+  printTest ((pred 'b'))
+  printTest (pred (maxBound::Char))
+  mayBomb (printTest (pred (minBound::Char)))
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Char) [123,ord (minBound::Char), ord(maxBound::Char)]))
+  mayBomb (printTest ((toEnum::Int->Char) (minBound::Int)))
+
+     -- fromEnum
+  printTest ((map fromEnum ['X',minBound,maxBound]))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 ['\NUL' .. ]))
+  printTest ((take 7 ['\250' .. ]))
+  
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 ['a','b'..]))
+  printTest ((take 7 ['a','e'..]))
+  printTest ((take 7 ['a','a'..]))
+  printTest ((take 7 ['z','y'..]))
+  printTest ((take 7 ['z','v'..]))
+  let x = '\1'
+  printTest ((take 7 ['\1', '\0' ..]))
+  let x = '\5'
+  printTest ((take 7 ['\5', '\4' ..]))
+  let x = (maxBound::Int) - 5
+  printTest ((take 7 ['\250', '\251' ..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 (['a' .. 'e'])))
+  printTest ((take 4 (['a' .. 'a'])))
+  printTest ((take 7 (['b' .. 'a'])))
+  printTest ((take 7 (['e' .. 'a'])))
+  printTest ((take 7 (['\250' .. '\255'])))
+  printTest ((take 7 (['\5' .. '\0'])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 ['f','e' .. 'b']))
+  printTest ((take 7 ['g','e' .. 'b']))
+  printTest ((take 7 ['g','d' .. 'c']))
+  printTest ((take 7 ['b','c' .. 'b']))
+  printTest ((take 7 ['c','b' .. 'c']))
+  printTest ((take 7 ['c','b' .. 'b']))
+  printTest ((take 7 ['c','d' .. 'b']))
+  printTest ((take 7 ['\251', '\252' .. maxBound]))
+  printTest ((take 7 ['\5', '\4' .. minBound]))
+
+
+testEnumUnit :: IO ()
+testEnumUnit = do
+   -- succ:
+  mayBomb (printTest ((succ ())))
+  mayBomb (printTest ((succ (minBound::()))))
+  mayBomb (printTest ((succ (maxBound::()))))
+       
+   -- pred:
+  mayBomb (printTest ((pred ())))
+  mayBomb (printTest ((pred (minBound::()))))
+  mayBomb (printTest ((pred (maxBound::()))))
+
+   -- toEnum:
+  printTest ((toEnum 0)::())
+  mayBomb   (printTest ((toEnum 1)::()))
+
+   -- fromEnum:
+  printTest ((fromEnum ()))
+
+   -- enumFrom:
+  printTest (([()..]))
+
+   -- enumFromThen:
+  printTest (([(),()..]))
+
+   -- enumFromTo
+  printTest (([()..()]))
+
+   -- enumFromThenTo
+  printTest (([(),()..()]))
+
+testEnumOrdering :: IO ()
+testEnumOrdering = do
+   -- succ:
+  printTest ((succ LT))
+  printTest ((succ (minBound::Ordering)))
+  mayBomb (printTest ((succ (maxBound::Ordering))))
+       
+   -- pred:
+  printTest ((pred GT))
+  printTest ((pred (maxBound::Ordering)))
+  mayBomb (printTest ((pred (minBound::Ordering))))
+
+   -- toEnum:
+  printTest ((toEnum 0)::Ordering)
+  mayBomb   (printTest ((toEnum 5)::Ordering))
+
+   -- fromEnum:
+  printTest ((fromEnum LT))
+  printTest ((fromEnum EQ))
+  printTest ((fromEnum GT))
+
+   -- enumFrom:
+  printTest (([LT ..]))
+  printTest (([EQ ..]))
+  printTest (([GT ..]))
+
+   -- enumFromThen:
+  printTest (([LT,EQ ..]))
+  printTest (([EQ,GT ..]))
+  printTest (([EQ,LT ..]))
+  printTest (([LT,GT ..]))
+  printTest (([GT,LT ..]))
+  printTest (take 7 (([GT,GT ..])))
+  printTest (take 7 (([LT,LT ..])))
+
+   -- enumFromTo
+  printTest (([LT .. GT]))
+  printTest (([LT .. EQ]))
+  printTest (([LT .. LT]))
+  printTest (([GT .. LT]))
+  printTest (([GT .. EQ]))
+  printTest (([GT .. GT]))
+
+   -- enumFromThenTo
+  printTest (([LT,EQ .. GT]))
+  printTest (([GT,EQ .. LT]))
+  printTest (([GT,EQ .. EQ]))
+  printTest (([GT,EQ .. GT]))
+  printTest (([GT,EQ .. LT]))
+  printTest (([LT,EQ .. LT]))
+  printTest (([LT,EQ .. GT]))
+  printTest (take 7 (([LT,LT .. GT])))
+  printTest (take 7 (([GT,GT .. LT])))
+
+testEnumBool :: IO ()
+testEnumBool = do
+   -- succ:
+  printTest ((succ False))
+  printTest ((succ (minBound::Bool)))
+  mayBomb (printTest ((succ (maxBound::Bool))))
+       
+   -- pred:
+  printTest ((pred True))
+  printTest ((pred (maxBound::Bool)))
+  mayBomb (printTest ((pred (minBound::Bool))))
+
+   -- toEnum:
+  printTest ((toEnum 0)::Bool)
+  mayBomb   (printTest ((toEnum 5)::Bool))
+
+   -- fromEnum:
+  printTest ((fromEnum False))
+  printTest ((fromEnum True))
+
+   -- enumFrom:
+  printTest (([False ..]))
+  printTest (([True ..]))
+
+   -- enumFromThen:
+  printTest (([False,True ..]))
+  printTest (([True,False ..]))
+  printTest ((take 7 ([False,False ..])))
+  printTest ((take 7 ([True,True ..])))
+
+   -- enumFromTo
+  printTest (([False .. True]))
+  printTest (([True .. False]))
+
+   -- enumFromThenTo
+  printTest (take 7 ([False,False .. False]))
+  printTest (take 7 ([False,False .. True]))
+  printTest (take 7 ([False,True .. False]))
+  printTest (take 7 ([False,True .. True]))
+  printTest (take 7 ([True,False .. False]))
+  printTest (take 7 ([True,False .. True]))
+  printTest (take 7 ([True,True ..  False]))
+  printTest (take 7 ([True,True ..  True]))
+
+
+testEnumInteger :: IO ()
+testEnumInteger = do
+     -- succ
+  printTest ((succ (0::Integer)))
+  printTest ((succ ((-1)::Integer)))
+
+     -- pred
+  printTest (pred (1::Integer))
+  printTest (pred (0::Integer))
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Integer) [1,minBound,maxBound]))
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Integer),42,45]))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Integer)..]))
+  printTest ((take 7 [(-5::Integer)..]))
+  
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Integer),2..]))
+  printTest ((take 7 [(1::Integer),7..]))
+  printTest ((take 7 [(1::Integer),1..]))
+  printTest ((take 7 [(1::Integer),0..]))
+  printTest ((take 7 [(5::Integer),2..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Integer) .. 5])))
+  printTest ((take 4 ([(1::Integer) .. 1])))
+  printTest ((take 7 ([(1::Integer) .. 0])))
+  printTest ((take 7 ([(5::Integer) .. 0])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Integer),4..1]))
+  printTest ((take 7 [(5::Integer),3..1]))
+  printTest ((take 7 [(5::Integer),3..2]))
+  printTest ((take 7 [(1::Integer),2..1]))
+  printTest ((take 7 [(2::Integer),1..2]))
+  printTest ((take 7 [(2::Integer),1..1]))
+  printTest ((take 7 [(2::Integer),3..1]))
+
+testEnumRational :: IO ()
+testEnumRational = do
+     -- succ
+  printTest ((succ (0::Rational)))
+  printTest ((succ ((-1)::Rational)))
+
+     -- pred
+  printTest (pred (1::Rational))
+  printTest (pred (0::Rational))
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Rational) [1,minBound,maxBound]))
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Rational),42,45]))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Rational)..]))
+  printTest ((take 7 [(-5::Rational)..]))
+  
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Rational),2..]))
+  printTest ((take 7 [(1::Rational),7..]))
+  printTest ((take 7 [(1::Rational),1..]))
+  printTest ((take 7 [(1::Rational),0..]))
+  printTest ((take 7 [(5::Rational),2..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Rational) .. 5])))
+  printTest ((take 4 ([(1::Rational) .. 1])))
+  printTest ((take 7 ([(1::Rational) .. 0])))
+  printTest ((take 7 ([(5::Rational) .. 0])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Rational),4..1]))
+  printTest ((take 7 [(5::Rational),3..1]))
+  printTest ((take 7 [(5::Rational),3..2]))
+  printTest ((take 7 [(1::Rational),2..1]))
+  printTest ((take 7 [(2::Rational),1..2]))
+  printTest ((take 7 [(2::Rational),1..1]))
+  printTest ((take 7 [(2::Rational),3..1]))
+
+testEnumRatioInt :: IO ()
+testEnumRatioInt = do
+     -- succ
+  printTest ((succ (0::Ratio Int)))
+  printTest ((succ ((-1)::Ratio Int)))
+
+     -- pred
+  printTest (pred (1::Ratio Int))
+  printTest (pred (0::Ratio Int))
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Ratio Int) [1,minBound,maxBound]))
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Ratio Int),42,45]))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Ratio Int)..]))
+  printTest ((take 7 [(-5::Ratio Int)..]))
+  printTest ((take 7 [((toEnum ((maxBound::Int)-5))::Ratio Int)..]))
+  
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Ratio Int),2..]))
+  printTest ((take 7 [(1::Ratio Int),7..]))
+  printTest ((take 7 [(1::Ratio Int),1..]))
+  printTest ((take 7 [(1::Ratio Int),0..]))
+  printTest ((take 7 [(5::Ratio Int),2..]))
+  let x = (toEnum ((minBound::Int) + 1))::Ratio Int
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (toEnum ((minBound::Int) + 5))::Ratio Int
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (toEnum ((maxBound::Int) - 5))::Ratio Int
+  printTest ((take 7 [x, (x+1) ..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Ratio Int) .. 5])))
+  printTest ((take 4 ([(1::Ratio Int) .. 1])))
+  printTest ((take 7 ([(1::Ratio Int) .. 0])))
+  printTest ((take 7 ([(5::Ratio Int) .. 0])))
+  let x = (toEnum (maxBound - (5::Int))) :: Ratio Int
+  let y = (toEnum (maxBound::Int)) :: Ratio Int
+  printTest ((take 7 ([x..y])))
+  let x = (toEnum (minBound + (5::Int))) :: Ratio Int
+  let y = (toEnum (minBound::Int)) :: Ratio Int
+  printTest ((take 7 ([x..y])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Ratio Int),4..1]))
+  printTest ((take 7 [(5::Ratio Int),3..1]))
+  printTest ((take 7 [(5::Ratio Int),3..2]))
+  printTest ((take 7 [(1::Ratio Int),2..1]))
+  printTest ((take 7 [(2::Ratio Int),1..2]))
+  printTest ((take 7 [(2::Ratio Int),1..1]))
+  printTest ((take 7 [(2::Ratio Int),3..1]))
+
+  let x = (toEnum ((maxBound::Int) - 4)) :: Ratio Int
+  let y = (toEnum (maxBound::Int)) :: Ratio Int
+  printTest ((take 7 [x,(x+1)..y]))
+  let x = (toEnum ((minBound::Int) + 5)) :: Ratio Int
+  let y = (toEnum (minBound::Int)) :: Ratio Int
+  printTest ((take 7 [x,(x-1)..y]))
+
+--
+--
+--  Utils
+--
+--
+
+
+mayBomb x = catchAllIO x errorHandler
+
+errorHandler :: Exception -> IO ()
+errorHandler e =
+  case justErrors e of
+    Just t -> putStrLn ("error " ++ show t)
+    _     -> return ()
+
+test :: Show a => String -> String -> a -> IO ()
+test test_nm expected val = do
+   putStr test_nm
+   if expected == got then
+      putStrLn ": SUCCEEDED"
+    else do
+      putStr   ": FAILED"
+      putStrLn ("( expected: " ++ show expected ++ " , got: " ++ show got ++ " )")
+  where
+   got = show val
diff --git a/ghc/tests/lib/should_run/enum01.stdout b/ghc/tests/lib/should_run/enum01.stdout
new file mode 100644 (file)
index 0000000..79f5f2a
--- /dev/null
@@ -0,0 +1,230 @@
+Testing Enum Int: 
+    (succ (0::Int)) = 1
+    (succ (minBound::Int)) = -2147483647
+    (succ (maxBound::Int)) = error "Prelude.Enum.succ{Int}: tried to take `succ' of maxBound"
+    pred (1::Int) = 0
+    pred (maxBound::Int) = 2147483646
+    pred (minBound::Int) = error "Prelude.Enum.pred{Int}: tried to take `pred' of minBound"
+    (map (toEnum::Int->Int) [1,minBound,maxBound]) = [1,-2147483648,2147483647]
+    (map fromEnum [(1::Int),minBound,maxBound]) = [1,-2147483648,2147483647]
+    (take 7 [(1::Int)..]) = [1,2,3,4,5,6,7]
+    (take 7 [((maxBound::Int)-5)..]) = [2147483642,2147483643,2147483644,2147483645,2147483646,2147483647]
+    (take 7 [(1::Int),2..]) = [1,2,3,4,5,6,7]
+    (take 7 [(1::Int),7..]) = [1,7,13,19,25,31,37]
+    (take 7 [(1::Int),1..]) = [1,1,1,1,1,1,1]
+    (take 7 [(1::Int),0..]) = [1,0,-1,-2,-3,-4,-5]
+    (take 7 [(5::Int),2..]) = [5,2,-1,-4,-7,-10,-13]
+    (take 7 [x, x-1 ..]) = [-2147483647,-2147483648]
+    (take 7 [x, x-1 ..]) = [-2147483643,-2147483644,-2147483645,-2147483646,-2147483647,-2147483648]
+    (take 7 [x, (x+1) ..]) = [2147483642,2147483643,2147483644,2147483645,2147483646,2147483647]
+    (take 7 ([(1::Int) .. 5])) = [1,2,3,4,5]
+    (take 4 ([(1::Int) .. 1])) = [1]
+    (take 7 ([(1::Int) .. 0])) = [1,0]
+    (take 7 ([(5::Int) .. 0])) = [5,4,3,2,1,0]
+    (take 7 ([(maxBound-(5::Int)) .. maxBound])) = [2147483642,2147483643,2147483644,2147483645,2147483646,2147483647]
+    (take 7 ([(minBound+(5::Int)) .. minBound])) = [-2147483643,-2147483644,-2147483645,-2147483646,-2147483647,-2147483648]
+    (take 7 [(5::Int),4..1]) = [5,4,3,2,1]
+    (take 7 [(5::Int),3..1]) = [5,3,1]
+    (take 7 [(5::Int),3..2]) = [5,3]
+    (take 7 [(1::Int),2..1]) = [1]
+    (take 7 [(2::Int),1..2]) = [2]
+    (take 7 [(2::Int),1..1]) = [2,1]
+    (take 7 [(2::Int),3..1]) = []
+    (take 7 [x,(x+1)..maxBound]) = [2147483643,2147483644,2147483645,2147483646,2147483647]
+    (take 7 [x,(x-1)..minBound]) = [-2147483643,-2147483644,-2147483645,-2147483646,-2147483647,-2147483648]
+Testing Enum Integer: 
+    (succ (0::Integer)) = 1
+    (succ ((-1)::Integer)) = 0
+    pred (1::Integer) = 0
+    pred (0::Integer) = -1
+    (map (toEnum::Int->Integer) [1,minBound,maxBound]) = [1,-2147483648,2147483647]
+    (map fromEnum [(1::Integer),42,45]) = [1,42,45]
+    (take 7 [(1::Integer)..]) = [1,2,3,4,5,6,7]
+    (take 7 [(-5::Integer)..]) = [-5,-4,-3,-2,-1,0,1]
+    (take 7 [(1::Integer),2..]) = [1,2,3,4,5,6,7]
+    (take 7 [(1::Integer),7..]) = [1,7,13,19,25,31,37]
+    (take 7 [(1::Integer),1..]) = [1,1,1,1,1,1,1]
+    (take 7 [(1::Integer),0..]) = [1,0,-1,-2,-3,-4,-5]
+    (take 7 [(5::Integer),2..]) = [5,2,-1,-4,-7,-10,-13]
+    (take 7 ([(1::Integer) .. 5])) = [1,2,3,4,5]
+    (take 4 ([(1::Integer) .. 1])) = [1]
+    (take 7 ([(1::Integer) .. 0])) = [1,0]
+    (take 7 ([(5::Integer) .. 0])) = [5,4,3,2,1,0]
+    (take 7 [(5::Integer),4..1]) = [5,4,3,2,1]
+    (take 7 [(5::Integer),3..1]) = [5,3,1]
+    (take 7 [(5::Integer),3..2]) = [5,3]
+    (take 7 [(1::Integer),2..1]) = [1]
+    (take 7 [(2::Integer),1..2]) = [2]
+    (take 7 [(2::Integer),1..1]) = [2,1]
+    (take 7 [(2::Integer),3..1]) = []
+Testing Enum Char: 
+    (succ 'a') = 'b'
+    (succ (minBound::Char)) = '\SOH'
+    (succ (maxBound::Char)) = error "Prelude.Enum.succ{Char}: tried to take `succ' of maxBound"
+    (pred 'b') = 'a'
+    pred (maxBound::Char) = '\254'
+    pred (minBound::Char) = error "Prelude.Enum.pred{Char}: tried to to take `pred' of minBound"
+    (map (toEnum::Int->Char) [123,ord (minBound::Char), ord(maxBound::Char)]) = "{\NUL\255"
+    (toEnum::Int->Char) (minBound::Int) = error "Prelude.Enum.toEnum{Char}: out of range: -2147483648"
+    (map fromEnum ['X',minBound,maxBound]) = [88,0,255]
+    (take 7 ['\NUL' .. ]) = "\NUL\SOH\STX\ETX\EOT\ENQ\ACK"
+    (take 7 ['\250' .. ]) = "\250\251\252\253\254\255"
+    (take 7 ['a','b'..]) = "abcdefg"
+    (take 7 ['a','e'..]) = "aeimquy"
+    (take 7 ['a','a'..]) = "aaaaaaa"
+    (take 7 ['z','y'..]) = "zyxwvut"
+    (take 7 ['z','v'..]) = "zvrnjfb"
+    (take 7 ['\1', '\0' ..]) = "\SOH\NUL"
+    (take 7 ['\5', '\4' ..]) = "\ENQ\EOT\ETX\STX\SOH\NUL"
+    (take 7 ['\250', '\251' ..]) = "\250\251\252\253\254\255"
+    (take 7 (['a' .. 'e'])) = "abcde"
+    (take 4 (['a' .. 'a'])) = "a"
+    (take 7 (['b' .. 'a'])) = "ba"
+    (take 7 (['e' .. 'a'])) = "edcba"
+    (take 7 (['\250' .. '\255'])) = "\250\251\252\253\254\255"
+    (take 7 (['\5' .. '\0'])) = "\ENQ\EOT\ETX\STX\SOH\NUL"
+    (take 7 ['f','e' .. 'b']) = "fedcb"
+    (take 7 ['g','e' .. 'b']) = "gec"
+    (take 7 ['g','d' .. 'c']) = "gd"
+    (take 7 ['b','c' .. 'b']) = "b"
+    (take 7 ['c','b' .. 'c']) = "c"
+    (take 7 ['c','b' .. 'b']) = "cb"
+    (take 7 ['c','d' .. 'b']) = ""
+    (take 7 ['\251', '\252' .. maxBound]) = "\251\252\253\254\255"
+    (take 7 ['\5', '\4' .. minBound]) = "\ENQ\EOT\ETX\STX\SOH\NUL"
+Testing Enum (): 
+    (succ ()) = error "Prelude.Enum.succ{()}: not possible"
+    (succ (minBound::())) = error "Prelude.Enum.succ{()}: not possible"
+    (succ (maxBound::())) = error "Prelude.Enum.succ{()}: not possible"
+    (pred ()) = error "Prelude.Enum.pred{()}: not possible"
+    (pred (minBound::())) = error "Prelude.Enum.pred{()}: not possible"
+    (pred (maxBound::())) = error "Prelude.Enum.pred{()}: not possible"
+    (toEnum 0)::() = ()
+    (toEnum 1)::() = error "Prelude.Enum.toEnum{()}: argument not 0"
+    (fromEnum ()) = 0
+    ([()..]) = [()]
+    ([(),()..]) = [()]
+    ([()..()]) = [()]
+    ([(),()..()]) = [()]
+Testing Enum Ordering (derived): 
+    (succ LT) = EQ
+    (succ (minBound::Ordering)) = EQ
+    (succ (maxBound::Ordering)) = error "succ{Ordering}: tried to take `succ' of last tag in enumeration"
+    (pred GT) = EQ
+    (pred (maxBound::Ordering)) = EQ
+    (pred (minBound::Ordering)) = error "pred{Ordering}: tried to take `pred' of first tag in enumeration"
+    (toEnum 0)::Ordering = LT
+    (toEnum 5)::Ordering = error "toEnum{Ordering}: tag (5) is outside of enumeration's range (0,2)"
+    (fromEnum LT) = 0
+    (fromEnum EQ) = 1
+    (fromEnum GT) = 2
+    ([LT ..]) = [LT,EQ,GT]
+    ([EQ ..]) = [EQ,GT]
+    ([GT ..]) = [GT]
+    ([LT,EQ ..]) = [LT,EQ,GT]
+    ([EQ,GT ..]) = [EQ,GT]
+    ([EQ,LT ..]) = [EQ,LT]
+    ([LT,GT ..]) = [LT,GT]
+    ([GT,LT ..]) = [GT,LT]
+    take 7 (([GT,GT ..])) = [GT,GT,GT,GT,GT,GT,GT]
+    take 7 (([LT,LT ..])) = [LT,LT,LT,LT,LT,LT,LT]
+    ([LT .. GT]) = [LT,EQ,GT]
+    ([LT .. EQ]) = [LT,EQ]
+    ([LT .. LT]) = [LT]
+    ([GT .. LT]) = [GT,EQ,LT]
+    ([GT .. EQ]) = [GT,EQ]
+    ([GT .. GT]) = [GT]
+    ([LT,EQ .. GT]) = [LT,EQ,GT]
+    ([GT,EQ .. LT]) = [GT,EQ,LT]
+    ([GT,EQ .. EQ]) = [GT,EQ]
+    ([GT,EQ .. GT]) = [GT]
+    ([GT,EQ .. LT]) = [GT,EQ,LT]
+    ([LT,EQ .. LT]) = [LT]
+    ([LT,EQ .. GT]) = [LT,EQ,GT]
+    take 7 (([LT,LT .. GT])) = [LT,LT,LT,LT,LT,LT,LT]
+    take 7 (([GT,GT .. LT])) = []
+Testing Enum Bool: 
+    (succ False) = True
+    (succ (minBound::Bool)) = True
+    (succ (maxBound::Bool)) = error "succ{Bool}: tried to take `succ' of last tag in enumeration"
+    (pred True) = False
+    (pred (maxBound::Bool)) = False
+    (pred (minBound::Bool)) = error "pred{Bool}: tried to take `pred' of first tag in enumeration"
+    (toEnum 0)::Bool = False
+    (toEnum 5)::Bool = error "toEnum{Bool}: tag (5) is outside of enumeration's range (0,1)"
+    (fromEnum False) = 0
+    (fromEnum True) = 1
+    ([False ..]) = [False,True]
+    ([True ..]) = [True]
+    ([False,True ..]) = [False,True]
+    ([True,False ..]) = [True,False]
+    (take 7 ([False,False ..])) = [False,False,False,False,False,False,False]
+    (take 7 ([True,True ..])) = [True,True,True,True,True,True,True]
+    ([False .. True]) = [False,True]
+    ([True .. False]) = [True,False]
+    take 7 ([False,False .. False]) = [False,False,False,False,False,False,False]
+    take 7 ([False,False .. True]) = [False,False,False,False,False,False,False]
+    take 7 ([False,True .. False]) = [False]
+    take 7 ([False,True .. True]) = [False,True]
+    take 7 ([True,False .. False]) = [True,False]
+    take 7 ([True,False .. True]) = [True]
+    take 7 ([True,True .. False]) = []
+    take 7 ([True,True .. True]) = [True,True,True,True,True,True,True]
+Testing Enum Rational: 
+    (succ (0::Rational)) = 1 % 1
+    (succ ((-1)::Rational)) = 0 % 1
+    pred (1::Rational) = 0 % 1
+    pred (0::Rational) = -1 % 1
+    (map (toEnum::Int->Rational) [1,minBound,maxBound]) = [1 % 1,-2147483648 % 1,2147483647 % 1]
+    (map fromEnum [(1::Rational),42,45]) = [1,42,45]
+    (take 7 [(1::Rational)..]) = [1 % 1,2 % 1,3 % 1,4 % 1,5 % 1,6 % 1,7 % 1]
+    (take 7 [(-5::Rational)..]) = [-5 % 1,-4 % 1,-3 % 1,-2 % 1,-1 % 1,0 % 1,1 % 1]
+    (take 7 [(1::Rational),2..]) = [1 % 1,2 % 1,3 % 1,4 % 1,5 % 1,6 % 1,7 % 1]
+    (take 7 [(1::Rational),7..]) = [1 % 1,7 % 1,13 % 1,19 % 1,25 % 1,31 % 1,37 % 1]
+    (take 7 [(1::Rational),1..]) = [1 % 1,1 % 1,1 % 1,1 % 1,1 % 1,1 % 1,1 % 1]
+    (take 7 [(1::Rational),0..]) = [1 % 1,0 % 1,-1 % 1,-2 % 1,-3 % 1,-4 % 1,-5 % 1]
+    (take 7 [(5::Rational),2..]) = [5 % 1,2 % 1,-1 % 1,-4 % 1,-7 % 1,-10 % 1,-13 % 1]
+    (take 7 ([(1::Rational) .. 5])) = [1 % 1,2 % 1,3 % 1,4 % 1,5 % 1]
+    (take 4 ([(1::Rational) .. 1])) = [1 % 1]
+    (take 7 ([(1::Rational) .. 0])) = [1 % 1,0 % 1]
+    (take 7 ([(5::Rational) .. 0])) = [5 % 1,4 % 1,3 % 1,2 % 1,1 % 1,0 % 1]
+    (take 7 [(5::Rational),4..1]) = [5 % 1,4 % 1,3 % 1,2 % 1,1 % 1]
+    (take 7 [(5::Rational),3..1]) = [5 % 1,3 % 1,1 % 1]
+    (take 7 [(5::Rational),3..2]) = [5 % 1,3 % 1]
+    (take 7 [(1::Rational),2..1]) = [1 % 1]
+    (take 7 [(2::Rational),1..2]) = [2 % 1]
+    (take 7 [(2::Rational),1..1]) = [2 % 1,1 % 1]
+    (take 7 [(2::Rational),3..1]) = []
+Testing Enum (Ratio Int): 
+    (succ (0::Ratio Int)) = 1 % 1
+    (succ ((-1)::Ratio Int)) = 0 % 1
+    pred (1::Ratio Int) = 0 % 1
+    pred (0::Ratio Int) = -1 % 1
+    (map (toEnum::Int->Ratio Int) [1,minBound,maxBound]) = [1 % 1,-2147483648 % 1,2147483647 % 1]
+    (map fromEnum [(1::Ratio Int),42,45]) = [1,42,45]
+    (take 7 [(1::Ratio Int)..]) = [1 % 1,2 % 1,3 % 1,4 % 1,5 % 1,6 % 1,7 % 1]
+    (take 7 [(-5::Ratio Int)..]) = [-5 % 1,-4 % 1,-3 % 1,-2 % 1,-1 % 1,0 % 1,1 % 1]
+    (take 7 [((toEnum ((maxBound::Int)-5))::Ratio Int)..]) = [2147483642 % 1,2147483643 % 1,2147483644 % 1,2147483645 % 1,2147483646 % 1,2147483647 % 1]
+    (take 7 [(1::Ratio Int),2..]) = [1 % 1,2 % 1,3 % 1,4 % 1,5 % 1,6 % 1,7 % 1]
+    (take 7 [(1::Ratio Int),7..]) = [1 % 1,7 % 1,13 % 1,19 % 1,25 % 1,31 % 1,37 % 1]
+    (take 7 [(1::Ratio Int),1..]) = [1 % 1,1 % 1,1 % 1,1 % 1,1 % 1,1 % 1,1 % 1]
+    (take 7 [(1::Ratio Int),0..]) = [1 % 1,0 % 1,-1 % 1,-2 % 1,-3 % 1,-4 % 1,-5 % 1]
+    (take 7 [(5::Ratio Int),2..]) = [5 % 1,2 % 1,-1 % 1,-4 % 1,-7 % 1,-10 % 1,-13 % 1]
+    (take 7 [x, x-1 ..]) = [-2147483647 % 1,-2147483648 % 1]
+    (take 7 [x, x-1 ..]) = [-2147483643 % 1,-2147483644 % 1,-2147483645 % 1,-2147483646 % 1,-2147483647 % 1,-2147483648 % 1]
+    (take 7 [x, (x+1) ..]) = [2147483642 % 1,2147483643 % 1,2147483644 % 1,2147483645 % 1,2147483646 % 1,2147483647 % 1]
+    (take 7 ([(1::Ratio Int) .. 5])) = [1 % 1,2 % 1,3 % 1,4 % 1,5 % 1]
+    (take 4 ([(1::Ratio Int) .. 1])) = [1 % 1]
+    (take 7 ([(1::Ratio Int) .. 0])) = [1 % 1,0 % 1]
+    (take 7 ([(5::Ratio Int) .. 0])) = [5 % 1,4 % 1,3 % 1,2 % 1,1 % 1,0 % 1]
+    (take 7 ([x..y])) = [2147483642 % 1,2147483643 % 1,2147483644 % 1,2147483645 % 1,2147483646 % 1,2147483647 % 1]
+    (take 7 ([x..y])) = [-2147483643 % 1,-2147483644 % 1,-2147483645 % 1,-2147483646 % 1,-2147483647 % 1,-2147483648 % 1]
+    (take 7 [(5::Ratio Int),4..1]) = [5 % 1,4 % 1,3 % 1,2 % 1,1 % 1]
+    (take 7 [(5::Ratio Int),3..1]) = [5 % 1,3 % 1,1 % 1]
+    (take 7 [(5::Ratio Int),3..2]) = [5 % 1,3 % 1]
+    (take 7 [(1::Ratio Int),2..1]) = [1 % 1]
+    (take 7 [(2::Ratio Int),1..2]) = [2 % 1]
+    (take 7 [(2::Ratio Int),1..1]) = [2 % 1,1 % 1]
+    (take 7 [(2::Ratio Int),3..1]) = []
+    (take 7 [x,(x+1)..y]) = [2147483643 % 1,2147483644 % 1,2147483645 % 1,2147483646 % 1,2147483647 % 1]
+    (take 7 [x,(x-1)..y]) = [-2147483643 % 1,-2147483644 % 1,-2147483645 % 1,-2147483646 % 1,-2147483647 % 1,-2147483648 % 1]
diff --git a/ghc/tests/lib/should_run/enum02.hs b/ghc/tests/lib/should_run/enum02.hs
new file mode 100644 (file)
index 0000000..27be3fd
--- /dev/null
@@ -0,0 +1,268 @@
+-- !!! Testing the Int Enum instances.
+module Main(main) where
+
+import Exception
+import Int
+
+main = do
+  putStrLn "Testing Enum Int8:"
+  testEnumInt8
+  putStrLn "Testing Enum Int16:"
+  testEnumInt16
+  putStrLn "Testing Enum Int32:"
+  testEnumInt32
+  putStrLn "Testing Enum Int64:"
+  testEnumInt64
+
+#define printTest(x) (do{ putStr ( "    " ++ "x" ++ " = " ) ; print (x) })
+
+testEnumInt8 :: IO ()
+testEnumInt8 = do
+     -- succ
+  printTest ((succ (0::Int8)))
+  printTest ((succ (minBound::Int8)))
+  mayBomb   (printTest ((succ (maxBound::Int8))))
+
+     -- pred
+  printTest (pred (1::Int8))
+  printTest (pred (maxBound::Int8))
+  mayBomb   (printTest (pred (minBound::Int8))) 
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Int8) [1, toInt (minBound::Int8), toInt (maxBound::Int8)]))
+  mayBomb   (printTest ((toEnum (maxBound::Int))::Int8))
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Int8),minBound,maxBound]))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Int8)..]))
+  printTest ((take 7 [((maxBound::Int8)-5)..])) -- just in case it doesn't catch the upper bound..
+  
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Int8),2..]))
+  printTest ((take 7 [(1::Int8),7..]))
+  printTest ((take 7 [(1::Int8),1..]))
+  printTest ((take 7 [(1::Int8),0..]))
+  printTest ((take 7 [(5::Int8),2..]))
+  let x = (minBound::Int8) + 1
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (minBound::Int8) + 5
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (maxBound::Int8) - 5
+  printTest ((take 7 [x, (x+1) ..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Int8) .. 5])))
+  printTest ((take 4 ([(1::Int8) .. 1])))
+  printTest ((take 7 ([(1::Int8) .. 0])))
+  printTest ((take 7 ([(5::Int8) .. 0])))
+  printTest ((take 7 ([(maxBound-(5::Int8)) .. maxBound])))
+  printTest ((take 7 ([(minBound+(5::Int8)) .. minBound])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Int8),4..1]))
+  printTest ((take 7 [(5::Int8),3..1]))
+  printTest ((take 7 [(5::Int8),3..2]))
+  printTest ((take 7 [(1::Int8),2..1]))
+  printTest ((take 7 [(2::Int8),1..2]))
+  printTest ((take 7 [(2::Int8),1..1]))
+  printTest ((take 7 [(2::Int8),3..1]))
+
+  let x = (maxBound::Int8) - 4
+  printTest ((take 7 [x,(x+1)..maxBound]))
+  let x = (minBound::Int8) + 5
+  printTest ((take 7 [x,(x-1)..minBound]))
+
+testEnumInt16 :: IO ()
+testEnumInt16 = do
+     -- succ
+  printTest ((succ (0::Int16)))
+  printTest ((succ (minBound::Int16)))
+  mayBomb   (printTest ((succ (maxBound::Int16))))
+
+     -- pred
+  printTest (pred (1::Int16))
+  printTest (pred (maxBound::Int16))
+  mayBomb   (printTest (pred (minBound::Int16))) 
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Int16) [1, toInt (minBound::Int16), toInt (maxBound::Int16)]))
+  mayBomb   (printTest ((toEnum (maxBound::Int))::Int16))
+
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Int16),minBound,maxBound]))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Int16)..]))
+  printTest ((take 7 [((maxBound::Int16)-5)..])) -- just in case it doesn't catch the upper bound..
+  
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Int16),2..]))
+  printTest ((take 7 [(1::Int16),7..]))
+  printTest ((take 7 [(1::Int16),1..]))
+  printTest ((take 7 [(1::Int16),0..]))
+  printTest ((take 7 [(5::Int16),2..]))
+  let x = (minBound::Int16) + 1
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (minBound::Int16) + 5
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (maxBound::Int16) - 5
+  printTest ((take 7 [x, (x+1) ..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Int16) .. 5])))
+  printTest ((take 4 ([(1::Int16) .. 1])))
+  printTest ((take 7 ([(1::Int16) .. 0])))
+  printTest ((take 7 ([(5::Int16) .. 0])))
+  printTest ((take 7 ([(maxBound-(5::Int16)) .. maxBound])))
+  printTest ((take 7 ([(minBound+(5::Int16)) .. minBound])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Int16),4..1]))
+  printTest ((take 7 [(5::Int16),3..1]))
+  printTest ((take 7 [(5::Int16),3..2]))
+  printTest ((take 7 [(1::Int16),2..1]))
+  printTest ((take 7 [(2::Int16),1..2]))
+  printTest ((take 7 [(2::Int16),1..1]))
+  printTest ((take 7 [(2::Int16),3..1]))
+
+  let x = (maxBound::Int16) - 4
+  printTest ((take 7 [x,(x+1)..maxBound]))
+  let x = (minBound::Int16) + 5
+  printTest ((take 7 [x,(x-1)..minBound]))
+
+testEnumInt32 :: IO ()
+testEnumInt32 = do
+     -- succ
+  printTest ((succ (0::Int32)))
+  printTest ((succ (minBound::Int32)))
+  mayBomb   (printTest ((succ (maxBound::Int32))))
+
+     -- pred
+  printTest (pred (1::Int32))
+  printTest (pred (maxBound::Int32))
+  mayBomb   (printTest (pred (minBound::Int32))) 
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Int32) [1, toInt (minBound::Int32), toInt (maxBound::Int32)]))
+  mayBomb   (printTest ((toEnum (maxBound::Int))::Int32))
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Int32),minBound,maxBound]))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Int32)..]))
+  printTest ((take 7 [((maxBound::Int32)-5)..])) -- just in case it doesn't catch the upper bound..
+  
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Int32),2..]))
+  printTest ((take 7 [(1::Int32),7..]))
+  printTest ((take 7 [(1::Int32),1..]))
+  printTest ((take 7 [(1::Int32),0..]))
+  printTest ((take 7 [(5::Int32),2..]))
+  let x = (minBound::Int32) + 1
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (minBound::Int32) + 5
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (maxBound::Int32) - 5
+  printTest ((take 7 [x, (x+1) ..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Int32) .. 5])))
+  printTest ((take 4 ([(1::Int32) .. 1])))
+  printTest ((take 7 ([(1::Int32) .. 0])))
+  printTest ((take 7 ([(5::Int32) .. 0])))
+  printTest ((take 7 ([(maxBound-(5::Int32)) .. maxBound])))
+  printTest ((take 7 ([(minBound+(5::Int32)) .. minBound])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Int32),4..1]))
+  printTest ((take 7 [(5::Int32),3..1]))
+  printTest ((take 7 [(5::Int32),3..2]))
+  printTest ((take 7 [(1::Int32),2..1]))
+  printTest ((take 7 [(2::Int32),1..2]))
+  printTest ((take 7 [(2::Int32),1..1]))
+  printTest ((take 7 [(2::Int32),3..1]))
+
+  let x = (maxBound::Int32) - 4
+  printTest ((take 7 [x,(x+1)..maxBound]))
+  let x = (minBound::Int32) + 5
+  printTest ((take 7 [x,(x-1)..minBound]))
+
+testEnumInt64 :: IO ()
+testEnumInt64 = do
+     -- succ
+  printTest ((succ (0::Int64)))
+  printTest ((succ (minBound::Int64)))
+  mayBomb   (printTest ((succ (maxBound::Int64))))
+
+     -- pred
+  printTest (pred (1::Int64))
+  printTest (pred (maxBound::Int64))
+  mayBomb   (printTest (pred (minBound::Int64))) 
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Int64) [1, toInt (minBound::Int64), toInt (maxBound::Int64)]))
+  mayBomb   (printTest ((toEnum (maxBound::Int))::Int64))
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Int64),fromInt (minBound::Int) ,fromInt (maxBound::Int)]))
+  mayBomb   (printTest (fromEnum (maxBound::Int64)))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Int64)..]))
+  printTest ((take 7 [((maxBound::Int64)-5)..])) -- just in case it doesn't catch the upper bound..
+
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Int64),2..]))
+  printTest ((take 7 [(1::Int64),7..]))
+  printTest ((take 7 [(1::Int64),1..]))
+  printTest ((take 7 [(1::Int64),0..]))
+  printTest ((take 7 [(5::Int64),2..]))
+  let x = (minBound::Int64) + 1
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (minBound::Int64) + 5
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (maxBound::Int64) - 5
+  printTest ((take 7 [x, (x+1) ..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Int64) .. 5])))
+  printTest ((take 4 ([(1::Int64) .. 1])))
+  printTest ((take 7 ([(1::Int64) .. 0])))
+  printTest ((take 7 ([(5::Int64) .. 0])))
+  printTest ((take 7 ([(maxBound-(5::Int64)) .. maxBound])))
+  printTest ((take 7 ([(minBound+(5::Int64)) .. minBound])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Int64),4..1]))
+  printTest ((take 7 [(5::Int64),3..1]))
+  printTest ((take 7 [(5::Int64),3..2]))
+  printTest ((take 7 [(1::Int64),2..1]))
+  printTest ((take 7 [(2::Int64),1..2]))
+  printTest ((take 7 [(2::Int64),1..1]))
+  printTest ((take 7 [(2::Int64),3..1]))
+
+  let x = (maxBound::Int64) - 4
+  printTest ((take 7 [x,(x+1)..maxBound]))
+  let x = (minBound::Int64) + 5
+  printTest ((take 7 [x,(x-1)..minBound]))
+
+
+--
+--
+--  Utils
+--
+--
+
+
+mayBomb x = catchAllIO x errorHandler
+
+errorHandler :: Exception -> IO ()
+errorHandler e =
+  case justErrors e of
+    Just t -> putStrLn ("error " ++ show t)
+    _     -> return ()
diff --git a/ghc/tests/lib/should_run/enum02.stdout b/ghc/tests/lib/should_run/enum02.stdout
new file mode 100644 (file)
index 0000000..d0d8e33
--- /dev/null
@@ -0,0 +1,141 @@
+Testing Enum Int8:
+    (succ (0::Int8)) = 1
+    (succ (minBound::Int8)) = -127
+    (succ (maxBound::Int8)) = error "Enum.succ{Int8}: tried to take `succ' of maxBound"
+    pred (1::Int8) = 0
+    pred (maxBound::Int8) = 126
+    pred (minBound::Int8) = error "Enum.pred{Int8}: tried to take `pred' of minBound"
+    (map (toEnum::Int->Int8) [1, toInt (minBound::Int8), toInt (maxBound::Int8)]) = [1,-128,127]
+    (toEnum (maxBound::Int))::Int8 = error "Enum.toEnum{Int8}: tag (2147483647) is outside of bounds (-128,127)"
+    (map fromEnum [(1::Int8),minBound,maxBound]) = [1,-128,127]
+    (take 7 [(1::Int8)..]) = [1,2,3,4,5,6,7]
+    (take 7 [((maxBound::Int8)-5)..]) = [122,123,124,125,126,127]
+    (take 7 [(1::Int8),2..]) = [1,2,3,4,5,6,7]
+    (take 7 [(1::Int8),7..]) = [1,7,13,19,25,31,37]
+    (take 7 [(1::Int8),1..]) = [1,1,1,1,1,1,1]
+    (take 7 [(1::Int8),0..]) = [1,0,-1,-2,-3,-4,-5]
+    (take 7 [(5::Int8),2..]) = [5,2,-1,-4,-7,-10,-13]
+    (take 7 [x, x-1 ..]) = [-127,-128]
+    (take 7 [x, x-1 ..]) = [-123,-124,-125,-126,-127,-128]
+    (take 7 [x, (x+1) ..]) = [122,123,124,125,126,127]
+    (take 7 ([(1::Int8) .. 5])) = [1,2,3,4,5]
+    (take 4 ([(1::Int8) .. 1])) = [1]
+    (take 7 ([(1::Int8) .. 0])) = [1,0]
+    (take 7 ([(5::Int8) .. 0])) = [5,4,3,2,1,0]
+    (take 7 ([(maxBound-(5::Int8)) .. maxBound])) = [122,123,124,125,126,127]
+    (take 7 ([(minBound+(5::Int8)) .. minBound])) = [-123,-124,-125,-126,-127,-128]
+    (take 7 [(5::Int8),4..1]) = [5,4,3,2,1]
+    (take 7 [(5::Int8),3..1]) = [5,3,1]
+    (take 7 [(5::Int8),3..2]) = [5,3]
+    (take 7 [(1::Int8),2..1]) = [1]
+    (take 7 [(2::Int8),1..2]) = [2]
+    (take 7 [(2::Int8),1..1]) = [2,1]
+    (take 7 [(2::Int8),3..1]) = []
+    (take 7 [x,(x+1)..maxBound]) = [123,124,125,126,127]
+    (take 7 [x,(x-1)..minBound]) = [-123,-124,-125,-126,-127,-128]
+Testing Enum Int16:
+    (succ (0::Int16)) = 1
+    (succ (minBound::Int16)) = -32767
+    (succ (maxBound::Int16)) = error "Enum.succ{Int16}: tried to take `succ' of maxBound"
+    pred (1::Int16) = 0
+    pred (maxBound::Int16) = 32766
+    pred (minBound::Int16) = error "Enum.pred{Int16}: tried to take `pred' of minBound"
+    (map (toEnum::Int->Int16) [1, toInt (minBound::Int16), toInt (maxBound::Int16)]) = [1,-32768,32767]
+    (toEnum (maxBound::Int))::Int16 = error "Enum.toEnum{Int16}: tag (2147483647) is outside of bounds (-32768,32767)"
+    (map fromEnum [(1::Int16),minBound,maxBound]) = [1,-32768,32767]
+    (take 7 [(1::Int16)..]) = [1,2,3,4,5,6,7]
+    (take 7 [((maxBound::Int16)-5)..]) = [32762,32763,32764,32765,32766,32767]
+    (take 7 [(1::Int16),2..]) = [1,2,3,4,5,6,7]
+    (take 7 [(1::Int16),7..]) = [1,7,13,19,25,31,37]
+    (take 7 [(1::Int16),1..]) = [1,1,1,1,1,1,1]
+    (take 7 [(1::Int16),0..]) = [1,0,-1,-2,-3,-4,-5]
+    (take 7 [(5::Int16),2..]) = [5,2,-1,-4,-7,-10,-13]
+    (take 7 [x, x-1 ..]) = [-32767,-32768]
+    (take 7 [x, x-1 ..]) = [-32763,-32764,-32765,-32766,-32767,-32768]
+    (take 7 [x, (x+1) ..]) = [32762,32763,32764,32765,32766,32767]
+    (take 7 ([(1::Int16) .. 5])) = [1,2,3,4,5]
+    (take 4 ([(1::Int16) .. 1])) = [1]
+    (take 7 ([(1::Int16) .. 0])) = [1,0]
+    (take 7 ([(5::Int16) .. 0])) = [5,4,3,2,1,0]
+    (take 7 ([(maxBound-(5::Int16)) .. maxBound])) = [32762,32763,32764,32765,32766,32767]
+    (take 7 ([(minBound+(5::Int16)) .. minBound])) = [-32763,-32764,-32765,-32766,-32767,-32768]
+    (take 7 [(5::Int16),4..1]) = [5,4,3,2,1]
+    (take 7 [(5::Int16),3..1]) = [5,3,1]
+    (take 7 [(5::Int16),3..2]) = [5,3]
+    (take 7 [(1::Int16),2..1]) = [1]
+    (take 7 [(2::Int16),1..2]) = [2]
+    (take 7 [(2::Int16),1..1]) = [2,1]
+    (take 7 [(2::Int16),3..1]) = []
+    (take 7 [x,(x+1)..maxBound]) = [32763,32764,32765,32766,32767]
+    (take 7 [x,(x-1)..minBound]) = [-32763,-32764,-32765,-32766,-32767,-32768]
+Testing Enum Int32:
+    (succ (0::Int32)) = 1
+    (succ (minBound::Int32)) = -2147483647
+    (succ (maxBound::Int32)) = error "Enum.succ{Int32}: tried to take `succ' of maxBound"
+    pred (1::Int32) = 0
+    pred (maxBound::Int32) = 2147483646
+    pred (minBound::Int32) = error "Enum.pred{Int32}: tried to take `pred' of minBound"
+    (map (toEnum::Int->Int32) [1, toInt (minBound::Int32), toInt (maxBound::Int32)]) = [1,-2147483648,2147483647]
+    (toEnum (maxBound::Int))::Int32 = 2147483647
+    (map fromEnum [(1::Int32),minBound,maxBound]) = [1,-2147483648,2147483647]
+    (take 7 [(1::Int32)..]) = [1,2,3,4,5,6,7]
+    (take 7 [((maxBound::Int32)-5)..]) = [2147483642,2147483643,2147483644,2147483645,2147483646,2147483647]
+    (take 7 [(1::Int32),2..]) = [1,2,3,4,5,6,7]
+    (take 7 [(1::Int32),7..]) = [1,7,13,19,25,31,37]
+    (take 7 [(1::Int32),1..]) = [1,1,1,1,1,1,1]
+    (take 7 [(1::Int32),0..]) = [1,0,-1,-2,-3,-4,-5]
+    (take 7 [(5::Int32),2..]) = [5,2,-1,-4,-7,-10,-13]
+    (take 7 [x, x-1 ..]) = [-2147483647,-2147483648]
+    (take 7 [x, x-1 ..]) = [-2147483643,-2147483644,-2147483645,-2147483646,-2147483647,-2147483648]
+    (take 7 [x, (x+1) ..]) = [2147483642,2147483643,2147483644,2147483645,2147483646,2147483647]
+    (take 7 ([(1::Int32) .. 5])) = [1,2,3,4,5]
+    (take 4 ([(1::Int32) .. 1])) = [1]
+    (take 7 ([(1::Int32) .. 0])) = [1,0]
+    (take 7 ([(5::Int32) .. 0])) = [5,4,3,2,1,0]
+    (take 7 ([(maxBound-(5::Int32)) .. maxBound])) = [2147483642,2147483643,2147483644,2147483645,2147483646,2147483647]
+    (take 7 ([(minBound+(5::Int32)) .. minBound])) = [-2147483643,-2147483644,-2147483645,-2147483646,-2147483647,-2147483648]
+    (take 7 [(5::Int32),4..1]) = [5,4,3,2,1]
+    (take 7 [(5::Int32),3..1]) = [5,3,1]
+    (take 7 [(5::Int32),3..2]) = [5,3]
+    (take 7 [(1::Int32),2..1]) = [1]
+    (take 7 [(2::Int32),1..2]) = [2]
+    (take 7 [(2::Int32),1..1]) = [2,1]
+    (take 7 [(2::Int32),3..1]) = []
+    (take 7 [x,(x+1)..maxBound]) = [2147483643,2147483644,2147483645,2147483646,2147483647]
+    (take 7 [x,(x-1)..minBound]) = [-2147483643,-2147483644,-2147483645,-2147483646,-2147483647,-2147483648]
+Testing Enum Int64:
+    (succ (0::Int64)) = 1
+    (succ (minBound::Int64)) = -9223372036854775807
+    (succ (maxBound::Int64)) = error "Enum.succ{Int64}: tried to take `succ' of maxBound"
+    pred (1::Int64) = 0
+    pred (maxBound::Int64) = 9223372036854775806
+    pred (minBound::Int64) = error "Enum.pred{Int64}: tried to take `pred' of minBound"
+    (map (toEnum::Int->Int64) [1, toInt (minBound::Int64), toInt (maxBound::Int64)]) = [1,0,-1]
+    (toEnum (maxBound::Int))::Int64 = 2147483647
+    (map fromEnum [(1::Int64),fromInt (minBound::Int) ,fromInt (maxBound::Int)]) = [1,-2147483648,2147483647]
+    fromEnum (maxBound::Int64) = error "Enum.fromEnum{Int64}: value (9223372036854775807) is outside of Int's bounds (-2147483648,2147483647)"
+    (take 7 [(1::Int64)..]) = [1,2,3,4,5,6,7]
+    (take 7 [((maxBound::Int64)-5)..]) = [9223372036854775802,9223372036854775803,9223372036854775804,9223372036854775805,9223372036854775806,9223372036854775807]
+    (take 7 [(1::Int64),2..]) = [1,2,3,4,5,6,7]
+    (take 7 [(1::Int64),7..]) = [1,7,13,19,25,31,37]
+    (take 7 [(1::Int64),1..]) = [1,1,1,1,1,1,1]
+    (take 7 [(1::Int64),0..]) = [1,0,-1,-2,-3,-4,-5]
+    (take 7 [(5::Int64),2..]) = [5,2,-1,-4,-7,-10,-13]
+    (take 7 [x, x-1 ..]) = [-9223372036854775807,-9223372036854775808]
+    (take 7 [x, x-1 ..]) = [-9223372036854775803,-9223372036854775804,-9223372036854775805,-9223372036854775806,-9223372036854775807,-9223372036854775808]
+    (take 7 [x, (x+1) ..]) = [9223372036854775802,9223372036854775803,9223372036854775804,9223372036854775805,9223372036854775806,9223372036854775807]
+    (take 7 ([(1::Int64) .. 5])) = [1,2,3,4,5]
+    (take 4 ([(1::Int64) .. 1])) = [1]
+    (take 7 ([(1::Int64) .. 0])) = [1,0]
+    (take 7 ([(5::Int64) .. 0])) = [5,4,3,2,1,0]
+    (take 7 ([(maxBound-(5::Int64)) .. maxBound])) = [9223372036854775802,9223372036854775803,9223372036854775804,9223372036854775805,9223372036854775806,9223372036854775807]
+    (take 7 ([(minBound+(5::Int64)) .. minBound])) = [-9223372036854775803,-9223372036854775804,-9223372036854775805,-9223372036854775806,-9223372036854775807,-9223372036854775808]
+    (take 7 [(5::Int64),4..1]) = [5,4,3,2,1]
+    (take 7 [(5::Int64),3..1]) = [5,3,1]
+    (take 7 [(5::Int64),3..2]) = [5,3]
+    (take 7 [(1::Int64),2..1]) = [1]
+    (take 7 [(2::Int64),1..2]) = [2]
+    (take 7 [(2::Int64),1..1]) = [2,1]
+    (take 7 [(2::Int64),3..1]) = []
+    (take 7 [x,(x+1)..maxBound]) = [9223372036854775803,9223372036854775804,9223372036854775805,9223372036854775806,9223372036854775807]
+    (take 7 [x,(x-1)..minBound]) = [-9223372036854775803,-9223372036854775804,-9223372036854775805,-9223372036854775806,-9223372036854775807,-9223372036854775808]
diff --git a/ghc/tests/lib/should_run/enum03.hs b/ghc/tests/lib/should_run/enum03.hs
new file mode 100644 (file)
index 0000000..6d25333
--- /dev/null
@@ -0,0 +1,270 @@
+-- !!! Testing the Word Enum instances.
+module Main(main) where
+
+import Exception
+import Word
+
+main = do
+  putStrLn "Testing Enum Word8:"
+  testEnumWord8
+  putStrLn "Testing Enum Word16:"
+  testEnumWord16
+  putStrLn "Testing Enum Word32:"
+  testEnumWord32
+  putStrLn "Testing Enum Word64:"
+  testEnumWord64
+
+
+#define printTest(x) (do{ putStr ( "    " ++ "x" ++ " = " ) ; print (x) })
+
+testEnumWord8 :: IO ()
+testEnumWord8 = do
+     -- succ
+  printTest ((succ (0::Word8)))
+  printTest ((succ (minBound::Word8)))
+  mayBomb   (printTest ((succ (maxBound::Word8))))
+
+     -- pred
+  printTest (pred (1::Word8))
+  printTest (pred (maxBound::Word8))
+  mayBomb   (printTest (pred (minBound::Word8))) 
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Word8) [1, toInt (minBound::Word8), toInt (maxBound::Word8)]))
+  mayBomb   (printTest ((toEnum (maxBound::Int))::Word8))
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Word8),minBound,maxBound]))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Word8)..]))
+  printTest ((take 7 [((maxBound::Word8)-5)..])) -- just in case it doesn't catch the upper bound..
+  
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Word8),2..]))
+  printTest ((take 7 [(1::Word8),7..]))
+  printTest ((take 7 [(1::Word8),1..]))
+  printTest ((take 7 [(1::Word8),0..]))
+  printTest ((take 7 [(5::Word8),2..]))
+  let x = (minBound::Word8) + 1
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (minBound::Word8) + 5
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (maxBound::Word8) - 5
+  printTest ((take 7 [x, (x+1) ..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Word8) .. 5])))
+  printTest ((take 4 ([(1::Word8) .. 1])))
+  printTest ((take 7 ([(1::Word8) .. 0])))
+  printTest ((take 7 ([(5::Word8) .. 0])))
+  printTest ((take 7 ([(maxBound-(5::Word8)) .. maxBound])))
+  printTest ((take 7 ([(minBound+(5::Word8)) .. minBound])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Word8),4..1]))
+  printTest ((take 7 [(5::Word8),3..1]))
+  printTest ((take 7 [(5::Word8),3..2]))
+  printTest ((take 7 [(1::Word8),2..1]))
+  printTest ((take 7 [(2::Word8),1..2]))
+  printTest ((take 7 [(2::Word8),1..1]))
+  printTest ((take 7 [(2::Word8),3..1]))
+
+  let x = (maxBound::Word8) - 4
+  printTest ((take 7 [x,(x+1)..maxBound]))
+  let x = (minBound::Word8) + 5
+  printTest ((take 7 [x,(x-1)..minBound]))
+
+testEnumWord16 :: IO ()
+testEnumWord16 = do
+     -- succ
+  printTest ((succ (0::Word16)))
+  printTest ((succ (minBound::Word16)))
+  mayBomb   (printTest ((succ (maxBound::Word16))))
+
+     -- pred
+  printTest (pred (1::Word16))
+  printTest (pred (maxBound::Word16))
+  mayBomb   (printTest (pred (minBound::Word16))) 
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Word16) [1, toInt (minBound::Word16), toInt (maxBound::Word16)]))
+  mayBomb   (printTest ((toEnum (maxBound::Int))::Word16))
+
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Word16),minBound,maxBound]))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Word16)..]))
+  printTest ((take 7 [((maxBound::Word16)-5)..])) -- just in case it doesn't catch the upper bound..
+  
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Word16),2..]))
+  printTest ((take 7 [(1::Word16),7..]))
+  printTest ((take 7 [(1::Word16),1..]))
+  printTest ((take 7 [(1::Word16),0..]))
+  printTest ((take 7 [(5::Word16),2..]))
+  let x = (minBound::Word16) + 1
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (minBound::Word16) + 5
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (maxBound::Word16) - 5
+  printTest ((take 7 [x, (x+1) ..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Word16) .. 5])))
+  printTest ((take 4 ([(1::Word16) .. 1])))
+  printTest ((take 7 ([(1::Word16) .. 0])))
+  printTest ((take 7 ([(5::Word16) .. 0])))
+  printTest ((take 7 ([(maxBound-(5::Word16)) .. maxBound])))
+  printTest ((take 7 ([(minBound+(5::Word16)) .. minBound])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Word16),4..1]))
+  printTest ((take 7 [(5::Word16),3..1]))
+  printTest ((take 7 [(5::Word16),3..2]))
+  printTest ((take 7 [(1::Word16),2..1]))
+  printTest ((take 7 [(2::Word16),1..2]))
+  printTest ((take 7 [(2::Word16),1..1]))
+  printTest ((take 7 [(2::Word16),3..1]))
+
+  let x = (maxBound::Word16) - 4
+  printTest ((take 7 [x,(x+1)..maxBound]))
+  let x = (minBound::Word16) + 5
+  printTest ((take 7 [x,(x-1)..minBound]))
+
+testEnumWord32 :: IO ()
+testEnumWord32 = do
+     -- succ
+  printTest ((succ (0::Word32)))
+  printTest ((succ (minBound::Word32)))
+  mayBomb   (printTest ((succ (maxBound::Word32))))
+
+     -- pred
+  printTest (pred (1::Word32))
+  printTest (pred (maxBound::Word32))
+  mayBomb   (printTest (pred (minBound::Word32))) 
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Word32) [1, toInt (minBound::Word32), maxBound::Int]))
+  mayBomb   (printTest ((toEnum (maxBound::Int))::Word32))
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Word32),minBound,fromInt (maxBound::Int)]))
+  mayBomb   (printTest (fromEnum (maxBound::Word32)))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Word32)..]))
+  printTest ((take 7 [((maxBound::Word32)-5)..])) -- just in case it doesn't catch the upper bound..
+  
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Word32),2..]))
+  printTest ((take 7 [(1::Word32),7..]))
+  printTest ((take 7 [(1::Word32),1..]))
+  printTest ((take 7 [(1::Word32),0..]))
+  printTest ((take 7 [(5::Word32),2..]))
+  let x = (minBound::Word32) + 1
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (minBound::Word32) + 5
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (maxBound::Word32) - 5
+  printTest ((take 7 [x, (x+1) ..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Word32) .. 5])))
+  printTest ((take 4 ([(1::Word32) .. 1])))
+  printTest ((take 7 ([(1::Word32) .. 0])))
+  printTest ((take 7 ([(5::Word32) .. 0])))
+  printTest ((take 7 ([(maxBound-(5::Word32)) .. maxBound])))
+  printTest ((take 7 ([(minBound+(5::Word32)) .. minBound])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Word32),4..1]))
+  printTest ((take 7 [(5::Word32),3..1]))
+  printTest ((take 7 [(5::Word32),3..2]))
+  printTest ((take 7 [(1::Word32),2..1]))
+  printTest ((take 7 [(2::Word32),1..2]))
+  printTest ((take 7 [(2::Word32),1..1]))
+  printTest ((take 7 [(2::Word32),3..1]))
+
+  let x = (maxBound::Word32) - 4
+  printTest ((take 7 [x,(x+1)..maxBound]))
+  let x = (minBound::Word32) + 5
+  printTest ((take 7 [x,(x-1)..minBound]))
+
+testEnumWord64 :: IO ()
+testEnumWord64 = do
+     -- succ
+  printTest ((succ (0::Word64)))
+  printTest ((succ (minBound::Word64)))
+  mayBomb   (printTest ((succ (maxBound::Word64))))
+
+     -- pred
+  printTest (pred (1::Word64))
+  printTest (pred (maxBound::Word64))
+  mayBomb   (printTest (pred (minBound::Word64))) 
+
+     -- toEnum
+  printTest ((map (toEnum::Int->Word64) [1, toInt (minBound::Word64), maxBound::Int]))
+  mayBomb   (printTest ((toEnum (maxBound::Int))::Word64))
+
+     -- fromEnum
+  printTest ((map fromEnum [(1::Word64),minBound,fromInt (maxBound::Int)]))
+  mayBomb   (printTest (fromEnum (maxBound::Word64)))
+
+     -- [x..] aka enumFrom
+  printTest ((take 7 [(1::Word64)..]))
+  printTest ((take 7 [((maxBound::Word64)-5)..])) -- just in case it doesn't catch the upper bound..
+
+     -- [x,y..] aka enumFromThen
+  printTest ((take 7 [(1::Word64),2..]))
+  printTest ((take 7 [(1::Word64),7..]))
+  printTest ((take 7 [(1::Word64),1..]))
+  printTest ((take 7 [(1::Word64),0..]))
+  printTest ((take 7 [(5::Word64),2..]))
+  let x = (minBound::Word64) + 1
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (minBound::Word64) + 5
+  printTest ((take 7 [x, x-1 ..]))
+  let x = (maxBound::Word64) - 5
+  printTest ((take 7 [x, (x+1) ..]))
+
+     -- [x..y] aka enumFromTo
+  printTest ((take 7 ([(1::Word64) .. 5])))
+  printTest ((take 4 ([(1::Word64) .. 1])))
+  printTest ((take 7 ([(1::Word64) .. 0])))
+  printTest ((take 7 ([(5::Word64) .. 0])))
+  printTest ((take 7 ([(maxBound-(5::Word64)) .. maxBound])))
+  printTest ((take 7 ([(minBound+(5::Word64)) .. minBound])))
+
+     -- [x,y..z] aka enumFromThenTo
+  printTest ((take 7 [(5::Word64),4..1]))
+  printTest ((take 7 [(5::Word64),3..1]))
+  printTest ((take 7 [(5::Word64),3..2]))
+  printTest ((take 7 [(1::Word64),2..1]))
+  printTest ((take 7 [(2::Word64),1..2]))
+  printTest ((take 7 [(2::Word64),1..1]))
+  printTest ((take 7 [(2::Word64),3..1]))
+
+  let x = (maxBound::Word64) - 4
+  printTest ((take 7 [x,(x+1)..maxBound]))
+  let x = (minBound::Word64) + 5
+  printTest ((take 7 [x,(x-1)..minBound]))
+
+
+--
+--
+--  Utils
+--
+--
+
+
+mayBomb x = catchAllIO x errorHandler
+
+errorHandler :: Exception -> IO ()
+errorHandler e =
+  case justErrors e of
+    Just t -> putStrLn ("error " ++ show t)
+    _     -> return ()
diff --git a/ghc/tests/lib/should_run/enum03.stdout b/ghc/tests/lib/should_run/enum03.stdout
new file mode 100644 (file)
index 0000000..2b93de1
--- /dev/null
@@ -0,0 +1,142 @@
+Testing Enum Word8:
+    (succ (0::Word8)) = 1
+    (succ (minBound::Word8)) = 1
+    (succ (maxBound::Word8)) = error "Enum.succ{Word8}: tried to take `succ' of maxBound"
+    pred (1::Word8) = 0
+    pred (maxBound::Word8) = 254
+    pred (minBound::Word8) = error "Enum.pred{Word8}: tried to take `pred' of minBound"
+    (map (toEnum::Int->Word8) [1, toInt (minBound::Word8), toInt (maxBound::Word8)]) = [1,0,255]
+    (toEnum (maxBound::Int))::Word8 = error "Enum.toEnum{Word8}: tag (2147483647) is outside of bounds (0,255)"
+    (map fromEnum [(1::Word8),minBound,maxBound]) = [1,0,255]
+    (take 7 [(1::Word8)..]) = [1,2,3,4,5,6,7]
+    (take 7 [((maxBound::Word8)-5)..]) = [250,251,252,253,254,255]
+    (take 7 [(1::Word8),2..]) = [1,2,3,4,5,6,7]
+    (take 7 [(1::Word8),7..]) = [1,7,13,19,25,31,37]
+    (take 7 [(1::Word8),1..]) = [1,1,1,1,1,1,1]
+    (take 7 [(1::Word8),0..]) = [1,0]
+    (take 7 [(5::Word8),2..]) = [5,2]
+    (take 7 [x, x-1 ..]) = [1,0]
+    (take 7 [x, x-1 ..]) = [5,4,3,2,1,0]
+    (take 7 [x, (x+1) ..]) = [250,251,252,253,254,255]
+    (take 7 ([(1::Word8) .. 5])) = [1,2,3,4,5]
+    (take 4 ([(1::Word8) .. 1])) = [1]
+    (take 7 ([(1::Word8) .. 0])) = [1,0]
+    (take 7 ([(5::Word8) .. 0])) = [5,4,3,2,1,0]
+    (take 7 ([(maxBound-(5::Word8)) .. maxBound])) = [250,251,252,253,254,255]
+    (take 7 ([(minBound+(5::Word8)) .. minBound])) = [5,4,3,2,1,0]
+    (take 7 [(5::Word8),4..1]) = [5,4,3,2,1]
+    (take 7 [(5::Word8),3..1]) = [5,3,1]
+    (take 7 [(5::Word8),3..2]) = [5,3]
+    (take 7 [(1::Word8),2..1]) = [1]
+    (take 7 [(2::Word8),1..2]) = [2]
+    (take 7 [(2::Word8),1..1]) = [2,1]
+    (take 7 [(2::Word8),3..1]) = []
+    (take 7 [x,(x+1)..maxBound]) = [251,252,253,254,255]
+    (take 7 [x,(x-1)..minBound]) = [5,4,3,2,1,0]
+Testing Enum Word16:
+    (succ (0::Word16)) = 1
+    (succ (minBound::Word16)) = 1
+    (succ (maxBound::Word16)) = error "Enum.succ{Word16}: tried to take `succ' of maxBound"
+    pred (1::Word16) = 0
+    pred (maxBound::Word16) = 65534
+    pred (minBound::Word16) = error "Enum.pred{Word16}: tried to take `pred' of minBound"
+    (map (toEnum::Int->Word16) [1, toInt (minBound::Word16), toInt (maxBound::Word16)]) = [1,0,65535]
+    (toEnum (maxBound::Int))::Word16 = error "Enum.toEnum{Word16}: tag (2147483647) is outside of bounds (0,65535)"
+    (map fromEnum [(1::Word16),minBound,maxBound]) = [1,0,65535]
+    (take 7 [(1::Word16)..]) = [1,2,3,4,5,6,7]
+    (take 7 [((maxBound::Word16)-5)..]) = [65530,65531,65532,65533,65534,65535]
+    (take 7 [(1::Word16),2..]) = [1,2,3,4,5,6,7]
+    (take 7 [(1::Word16),7..]) = [1,7,13,19,25,31,37]
+    (take 7 [(1::Word16),1..]) = [1,1,1,1,1,1,1]
+    (take 7 [(1::Word16),0..]) = [1,0]
+    (take 7 [(5::Word16),2..]) = [5,2]
+    (take 7 [x, x-1 ..]) = [1,0]
+    (take 7 [x, x-1 ..]) = [5,4,3,2,1,0]
+    (take 7 [x, (x+1) ..]) = [65530,65531,65532,65533,65534,65535]
+    (take 7 ([(1::Word16) .. 5])) = [1,2,3,4,5]
+    (take 4 ([(1::Word16) .. 1])) = [1]
+    (take 7 ([(1::Word16) .. 0])) = [1,0]
+    (take 7 ([(5::Word16) .. 0])) = [5,4,3,2,1,0]
+    (take 7 ([(maxBound-(5::Word16)) .. maxBound])) = [65530,65531,65532,65533,65534,65535]
+    (take 7 ([(minBound+(5::Word16)) .. minBound])) = [5,4,3,2,1,0]
+    (take 7 [(5::Word16),4..1]) = [5,4,3,2,1]
+    (take 7 [(5::Word16),3..1]) = [5,3,1]
+    (take 7 [(5::Word16),3..2]) = [5,3]
+    (take 7 [(1::Word16),2..1]) = [1]
+    (take 7 [(2::Word16),1..2]) = [2]
+    (take 7 [(2::Word16),1..1]) = [2,1]
+    (take 7 [(2::Word16),3..1]) = []
+    (take 7 [x,(x+1)..maxBound]) = [65531,65532,65533,65534,65535]
+    (take 7 [x,(x-1)..minBound]) = [5,4,3,2,1,0]
+Testing Enum Word32:
+    (succ (0::Word32)) = 1
+    (succ (minBound::Word32)) = 1
+    (succ (maxBound::Word32)) = error "Enum.succ{Word32}: tried to take `succ' of maxBound"
+    pred (1::Word32) = 0
+    pred (maxBound::Word32) = 4294967294
+    pred (minBound::Word32) = error "Enum.pred{Word32}: tried to take `pred' of minBound"
+    (map (toEnum::Int->Word32) [1, toInt (minBound::Word32), maxBound::Int]) = [1,0,2147483647]
+    (toEnum (maxBound::Int))::Word32 = 2147483647
+    (map fromEnum [(1::Word32),minBound,fromInt (maxBound::Int)]) = [1,0,2147483647]
+    fromEnum (maxBound::Word32) = error "Enum.fromEnum{Word32}: value (4294967295) is outside of Int's bounds (-2147483648,2147483647)"
+    (take 7 [(1::Word32)..]) = [1,2,3,4,5,6,7]
+    (take 7 [((maxBound::Word32)-5)..]) = [4294967290,4294967291,4294967292,4294967293,4294967294,4294967295]
+    (take 7 [(1::Word32),2..]) = [1,2,3,4,5,6,7]
+    (take 7 [(1::Word32),7..]) = [1,7,13,19,25,31,37]
+    (take 7 [(1::Word32),1..]) = [1,1,1,1,1,1,1]
+    (take 7 [(1::Word32),0..]) = [1,0]
+    (take 7 [(5::Word32),2..]) = [5,2]
+    (take 7 [x, x-1 ..]) = [1,0]
+    (take 7 [x, x-1 ..]) = [5,4,3,2,1,0]
+    (take 7 [x, (x+1) ..]) = [4294967290,4294967291,4294967292,4294967293,4294967294,4294967295]
+    (take 7 ([(1::Word32) .. 5])) = [1,2,3,4,5]
+    (take 4 ([(1::Word32) .. 1])) = [1]
+    (take 7 ([(1::Word32) .. 0])) = [1,0]
+    (take 7 ([(5::Word32) .. 0])) = [5,4,3,2,1,0]
+    (take 7 ([(maxBound-(5::Word32)) .. maxBound])) = [4294967290,4294967291,4294967292,4294967293,4294967294,4294967295]
+    (take 7 ([(minBound+(5::Word32)) .. minBound])) = [5,4,3,2,1,0]
+    (take 7 [(5::Word32),4..1]) = [5,4,3,2,1]
+    (take 7 [(5::Word32),3..1]) = [5,3,1]
+    (take 7 [(5::Word32),3..2]) = [5,3]
+    (take 7 [(1::Word32),2..1]) = [1]
+    (take 7 [(2::Word32),1..2]) = [2]
+    (take 7 [(2::Word32),1..1]) = [2,1]
+    (take 7 [(2::Word32),3..1]) = []
+    (take 7 [x,(x+1)..maxBound]) = [4294967291,4294967292,4294967293,4294967294,4294967295]
+    (take 7 [x,(x-1)..minBound]) = [5,4,3,2,1,0]
+Testing Enum Word64:
+    (succ (0::Word64)) = 1
+    (succ (minBound::Word64)) = 1
+    (succ (maxBound::Word64)) = error "Enum.succ{Word64}: tried to take `succ' of maxBound"
+    pred (1::Word64) = 0
+    pred (maxBound::Word64) = 18446744073709551614
+    pred (minBound::Word64) = error "Enum.pred{Word64}: tried to take `pred' of minBound"
+    (map (toEnum::Int->Word64) [1, toInt (minBound::Word64), maxBound::Int]) = [1,0,2147483647]
+    (toEnum (maxBound::Int))::Word64 = 2147483647
+    (map fromEnum [(1::Word64),minBound,fromInt (maxBound::Int)]) = [1,0,2147483647]
+    fromEnum (maxBound::Word64) = error "Enum.fromEnum{Word64}: value (18446744073709551615) is outside of Int's bounds (-2147483648,2147483647)"
+    (take 7 [(1::Word64)..]) = [1,2,3,4,5,6,7]
+    (take 7 [((maxBound::Word64)-5)..]) = [18446744073709551610,18446744073709551611,18446744073709551612,18446744073709551613,18446744073709551614,18446744073709551615]
+    (take 7 [(1::Word64),2..]) = [1,2,3,4,5,6,7]
+    (take 7 [(1::Word64),7..]) = [1,7,13,19,25,31,37]
+    (take 7 [(1::Word64),1..]) = [1,1,1,1,1,1,1]
+    (take 7 [(1::Word64),0..]) = [1,0]
+    (take 7 [(5::Word64),2..]) = [5,2]
+    (take 7 [x, x-1 ..]) = [1,0]
+    (take 7 [x, x-1 ..]) = [5,4,3,2,1,0]
+    (take 7 [x, (x+1) ..]) = [18446744073709551610,18446744073709551611,18446744073709551612,18446744073709551613,18446744073709551614,18446744073709551615]
+    (take 7 ([(1::Word64) .. 5])) = [1,2,3,4,5]
+    (take 4 ([(1::Word64) .. 1])) = [1]
+    (take 7 ([(1::Word64) .. 0])) = [1,0]
+    (take 7 ([(5::Word64) .. 0])) = [5,4,3,2,1,0]
+    (take 7 ([(maxBound-(5::Word64)) .. maxBound])) = [18446744073709551610,18446744073709551611,18446744073709551612,18446744073709551613,18446744073709551614,18446744073709551615]
+    (take 7 ([(minBound+(5::Word64)) .. minBound])) = [5,4,3,2,1,0]
+    (take 7 [(5::Word64),4..1]) = [5,4,3,2,1]
+    (take 7 [(5::Word64),3..1]) = [5,3,1]
+    (take 7 [(5::Word64),3..2]) = [5,3]
+    (take 7 [(1::Word64),2..1]) = [1]
+    (take 7 [(2::Word64),1..2]) = [2]
+    (take 7 [(2::Word64),1..1]) = [2,1]
+    (take 7 [(2::Word64),3..1]) = []
+    (take 7 [x,(x+1)..maxBound]) = [18446744073709551611,18446744073709551612,18446744073709551613,18446744073709551614,18446744073709551615]
+    (take 7 [x,(x-1)..minBound]) = [5,4,3,2,1,0]