Commit 5246de0c authored by mikhail.vorozhtsov's avatar mikhail.vorozhtsov Committed by Simon Marlow

Added MultiWayIf tests.

parent b72aa2c9
{-# LANGUAGE MultiWayIf #-}
module Main where
import Data.List (isSuffixOf)
import Control.Exception
errMsg = "Non-exhaustive guards in multi-way if\n"
table = [(1, "one"), (100, "hundred")]
f t x = if | l <- length t, l > 2, l < 5 -> "length is 3 or 4"
| Just y <- lookup x t -> y
| False -> "impossible"
| null t -> "empty"
main = do
print $ [ f table 1 == "one"
, f table 100 == "hundred"
, f [] 1 == "empty"
, f [undefined, undefined, undefined] (undefined :: Bool) ==
"length is 3 or 4"
, f ((0, "zero") : table) 100 == "length is 3 or 4"
]
r <- try $ evaluate $ f table 99
print $ case r of
Left (PatternMatchFail s) | errMsg `isSuffixOf` s -> True
_ -> False
......@@ -39,3 +39,4 @@ test('mc07', normal, compile_and_run, [''])
test('mc08', normal, compile_and_run, [''])
test('T5742', normal, compile_and_run, [''])
test('DsLambdaCase', if_compiler_lt('ghc', '7.5', skip), compile_and_run, [''])
test('DsMultiWayIf', if_compiler_lt('ghc', '7.5', skip), compile_and_run, [''])
module ParserNoMultiWayIf where
x = 123
y = if | x < 0 -> -1
| x == 0 -> 0
| otherwise -> 1
ParserNoMultiWayIf.hs:4:5:
Multi-way if-expressions need -XMultiWayIf turned on
......@@ -73,5 +73,6 @@ test('readFailTraditionalRecords1', normal, compile_fail, [''])
test('readFailTraditionalRecords2', normal, compile_fail, [''])
test('readFailTraditionalRecords3', normal, compile_fail, [''])
test('ParserNoLambdaCase', if_compiler_lt('ghc', '7.5', skip), compile_fail, [''])
test('ParserNoMultiWayIf', if_compiler_lt('ghc', '7.5', skip), compile_fail, [''])
test('T5425', normal, compile_fail, [''])
{-# LANGUAGE MultiWayIf #-}
module Main where
x = 10
x1 = if | x < 10 -> "< 10" | otherwise -> ""
x2 = if | x < 10 -> "< 10"
| otherwise -> ""
x3 = if | x < 10 -> "< 10"
| otherwise -> ""
x4 = if | True -> "yes"
x5 = if | True -> if | False -> 1 | True -> 2
main = print $ x5 == 2
......@@ -5,3 +5,4 @@ test('readRun004', normal, compile_and_run, ['-fobject-code'])
test('T1344', normal, compile_and_run, [''])
test('operator', normal, compile_and_run, [''])
test('operator2', normal, compile_and_run, [''])
test('ParserMultiWayIf', if_compiler_lt('ghc', '7.5', skip), compile_and_run, [''])
{-# LANGUAGE MultiWayIf #-}
module TcMultiWayIfFail where
x1 = if | True -> 1 :: Int
| False -> "2"
| otherwise -> [3 :: Int]
TcMultiWayIfFail.hs:6:24:
Couldn't match expected type `Int' with actual type `[Char]'
In the expression: "2"
In the expression:
if | True -> 1 :: Int | False -> "2" | otherwise -> [3 :: Int]
In an equation for `x1':
x1 = if | True -> 1 :: Int | False -> "2" | otherwise -> [3 :: Int]
TcMultiWayIfFail.hs:7:24:
Couldn't match expected type `Int' with actual type `[Int]'
In the expression: [3 :: Int]
In the expression:
if | True -> 1 :: Int | False -> "2" | otherwise -> [3 :: Int]
In an equation for `x1':
x1 = if | True -> 1 :: Int | False -> "2" | otherwise -> [3 :: Int]
......@@ -277,3 +277,4 @@ test('T6078', normal, compile_fail, [''])
test('FDsFromGivens', normal, compile_fail, [''])
test('T5978', normal, compile_fail, [''])
test('TcMultiWayIfFail', if_compiler_lt('ghc', '7.5', skip), compile_fail, [''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment