[project @ 1999-02-06 16:00:43 by sof]
authorsof <unknown>
Sat, 6 Feb 1999 16:00:47 +0000 (16:00 +0000)
committersof <unknown>
Sat, 6 Feb 1999 16:00:47 +0000 (16:00 +0000)
Added two new (read.show) regression tests for derived Read&Show instances.

ghc/tests/deriving/should_run/drvrun002.hs [new file with mode: 0644]
ghc/tests/deriving/should_run/drvrun002.stdout [new file with mode: 0644]
ghc/tests/deriving/should_run/drvrun003.hs [new file with mode: 0644]
ghc/tests/deriving/should_run/drvrun003.stdout [new file with mode: 0644]

diff --git a/ghc/tests/deriving/should_run/drvrun002.hs b/ghc/tests/deriving/should_run/drvrun002.hs
new file mode 100644 (file)
index 0000000..26497bd
--- /dev/null
@@ -0,0 +1,17 @@
+-- !!! Deriving Show/Read for type with labelled fields.
+--     (based on a Hugs bug report.)
+module Main(main) where
+
+data Options = 
+   Options { s :: OptionKind } 
+   deriving (Show, Read)
+
+data OptionKind = 
+   SpecialOptions { test :: Int }
+   deriving (Show, Read)
+
+x = Options{s=SpecialOptions{test=42}}
+
+main = do
+  print x
+  print ((read (show x))::Options)
diff --git a/ghc/tests/deriving/should_run/drvrun002.stdout b/ghc/tests/deriving/should_run/drvrun002.stdout
new file mode 100644 (file)
index 0000000..183c213
--- /dev/null
@@ -0,0 +1,2 @@
+Options{s=(SpecialOptions{test=42})}
+Options{s=(SpecialOptions{test=42})}
diff --git a/ghc/tests/deriving/should_run/drvrun003.hs b/ghc/tests/deriving/should_run/drvrun003.hs
new file mode 100644 (file)
index 0000000..bb74861
--- /dev/null
@@ -0,0 +1,30 @@
+-- !!! Deriving Show/Read for nullary constructors.
+module Main(main) where
+
+data A = B | C deriving ( Show, Read )
+
+data Opt = N | Y A deriving (Show, Read)
+
+x = Y B
+
+{-
+ If the Haskell report's specification of how Show instances
+ are to be derived is followed to the letter, the code for
+ a nullary constructor would put parens around the constructor
+ when (showsPrec 10) is used. This would cause
+
+      Y A
+
+ to be showed as
+      Y (A)
+
+ Overkill, so ghc's derived Show code treats nullary
+ constructors specially.
+-}
+
+main = do
+  print x
+  print ((read (show x))::Opt)
+  print ((read "Y (B)")::Opt)
+
diff --git a/ghc/tests/deriving/should_run/drvrun003.stdout b/ghc/tests/deriving/should_run/drvrun003.stdout
new file mode 100644 (file)
index 0000000..584cfcd
--- /dev/null
@@ -0,0 +1,3 @@
+Y B
+Y B
+Y B