From 43f20ce4e8a773ff57d2badf575ac86e8e7549d3 Mon Sep 17 00:00:00 2001 From: sof <unknown> Date: Sat, 6 Feb 1999 16:00:47 +0000 Subject: [PATCH] [project @ 1999-02-06 16:00:43 by sof] Added two new (read.show) regression tests for derived Read&Show instances. --- ghc/tests/deriving/should_run/drvrun002.hs | 17 +++++++++++ .../deriving/should_run/drvrun002.stdout | 2 ++ ghc/tests/deriving/should_run/drvrun003.hs | 30 +++++++++++++++++++ .../deriving/should_run/drvrun003.stdout | 3 ++ 4 files changed, 52 insertions(+) create mode 100644 ghc/tests/deriving/should_run/drvrun002.hs create mode 100644 ghc/tests/deriving/should_run/drvrun002.stdout create mode 100644 ghc/tests/deriving/should_run/drvrun003.hs create mode 100644 ghc/tests/deriving/should_run/drvrun003.stdout diff --git a/ghc/tests/deriving/should_run/drvrun002.hs b/ghc/tests/deriving/should_run/drvrun002.hs new file mode 100644 index 000000000000..26497bd32c9f --- /dev/null +++ b/ghc/tests/deriving/should_run/drvrun002.hs @@ -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 index 000000000000..183c2135b674 --- /dev/null +++ b/ghc/tests/deriving/should_run/drvrun002.stdout @@ -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 index 000000000000..bb7486159e45 --- /dev/null +++ b/ghc/tests/deriving/should_run/drvrun003.hs @@ -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 index 000000000000..584cfcd5cede --- /dev/null +++ b/ghc/tests/deriving/should_run/drvrun003.stdout @@ -0,0 +1,3 @@ +Y B +Y B +Y B -- GitLab