Files
  • main.hs
main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
type TestResult = (String, Bool)

should :: String -> Bool -> TestResult
should label result = (label, result)

formatOne :: TestResult -> String
formatOne (label, result) = "  " ++ label ++ " " ++ show result

format :: [TestResult] -> [String]
format = map formatOne 

addLabel :: String -> [String] -> [String]
addLabel label reports = label : reports

(|>) :: a -> (a -> b) -> b
x |> f = f x

describe :: String -> [TestResult] -> String
describe label results = 
    results |> format |> addLabel label |> unlines

main :: IO ()
main = putStrLn $ describe "Addition" [
        should "1 + 1 == 2" $ 1 + 1 == 2,
        should "2 + 2 == 3" $ 2 + 2 == 3
    ]
GHCi, version 8.6.3