-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
includes.re
210 lines (207 loc) 路 7.26 KB
/
includes.re
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
open Grain_tests.TestFramework;
open Grain_tests.Runner;
describe("includes", ({test, testSkip}) => {
let test_or_skip =
Sys.backend_type == Other("js_of_ocaml") ? testSkip : test;
let assertSnapshot = makeSnapshotRunner(test);
let assertCompileError = makeCompileErrorRunner(test);
let assertRun = makeRunner(test_or_skip);
let assertFileRun = makeFileRunner(test_or_skip);
let assertFileCompileError = makeFileCompileErrorRunner(test_or_skip);
let assertFileSnapshot = makeSnapshotFileRunner(test);
/* use * tests */
assertRun(
"include_all",
"from \"provideAll\" include ProvideAll; use ProvideAll.*; {print(x); print(y(4)); print(z)}",
"5\n4\nfoo\n",
);
assertSnapshot(
"include_all_constructor",
"from \"tlists\" include TLists; use TLists.*; Cons(2, Empty)",
);
/* use {} tests */
assertSnapshot(
"include_some",
"from \"provideAll\" include ProvideAll; use ProvideAll.{x}; x",
);
assertSnapshot(
"include_some_multiple",
"from \"provideAll\" include ProvideAll; use ProvideAll.{x, y}; y(x)",
);
assertSnapshot(
"include_some_multiple_trailing",
"from \"provideAll\" include ProvideAll; use ProvideAll.{x, y,}; y(x)",
);
assertSnapshot(
"include_some_multiple_trailing2",
"from \"provideAll\" include ProvideAll; use ProvideAll.{
x,
y,
}; y(x)",
);
assertSnapshot(
"include_some_constructor",
"from \"tlists\" include TLists; use TLists.{type TList}; Cons(5, Empty)",
);
assertSnapshot(
"include_some_mixed",
"from \"tlists\" include TLists; use TLists.{type TList, sum}; sum(Cons(5, Empty))",
);
assertSnapshot(
"include_alias",
"from \"provideAll\" include ProvideAll; use ProvideAll.{x as y}; y",
);
assertSnapshot(
"include_alias_multiple",
"from \"provideAll\" include ProvideAll; use ProvideAll.{x as y, y as x}; x(y)",
);
/* use {} errors */
assertCompileError(
"include_some_error",
"from \"provideAll\" include ProvideAll; use ProvideAll.{a}; a",
"Unbound value a in module ProvideAll",
);
assertCompileError(
"include_some_error2",
"from \"provideAll\" include ProvideAll; use ProvideAll.{x, a}; a",
"Unbound value a in module ProvideAll",
);
assertCompileError(
"include_some_error3",
"from \"provideAll\" include ProvideAll; use ProvideAll.{module Foo}",
"Unbound module Foo in module ProvideAll",
);
assertCompileError(
"include_some_error4",
"from \"provideAll\" include ProvideAll; use ProvideAll.{x, module Foo}",
"Unbound module Foo in module ProvideAll",
);
assertCompileError(
"include_some_error5",
"from \"provideAll\" include ProvideAll; use ProvideAll.{Foo}",
"Expected a lowercase identifier to use a value, the keyword `module` followed by an uppercase identifier to use a module, or the keyword `type` followed by an uppercase identifier to use a type.",
);
assertCompileError(
"include_some_error6",
"from \"provideAll\" include ProvideAll; use ProvideAll.{a, Foo}",
"Expected a lowercase identifier to use a value, the keyword `module` followed by an uppercase identifier to use a module, the keyword `type` followed by an uppercase identifier to use a type, or `}` to end the use statement.",
);
/* include module tests */
assertSnapshot(
"include_module",
"from \"provideAll\" include ProvideAll as Foo; Foo.x",
);
assertSnapshot(
"include_module2",
"from \"provideAll\" include ProvideAll as Foo; Foo.y(Foo.x)",
);
/* include module errors */
assertCompileError(
"include_module_error",
"from \"provideAll\" include ProvideAll as Foo; Foo.foo",
"Unbound value foo in module Foo",
);
assertCompileError(
"include_module_error",
"from \"provideAll\" include Foo; Foo.foo",
"This statement includes module Foo, but the file at the path defines module ProvideAll. Did you mean `include ProvideAll as Foo`?",
);
/* use well-formedness errors */
assertCompileError(
"include_alias_illegal_renaming",
"from \"list\" include List; use List.{module Cons as cons, module Empty}; cons(3, Empty)",
"Expected an uppercase module alias",
);
assertCompileError(
"include_alias_illegal_renaming2",
"from \"list\" include List; use List.{sum as Sum, module Empty}; sum(Empty)",
"Expected a lowercase alias",
);
assertCompileError(
"include_module_illegal_name",
"from \"list\" include List as foo;",
"Expected an uppercase module identifier",
);
assertCompileError(
"include_module_not_external",
"from \"list\" include List as Foo.Foo;",
"A module alias cannot contain `.` as that would reference a binding within another module.",
);
assertCompileError(
"include_value_not_external",
"from \"list\" include List; use List.{foo as Foo.foo};",
"Expected a lowercase alias",
);
/* include multiple modules tests */
assertSnapshot(
"include_muliple_modules",
"from \"tlists\" include TLists; use TLists.*; from \"provideAll\" include ProvideAll; use ProvideAll.*; Cons(x, Empty)",
);
/* include same module tests */
assertSnapshot(
"include_same_module_unify",
"from \"tlists\" include TLists; use TLists.*; Cons(5, TLists.Empty)",
);
/* include filepath tests */
assertFileSnapshot("include_relative_path1", "relativeInclude1");
assertFileSnapshot("include_relative_path2", "relativeInclude2");
assertFileSnapshot("include_relative_path3", "relativeInclude3");
assertFileSnapshot("include_relative_path4", "relativeIncludes/foo");
assertCompileError(
"include_missing_file",
"from \"foo\" include Foo; 2",
"Missing file for module \"foo.gr\"",
);
/* Unbound module tests */
assertCompileError(
"test_unbound_module",
"String.concat(\"hello \", \"world\")",
"Unbound module String",
);
/* Misc include tests */
assertCompileError(
"test_bad_import",
"{let x = (1, 2); from \"tlists\" include TLists; x}",
"error",
);
assertFileRun("test_file_same_name", "list", "OK\n");
assertSnapshot(
"annotation_across_import",
"from \"tlists\" include TLists; use TLists.{ type TList }; let foo : TLists.TList<String> = Empty; foo",
);
assertFileRun(
"relative_include_linking",
"relativeIncludeLinking",
"2\n2\n",
);
assertFileCompileError(
"include_broken",
"brokenIncludes/main",
"./broken.gr\", line 4, characters 5-15",
);
assertCompileError(
"include_extension1",
"from \"list.gr\" include List",
"Missing file for module \"list.gr\": did you mean \"list\"?",
);
assertCompileError(
"include_extension2",
"from \"brokenRelativeInclude\" include BrokenRelativeInclude",
"Missing file for module \"./data\": did you mean \"./data.gr\"?",
);
assertRun(
"reprovide_values",
"from \"reprovideContents\" include ReprovideContents; use ReprovideContents.{ type Type, module Mod }; print(A); print(Mod.val)",
"A\n123\n",
);
assertRun(
"reprovide_type2",
"from \"reprovideContents\" include ReprovideContents; use ReprovideContents.{ type OtherT as TT, val }; print(val); print({ x: 2 })",
"{\n x: 1\n}\n{\n x: 2\n}\n",
);
assertRun(
"reprovide_type3",
"from \"reprovideContents\" include ReprovideContents; use ReprovideContents.{ type OtherT as Other }; print({ x: 1 }: Other)",
"{\n x: 1\n}\n",
);
});