-
Notifications
You must be signed in to change notification settings - Fork 217
/
release.nix
192 lines (189 loc) · 7.68 KB
/
release.nix
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
let
shared = import ../nix/shared.nix { };
inherit (shared.pkgs) dhallToNix stdenv;
in
{ tests =
let
testConst = dhallToNix "Type";
testLam = dhallToNix "λ(x : Bool) → x";
testPi = dhallToNix "Bool → Bool";
testApp = dhallToNix "λ(f : Bool → Bool) → λ(x : Bool) → f x";
testLet = dhallToNix "λ(b : Bool) → let x = b in x";
testAnnot = dhallToNix "True : Bool";
testBool = dhallToNix "Bool";
testBoolLit = dhallToNix "True";
testBoolAnd = dhallToNix "λ(l : Bool) → λ(r : Bool) → l && r";
testBoolOr = dhallToNix "λ(l : Bool) → λ(r : Bool) → l || r";
testBoolEQ = dhallToNix "λ(l : Bool) → λ(r : Bool) → l == r";
testBoolNE = dhallToNix "λ(l : Bool) → λ(r : Bool) → l != r";
testBoolIf = dhallToNix "λ(x : Bool) → if x then True else False";
testNatural = dhallToNix "Natural";
testNaturalLit = dhallToNix "123";
testNaturalFold = dhallToNix ''
λ(x : Natural)
→ Natural/fold x Natural (λ(n : Natural) → 2 + n) 0
'';
testNaturalBuild = dhallToNix ''
λ(b : Bool)
→ Natural/build
( λ(natural : Type)
→ λ(succ : natural → natural)
→ λ(zero : natural)
→ if b then succ zero else zero
)
'';
testNaturalIsZero = dhallToNix "Natural/isZero";
testNaturalEven = dhallToNix "Natural/even";
testNaturalOdd = dhallToNix "Natural/odd";
testNaturalToInteger = dhallToNix "Natural/toInteger";
testNaturalShow = dhallToNix "Natural/show";
testNaturalPlus = dhallToNix "λ(x : Natural) → λ(y : Natural) → x + y";
testNaturalTimes = dhallToNix "λ(x : Natural) → λ(y : Natural) → x * y";
testInteger = dhallToNix "Integer";
testIntegerLit = dhallToNix "+123";
testIntegerShow = dhallToNix "Integer/show";
testDouble = dhallToNix "Double";
testTextLit = dhallToNix ''"ABC"'';
testInterpolation = dhallToNix ''λ(x : Text) → "ABC''${x}GHI"'' "DEF";
testTextAppend = dhallToNix "λ(x : Text) → λ(y : Text) → x ++ y";
testList = dhallToNix "List Natural";
testListLit = dhallToNix "[1, 2, 3] : List Natural";
testListAppend = dhallToNix ''
λ(xs : List Natural) → λ(ys : List Natural) → xs # ys
'';
testListBuild = dhallToNix ''
λ(b : Bool)
→ List/build
Natural
( λ(list : Type)
→ λ(cons : Natural → list → list)
→ λ(nil : list)
→ if b then cons 1 (cons 2 (cons 3 nil)) else nil
)
'';
testListFold = dhallToNix ''
List/fold
Natural
([1, 2, 3] : List Natural)
Natural
'';
testListLength = dhallToNix "List/length Natural";
testListHead = dhallToNix "List/head Natural";
testListLast = dhallToNix "List/last Natural";
testListIndexed = dhallToNix "List/indexed Natural";
testListReverse = dhallToNix "List/reverse Natural";
testOptional = dhallToNix "Optional";
testOptionalLit = dhallToNix ''
λ(b : Bool)
→ if b
then (Some 0)
else (None Natural)
'';
testNone = dhallToNix "None Natural";
testSome = dhallToNix "Some 4";
testRecord = dhallToNix "{}";
testRecordLit = dhallToNix "{ foo = 1, bar = True}";
testUnion = dhallToNix "< Left : Natural | Right : Bool >";
testUnionLit = dhallToNix "< Left : Natural | Right : Bool >.Left 2";
testCombine = dhallToNix ''
λ(x : { foo : { bar : Text } })
→ λ(y : { foo : { baz : Bool } })
→ x ∧ y
'';
testCombineTypes = dhallToNix ''
{ foo : Text } ⩓ { bar : Bool, baz : Natural }
'';
testMerge = dhallToNix ''
λ(r : < Left : Natural | Right : Bool >)
→ merge
{ Left = Natural/isZero, Right = λ(b : Bool) → b }
r : Bool
'';
testField = dhallToNix "λ(r : { foo : Bool, bar : Text }) → r.foo";
testProject = dhallToNix ''
λ(r : { foo : Bool, bar : Text, baz : Natural }) → r.{ foo, bar }
'';
testShadow = dhallToNix ''
λ(x : Natural) → λ(x1 : Natural) → λ(x : Natural) → [ x, x1, x@1 ]
'';
in
assert (testConst == {});
assert (testLam true == true);
assert (testPi == {});
assert (testApp (b : b) true == true);
assert (testLet true == true);
assert (testAnnot == true);
assert (testBool == {});
assert (testBoolLit == true);
assert (testBoolAnd true false == false);
assert (testBoolOr true false == true);
assert (testBoolEQ true false == false);
assert (testBoolNE true false == true);
assert (testBoolIf true == true);
assert (testNatural == {});
assert (testNaturalLit == 123);
assert (testNaturalFold 123 == 246);
assert (testNaturalBuild true == 1);
assert (testNaturalBuild false == 0);
assert (testNaturalIsZero 0 == true);
assert (testNaturalIsZero 3 == false);
assert (testNaturalEven 2 == true);
assert (testNaturalEven 3 == false);
assert (testNaturalOdd 2 == false);
assert (testNaturalToInteger 2 == 2);
assert (testNaturalShow 2 == "2");
assert (testNaturalOdd 3 == true);
assert (testNaturalPlus 2 3 == 5);
assert (testNaturalTimes 2 3 == 6);
assert (testInteger == {});
assert (testIntegerLit == 123);
assert (testIntegerShow 2 == "+2");
assert (testIntegerShow (-3) == "-3");
assert (testDouble == {});
assert (testTextLit == "ABC");
assert (testInterpolation == "ABCDEFGHI");
assert (testTextAppend "ABC" "DEF" == "ABCDEF");
assert (testList == {});
assert (testListLit == [1 2 3]);
assert (testListAppend [1 2 3] [4 5 6] == [1 2 3 4 5 6]);
assert (testListBuild false == []);
assert (testListBuild true == [1 2 3]);
assert (testListFold (x : y: x + y) 0 == 6);
assert (testListLength [1 2 3] == 3);
assert (testListLength [] == 0);
assert (testListHead [1 2 3] == 1);
assert (testListHead [] == null);
assert (testListLast [1 2 3] == 3);
assert (testListLast [] == null);
assert (testListIndexed [2 3 5] == [
{ index = 0; value = 2; }
{ index = 1; value = 3; }
{ index = 2; value = 5; }
]);
assert (testListReverse [1 2 3] == [3 2 1]);
assert (testOptional {} == {});
assert (testOptionalLit true == 0);
assert (testOptionalLit false == null);
assert (testRecord == {});
assert (testRecordLit == { foo = 1; bar = true; });
assert (testUnion == {});
assert (testUnionLit { Left = n : n == 0; Right = b : b; } == false);
assert ((testCombine { foo.baz = true; } { foo.bar = "ABC"; }) == {
foo = {
baz = true;
bar = "ABC";
};
});
assert (testCombineTypes == {});
assert (testMerge ({ Left, Right }: Left 2) == false);
assert (testField { foo = true; bar = "ABC"; } == true);
assert (testProject { foo = true; bar = "ABC"; baz = 1; } == {
foo = true;
bar = "ABC";
});
assert (testShadow 0 1 2 == [ 2 1 0 ]);
stdenv.mkDerivation {
name = "tests-pass";
buildCommand = "touch $out";
};
}