-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleTypingSpec.hs
94 lines (78 loc) · 2.67 KB
/
SimpleTypingSpec.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
module SimpleTypingSpec (spec) where
import Test.Hspec
import SimpleType
import SimpleTyping
import Expr
spec :: Spec
spec = do
-- inferSpec
extractSpec
unifySpec
ftvSpec
substituteOneSpec
substituteSpec
substituteEqsSpec
{-
inferSpec :: Spec -- 散発的なテストにとどめて、全体の仕組みが動いているかどうかのチェックだけをする。
inferSpec =
describe "infer" $ do
context "given typable expressions" $ do
it "types 1" $
EInt 1 `hasType` TInt
it "types 1 + 2" $
EAdd (EInt 1) (EInt 2) `hasType` TInt
it "types (fun x -> x + 1)" $
EAbs "x" (EAdd (EVar "x") (EInt 1)) `hasType` TFun TInt TInt
it "types (fun x -> x + 1) 1" $
EApp (EAbs "x" (EAdd (EVar "x") (EInt 1))) (EInt 1) `hasType` TInt
context "given untypable expressions" $ do
it "rejects x" $
hasNoType $ EVar "x"
it "rejects 1 + true" $
hasNoType $ EAdd (EInt 1) (EBool True)
it "rejects (fun x -> x + 1) true" $
hasNoType $ EApp (EAbs "x" (EAdd (EVar "x") (EInt 1))) (EBool True)
context "given multi-typed expressions" $
it "gives a type with not reified type variables" $
hasMultipleTypes $ EAbs "x" (EVar "x")
hasType :: Expr -> SimpleType -> Expectation
e `hasType` t = infer e `shouldBe` SuccessfullyTyped t
hasNoType :: Expr -> Expectation
hasNoType e = infer e `shouldBe` Untypable
hasMultipleTypes :: Expr -> Expectation
hasMultipleTypes e =
case infer e of
ConstraintInsufficient _ -> return ()
_ -> 1 `shouldBe` 0 -- まともな書き方に書き直したい、、、
-}
extractSpec :: Spec
extractSpec =
describe "extract" $ do
context "given EVar" notYet
context "given EBool" notYet
context "given EInt" notYet
context "given EAdd" notYet
context "given ESub" notYet
context "given EMul" notYet
context "given EDiv" notYet
context "given EAnd" notYet
context "given EOr" notYet
context "given ELT" notYet
context "given EEqInt" notYet
context "given ELet" notYet
context "given EAbs" notYet
context "given EApp" notYet
context "given ENil" notYet
context "given ECons" notYet
context "given EMatch" notYet
unifySpec :: Spec
unifySpec = notYet
ftvSpec :: Spec
ftvSpec = notYet
substituteOneSpec :: Spec
substituteOneSpec = notYet
substituteSpec :: Spec
substituteSpec = notYet
substituteEqsSpec :: Spec
substituteEqsSpec = notYet
notYet = it "has not yet tested" pending