diff options
Diffstat (limited to 'libraries/base/tests')
-rw-r--r-- | libraries/base/tests/all.T | 1 | ||||
-rw-r--r-- | libraries/base/tests/functorOperators.hs | 38 | ||||
-rw-r--r-- | libraries/base/tests/functorOperators.stdout | 16 |
3 files changed, 55 insertions, 0 deletions
diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T index 4bd8084220..b52a5d922b 100644 --- a/libraries/base/tests/all.T +++ b/libraries/base/tests/all.T @@ -214,3 +214,4 @@ test('T13191', ['-O']) test('T13525', when(opsys('mingw32'), skip), compile_and_run, ['']) test('T13097', normal, compile_and_run, ['']) +test('functorOperators', normal, compile_and_run, ['']) diff --git a/libraries/base/tests/functorOperators.hs b/libraries/base/tests/functorOperators.hs new file mode 100644 index 0000000000..aea5dfda80 --- /dev/null +++ b/libraries/base/tests/functorOperators.hs @@ -0,0 +1,38 @@ +-- Test infix operators of 'Functor' + +import Data.Functor + +main :: IO () +main = do + testInfixFmap + testFlippedInfixFmap + testInfixReplace + testFlippedInfixReplace + +testInfixFmap :: IO () +testInfixFmap = do + print "<$> tests:" + print $ (+ 1) <$> Just 2 -- => Just 3 + print (((+ 1) <$> Right 3) :: Either Int Int) -- => Right 4 + print $ (+ 1) <$> [1, 2, 3] -- => [2,3,4] + +testFlippedInfixFmap :: IO () +testFlippedInfixFmap = do + print "<&> tests:" + print $ Just 2 <&> (+ 1) -- => Just 3 + print ((Right 3 <&> (+ 1)) :: Either Int Int) -- => Right 4 + print $ [1, 2, 3] <&> (+ 1) -- => [2,3,4] + +testInfixReplace :: IO () +testInfixReplace = do + print "<$ tests:" + print $ 42 <$ Just 1 -- => Just 42 + print ((42 <$ Right 1) :: Either Int Int) -- => Right 42 + print $ 42 <$ [1, 2, 3] -- => [42,42,42] + +testFlippedInfixReplace :: IO () +testFlippedInfixReplace = do + print "$> tests:" + print $ Just 1 $> 42 -- => Just 42 + print ((Right 1 $> 42) :: Either Int Int) -- => Right 42 + print $ [1, 2, 3] $> 42 -- => [42,42,42] diff --git a/libraries/base/tests/functorOperators.stdout b/libraries/base/tests/functorOperators.stdout new file mode 100644 index 0000000000..00a17ed3b8 --- /dev/null +++ b/libraries/base/tests/functorOperators.stdout @@ -0,0 +1,16 @@ +"<$> tests:" +Just 3 +Right 4 +[2,3,4] +"<&> tests:" +Just 3 +Right 4 +[2,3,4] +"<$ tests:" +Just 42 +Right 42 +[42,42,42] +"$> tests:" +Just 42 +Right 42 +[42,42,42] |