summaryrefslogtreecommitdiffstats
path: root/tests/Catch.hs
blob: ce0521250296982cfdb04fc5655b0966df5d0ea2 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

-- This is a test set for running with Catch
-- http://www-users.cs.york.ac.uk/~ndm/catch/

module Catch where

import StackSet

---------------------------------------------------------------------
-- TESTING PROPERTIES

main = 
        new
    ||| view
    ||| lookupWorkspace
    ||| modify
    ||| peek
    ||| index
    ||| focusLeft
    ||| focusRight
    ||| focusWindow
    ||| member
    ||| findIndex
    ||| insertLeft
    ||| delete
    ||| swap
    ||| shift


---------------------------------------------------------------------
-- CATCH FIRST-ORDER LIBRARY

-- this should be included with Catch by default
-- and will be (one day!)

foreign import primitive any0 :: a
foreign import primitive anyEval1 :: a -> b
foreign import primitive anyEval2 :: a -> b -> c
foreign import primitive anyEval3 :: a -> b -> c -> d


class Test a where
    test :: a -> Bool


instance Test b => Test (a -> b) where
    test f = test (f any0)

instance Test (Maybe a) where
    test f = anyEval1 f

instance Test [a] where
    test f = anyEval1 f

instance Test (StackSet a b c) where
    test f = anyEval1 f

instance Test (a,b) where
    test f = anyEval1 f

instance Test Bool where
    test f = anyEval1 f

instance Test Char where
    test f = anyEval1 f

instance Test (IO a) where
    test f = anyEval1 (f >> return ())
    

(|||) :: (Test a, Test b) => a -> b -> IO c
(|||) l r = anyEval2 (test l) (test r)