diff options
Diffstat (limited to 'libraries/base/tests')
-rw-r--r-- | libraries/base/tests/T22816.hs | 31 | ||||
-rw-r--r-- | libraries/base/tests/T22816.stdout | 2 | ||||
-rw-r--r-- | libraries/base/tests/all.T | 1 |
3 files changed, 34 insertions, 0 deletions
diff --git a/libraries/base/tests/T22816.hs b/libraries/base/tests/T22816.hs new file mode 100644 index 0000000000..0105a18c9d --- /dev/null +++ b/libraries/base/tests/T22816.hs @@ -0,0 +1,31 @@ +module Main (main) where + +import Data.Functor.Classes +import Data.Functor.Compose +import Text.ParserCombinators.ReadP as P +import Text.ParserCombinators.ReadPrec (ReadPrec, lift, minPrec, readPrec_to_S) + +readEither' :: ReadPrec a -> String -> Either String a +readEither' rp s = + case [ x | (x,"") <- readPrec_to_S read' minPrec s ] of + [x] -> Right x + [] -> Left "read1: no parse" + _ -> Left "read1: ambiguous parse" + where + read' = + do x <- rp + lift P.skipSpaces + return x + +-- | Like 'read', but tailored to 'Read1'. +read1 :: (Read1 f, Read a) => String -> f a +read1 s = either errorWithoutStackTrace id (readEither' readPrec1 s) + +exRead, exRead1 :: Compose Maybe Maybe Int +exRead = read "Compose Nothing" +exRead1 = read1 "Compose Nothing" + +main :: IO () +main = do + putStrLn $ showsPrec 0 exRead "" + putStrLn $ showsPrec1 0 exRead1 "" diff --git a/libraries/base/tests/T22816.stdout b/libraries/base/tests/T22816.stdout new file mode 100644 index 0000000000..1957c7edf8 --- /dev/null +++ b/libraries/base/tests/T22816.stdout @@ -0,0 +1,2 @@ +Compose Nothing +Compose Nothing diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T index 2b253ceca8..73e6059d7c 100644 --- a/libraries/base/tests/all.T +++ b/libraries/base/tests/all.T @@ -286,6 +286,7 @@ test('T18642', test('T19288', exit_code(1), compile_and_run, ['']) test('T19719', normal, compile_and_run, ['']) test('T20107', extra_run_opts('+RTS -M50M'), compile_and_run, ['-package bytestring']) +test('T22816', normal, compile_and_run, ['']) test('trace', normal, compile_and_run, ['']) test('listThreads', js_broken(22261), compile_and_run, ['']) test('inits1tails1', normal, compile_and_run, ['']) |