PageRenderTime 77ms CodeModel.GetById 2ms app.highlight 71ms RepoModel.GetById 1ms app.codeStats 0ms

/FingTest/TestCases.fs

http://github.com/sandersn/fing
F# | 461 lines | 436 code | 2 blank | 23 comment | 0 complexity | 07b7ca811b5df8157abed54de8620bf0 MD5 | raw file
  1// Copyright (c) 2010, Nathan Sanders
  2// Licence: New BSD. See accompanying documentation.
  3
  4module TestCases
  5open Types
  6let failures = [
  7 "'a<'a>" // I don't know if this is legal or not.
  8 "'a<'b>" // I .. uh .. think so?
  9 "list<'a<'b>>"
 10 "'a 'a"  // same but with stupid suffix type
 11 // I'm pretty sure this should pass. It's probably related to the special cased parsing
 12 // of 'a :> 'b, which I think has problems detecting the right edge
 13 // ... maybe "and" isn't providing a strong enough right edge there.
 14 // anyway, the error occurs any time that 'a :> 'b isn't the last type var constraint
 15 "list<'a> when 'a : (read<'a,'b when 'a :> 'b and 'a : null> : 'a -> 'b)"
 16 ]
 17// Later: I was thinking of Haskell's type system. F#'s is .NET's, which can't
 18// do higher-kinded stuff. OH WELL, LIVING WITH MEDIOCRITY.
 19let typedefpasses = ["<'a>"
 20                ; "<'a,'b>"
 21                ; "<'a,'b when 'a : null>"
 22                ; "<'a,'b when 'a : (new : unit -> 'T)>"
 23                ; "<'a,'b when 'a : struct>"
 24                ; "<'a,'b when 'a : not struct>"
 25                ; "<'a,'b when 'a : enum<int> >"
 26                ; "<'a,'b when 'a : enum<int Lazy> >"
 27                ; "<'a,'b when 'a : delegate<int,dword> >"
 28                ; "<'a,'b when 'a : (write : int->baz)>"
 29                ; "<'a,'b when 'a : (write : foo:int->bar:baz)>"
 30                ; "<'a,'b when 'a :> int>"
 31                ; "<'a,'b when 'a :> int Lazy>"
 32                ; "<'a,'b when 'a : null and 'b : null>"
 33                ; "<'a when 'a : null and 'a : null>"
 34                ; "<'a,'b when 'a :> 'b>"
 35                ; "<'a,'b when 'a : null and 'a :> 'b>"
 36                ; "<'a when 'a : null and 'a :> 'b>"]
 37let memberpasses = ["read : stream->int->string"
 38                    ; "read : stream->int list->string"
 39                    ; "read : stream->int Lazy->string"
 40                    ; "read : stream->list<int>->string"
 41                    ; "read : stream->int[]->string"
 42                    ; "read : stream->int[,,]->string"
 43                    ; "read : stream->'a->string"
 44                    ; "read : stream->'a when 'a : (read : int->string)->string"
 45                    ; "read : string*stream->int"
 46                    ; "read : ?foo:int->int"
 47                    ; "read : ?foo:int->bar:int->int"
 48                    ] @ [for t in typedefpasses -> "read"+t+" : 'a->'b"]
 49let passes = ["int"
 50             ; "int->int"
 51             ; "int ->   int-> \t int"
 52             ; "'a"
 53             ; "int*int"
 54             ; "int->int*int->int"
 55             ; "int*int->int*int"
 56             ; "'a->'a"
 57             ; "'a*'a"
 58             ; "_*^a"
 59             ; "(int)"
 60             ; "(int->int)"
 61             ; "('a->'a)"
 62             ; "('a*_)->(int->^a)"
 63             ; "(((int)))"
 64             ; "Microsoft.FSharp.Core.double"
 65             ; "Microsoft.FSharp.Core.list`1"
 66             ; "list"
 67             ; "list<>"
 68             ; "list<int>"
 69             ; "list<int->int>"
 70             ; "list<int*int>"
 71             ; "list<int*(int->int*int)>"
 72             ; "list<list<int>>"
 73             ; "list<_>"
 74             ; "list<_,_>"
 75             ; "list<int,'a,_>"
 76             ; "(int) Lazy"
 77             ; "(int->int) Lazy"
 78             ; "('a->'a) Lazy"
 79             ; "('a*_)->(int->^a) Lazy"
 80             ; "(('a*_)->(int->^a)) Lazy"
 81             ; "(((int))) Lazy"
 82             ; "Microsoft.FSharp.Core.double Lazy"
 83             ; "Microsoft.FSharp.Core.list`1 Lazy"
 84             ; "list Lazy"
 85             ; "list<'a> Lazy"
 86             ; "list Lazy Lazy"
 87             ; "int list"
 88             ; "int list Lazy"
 89             ; "int list list"
 90             ; "int list list Lazy"
 91             ; "int[]"
 92             ; "int[,]"
 93             ; "int[,,,,,,,]"
 94             ; "int[,] Lazy"
 95             ; "int[,,] Lazy"
 96             ; "list<'a> when 'a : null"
 97             ; "list<'a> when 'a : null Lazy"
 98             ; "list<'a> Lazy when 'a : null"
 99             ; "list<'a> when 'a : (new : unit -> 'T)"
100             ; "list<'a> when 'a : struct"
101             ; "list<'a> when 'a : not struct"
102             ; "list<'a> when 'a : enum<int>"
103             ; "list<'a> when 'a : delegate<int,'a>"
104             ; "list<'a> when 'a :> Microsoft.Collections.IComparable"
105             ; "list<'a,'b> when 'a :> 'b"
106             ; "list<'a> when 'a : (read : string->int with get)"
107             ; "list<'a> when 'a : (read : string->int with set)"
108             ; "list<'a> when 'a : (read : string->int with get,set)"
109             ; "list<'a> when 'a : (read : string->int with set,get)"
110             ; "list<'a> when ('a or 'b) : (read : string->int->stream)"
111             ; "list<'a> when 'a : (read<'b,'c> : 'a -> 'b -> 'c)"
112             ] @ [for m in memberpasses -> "list<'a> when 'a : ("+m+")"
113             ] @ ["set<'a> -> list<'a>"]
114let test () = 
115  Seq.map Parser.parse passes
116    (*["'a";
117     "(Microsoft.FSharp.Core.int)"; 
118     "Microsoft.FSharp.Core.char"; 
119     "Microsoft.FSharp.Core.string";
120     "Microsoft.FSharp.Core.int * Microsoft.FSharp.Core.int";
121     "Microsoft.FSharp.Core.int * Microsoft.FSharp.Core.int * Microsoft.FSharp.Core.int";
122     "Microsoft.FSharp.Core.int * (Microsoft.FSharp.Core.int * Microsoft.FSharp.Core.int)";
123     "(Microsoft.FSharp.Core.int * Microsoft.FSharp.Core.int) * Microsoft.FSharp.Core.int";
124//     "Microsoft.FSharp.Collections.HashSet" 
125//     "System.Console"
126//     "Microsoft.FSharp.Collections.list`1<Microsoft.FSharp.Core.int>"
127    ] *) 
128let passresults =
129 [Id "int"
130 ;Arrow [Id "int"; Id "int"]
131 ;Arrow [Id "int"; Id "int"; Id "int"]
132 ;Var (Normal "a")
133 ;Tuple [Id "int"; Id "int"]
134 ;Arrow [Id "int"; Tuple [Id "int"; Id "int"]; Id "int"]
135 ;Arrow [Tuple [Id "int"; Id "int"]; Tuple [Id "int"; Id "int"]]
136 ;Arrow [Var (Normal "a"); Var (Normal "a")]
137 ;Tuple [Var (Normal "a"); Var (Normal "a")]
138 ;Tuple [Var Anonymous; Var (Structural "a")]
139 ;Id "int"
140 ;Arrow [Id "int"; Id "int"]
141 ;Arrow [Var (Normal "a"); Var (Normal "a")]
142 ;Arrow
143  [Tuple [Var (Normal "a"); Var Anonymous];
144   Arrow [Id "int"; Var (Structural "a")]]
145 ;Id "int"
146 ;Id "Microsoft.FSharp.Core.double"
147 ;Id "Microsoft.FSharp.Core.list`1"
148 ;Id "list"
149 ;Generic (Id "list",[])
150 ;Generic (Id "list",[Id "int"])
151 ;Generic (Id "list",[Arrow [Id "int"; Id "int"]])
152 ;Generic (Id "list",[Tuple [Id "int"; Id "int"]])
153 ;Generic
154  (Id "list",[Tuple [Id "int"; Arrow [Id "int"; Tuple [Id "int"; Id "int"]]]])
155 ;Generic (Id "list",[Generic (Id "list",[Id "int"])])
156 ;Generic (Id "list",[Var Anonymous])
157 ;Generic (Id "list",[Var Anonymous; Var Anonymous])
158 ;Generic (Id "list",[Id "int"; Var (Normal "a"); Var Anonymous])
159 ;Generic (Id "Lazy",[Id "int"])
160 ;Generic (Id "Lazy",[Arrow [Id "int"; Id "int"]])
161 ;Generic (Id "Lazy",[Arrow [Var (Normal "a"); Var (Normal "a")]])
162 ;Arrow
163  [Tuple [Var (Normal "a"); Var Anonymous];
164   Generic (Id "Lazy",[Arrow [Id "int"; Var (Structural "a")]])]
165 ;Generic
166  (Id "Lazy",
167   [Arrow
168      [Tuple [Var (Normal "a"); Var Anonymous];
169       Arrow [Id "int"; Var (Structural "a")]]])
170 ;Generic (Id "Lazy",[Id "int"])
171 ;Generic (Id "Lazy",[Id "Microsoft.FSharp.Core.double"])
172 ;Generic (Id "Lazy",[Id "Microsoft.FSharp.Core.list`1"])
173 ;Generic (Id "Lazy",[Id "list"])
174 ;Generic (Id "Lazy",[Generic (Id "list",[Var (Normal "a")])])
175 ;Generic (Id "Lazy",[Generic (Id "Lazy",[Id "list"])])
176 ;Generic (Id "list",[Id "int"])
177 ;Generic (Id "Lazy",[Generic (Id "list",[Id "int"])])
178 ;Generic (Id "list",[Generic (Id "list",[Id "int"])])
179 ;Generic (Id "Lazy",[Generic (Id "list",[Generic (Id "list",[Id "int"])])])
180 ;Array (1,Id "int")
181 ;Array (2,Id "int")
182 ;Array (8,Id "int")
183 ;Generic (Id "Lazy",[Array (2,Id "int")])
184 ;Generic (Id "Lazy",[Array (3,Id "int")])
185 ;Constraint (Null (Normal "a"),Generic (Id "list",[Var (Normal "a")]))
186 ;Generic
187  (Id "Lazy",
188   [Constraint (Null (Normal "a"),Generic (Id "list",[Var (Normal "a")]))])
189 ;Constraint
190  (Null (Normal "a"),
191   Generic (Id "Lazy",[Generic (Id "list",[Var (Normal "a")])]))
192 ;Constraint
193  (DefaultConstructor (Normal "a"),Generic (Id "list",[Var (Normal "a")]))
194 ;Constraint (Struct (Normal "a"),Generic (Id "list",[Var (Normal "a")]))
195 ;Constraint (NotStruct (Normal "a"),Generic (Id "list",[Var (Normal "a")]))
196 ;Constraint (Enum (Normal "a",Id "int"),Generic (Id "list",[Var (Normal "a")]))
197 ;Constraint
198  (Delegate (Normal "a",Id "int",Var (Normal "a")),
199   Generic (Id "list",[Var (Normal "a")]))
200 ;Constraint
201  (Subtype (Normal "a",Id "Microsoft.Collections.IComparable"),
202   Generic (Id "list",[Var (Normal "a")]))
203 ;Constraint
204  (Subtype (Normal "a",Var (Normal "b")),
205   Generic (Id "list",[Var (Normal "a"); Var (Normal "b")]))
206 ;Constraint
207  (Sig (Normal "a",Id "read",Arrow [Id "string"; Id "int"],Get),
208   Generic (Id "list",[Var (Normal "a")]))
209 ;Constraint
210  (Sig (Normal "a",Id "read",Arrow [Id "string"; Id "int"],Set),
211   Generic (Id "list",[Var (Normal "a")]))
212 ;Constraint
213  (Sig (Normal "a",Id "read",Arrow [Id "string"; Id "int"],GetSet),
214   Generic (Id "list",[Var (Normal "a")]))
215 ;Constraint
216  (Sig (Normal "a",Id "read",Arrow [Id "string"; Id "int"],GetSet),
217   Generic (Id "list",[Var (Normal "a")]))
218 ;Constraint
219  (Sig
220     (Choice [Normal "a"; Normal "b"],Id "read",
221      Arrow [Id "string"; Id "int"; Id "stream"],Function),
222   Generic (Id "list",[Var (Normal "a")]))
223 ;Constraint
224  (Sig
225     (Normal "a",Generic (Id "read",[Var (Normal "b"); Var (Normal "c")]),
226      Arrow [Var (Normal "a"); Var (Normal "b"); Var (Normal "c")],Function),
227   Generic (Id "list",[Var (Normal "a")]))
228 ;Constraint
229  (Sig
230     (Normal "a",Id "read",Arrow [Id "stream"; Id "int"; Id "string"],Function),
231   Generic (Id "list",[Var (Normal "a")]))
232 ;Constraint
233  (Sig
234     (Normal "a",Id "read",
235      Arrow [Id "stream"; Generic (Id "list",[Id "int"]); Id "string"],Function),
236   Generic (Id "list",[Var (Normal "a")]))
237 ;Constraint
238  (Sig
239     (Normal "a",Id "read",
240      Arrow [Id "stream"; Generic (Id "Lazy",[Id "int"]); Id "string"],Function),
241   Generic (Id "list",[Var (Normal "a")]))
242 ;Constraint
243  (Sig
244     (Normal "a",Id "read",
245      Arrow [Id "stream"; Generic (Id "list",[Id "int"]); Id "string"],Function),
246   Generic (Id "list",[Var (Normal "a")]))
247 ;Constraint
248  (Sig
249     (Normal "a",Id "read",Arrow [Id "stream"; Array (1,Id "int"); Id "string"],
250      Function),Generic (Id "list",[Var (Normal "a")]))
251 ;Constraint
252  (Sig
253     (Normal "a",Id "read",Arrow [Id "stream"; Array (3,Id "int"); Id "string"],
254      Function),Generic (Id "list",[Var (Normal "a")]))
255 ;Constraint
256  (Sig
257     (Normal "a",Id "read",Arrow [Id "stream"; Var (Normal "a"); Id "string"],
258      Function),Generic (Id "list",[Var (Normal "a")]))
259 ;Constraint
260  (Sig
261     (Normal "a",Id "read",
262      Arrow
263        [Id "stream";
264         Constraint
265           (Sig (Normal "a",Id "read",Arrow [Id "int"; Id "string"],Function),
266            Var (Normal "a")); Id "string"],Function),
267   Generic (Id "list",[Var (Normal "a")]))
268 ;Constraint
269  (Sig
270     (Normal "a",Id "read",Arrow [Tuple [Id "string"; Id "stream"]; Id "int"],
271      Function),Generic (Id "list",[Var (Normal "a")]))
272 ;Constraint
273  (Sig
274     (Normal "a",Id "read",Arrow [NamedArg ("foo",Id "int",true); Id "int"],
275      Function),Generic (Id "list",[Var (Normal "a")]))
276 ;Constraint
277  (Sig
278     (Normal "a",Id "read",
279      Arrow
280        [NamedArg ("foo",Id "int",true); NamedArg ("bar",Id "int",false);
281         Id "int"],Function),Generic (Id "list",[Var (Normal "a")]))
282 ;Constraint
283  (Sig
284     (Normal "a",Generic (Id "read",[Var (Normal "a")]),
285      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
286   Generic (Id "list",[Var (Normal "a")]))
287 ;Constraint
288  (Sig
289     (Normal "a",Generic (Id "read",[Var (Normal "a"); Var (Normal "b")]),
290      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
291   Generic (Id "list",[Var (Normal "a")]))
292 ;Constraint
293  (Sig
294     (Normal "a",
295      Constraint
296        (TyparConstraint [Null (Normal "a")],
297         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
298      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
299   Generic (Id "list",[Var (Normal "a")]))
300 ;Constraint
301  (Sig
302     (Normal "a",
303      Constraint
304        (TyparConstraint [DefaultConstructor (Normal "a")],
305         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
306      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
307   Generic (Id "list",[Var (Normal "a")]))
308 ;Constraint
309  (Sig
310     (Normal "a",
311      Constraint
312        (TyparConstraint [Struct (Normal "a")],
313         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
314      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
315   Generic (Id "list",[Var (Normal "a")]))
316 ;Constraint
317  (Sig
318     (Normal "a",
319      Constraint
320        (TyparConstraint [NotStruct (Normal "a")],
321         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
322      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
323   Generic (Id "list",[Var (Normal "a")]))
324 ;Constraint
325  (Sig
326     (Normal "a",
327      Constraint
328        (TyparConstraint [Enum (Normal "a",Id "int")],
329         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
330      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
331   Generic (Id "list",[Var (Normal "a")]))
332 ;Constraint
333  (Sig
334     (Normal "a",
335      Constraint
336        (TyparConstraint [Enum (Normal "a",Generic (Id "Lazy",[Id "int"]))],
337         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
338      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
339   Generic (Id "list",[Var (Normal "a")]))
340 ;Constraint
341  (Sig
342     (Normal "a",
343      Constraint
344        (TyparConstraint [Delegate (Normal "a",Id "int",Id "dword")],
345         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
346      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
347   Generic (Id "list",[Var (Normal "a")]))
348 ;Constraint
349  (Sig
350     (Normal "a",
351      Constraint
352        (TyparConstraint [Sig (Normal "a",Id "write",Arrow [Id "int"; Id "baz"],Function)],
353         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
354      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
355   Generic (Id "list",[Var (Normal "a")]))
356 ;Constraint
357  (Sig
358     (Normal "a",
359      Constraint
360        (TyparConstraint
361              [Sig (Normal "a",Id "write",
362                    Arrow
363                      [NamedArg ("foo",Id "int",false);
364                       NamedArg ("bar",Id "baz",false)],Function)],
365         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
366      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
367   Generic (Id "list",[Var (Normal "a")]))
368 ;Constraint
369  (Sig
370     (Normal "a",
371      Constraint
372        (TyparConstraint [Subtype (Normal "a",Id "int")],
373         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
374      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
375   Generic (Id "list",[Var (Normal "a")]))
376 ;Constraint
377  (Sig
378     (Normal "a",
379      Constraint
380        (TyparConstraint [Subtype (Normal "a",Generic (Id "Lazy",[Id "int"]))],
381         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
382      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
383   Generic (Id "list",[Var (Normal "a")]))
384 ;Constraint
385  (Sig
386     (Normal "a",
387      Constraint
388        (TyparConstraint [Null (Normal "a"); Null (Normal "b")],
389         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
390      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
391   Generic (Id "list",[Var (Normal "a")]))
392 ;Constraint
393  (Sig
394     (Normal "a",
395      Constraint
396        (TyparConstraint [Null (Normal "a"); Null (Normal "a")],
397         Generic (Id "read",[Var (Normal "a")])),
398      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
399   Generic (Id "list",[Var (Normal "a")]))
400 ;Constraint
401  (Sig
402     (Normal "a",
403      Constraint
404        (TyparConstraint [Subtype (Normal "a",Var (Normal "b"))],
405         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
406      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
407   Generic (Id "list",[Var (Normal "a")]))
408 ;Constraint
409  (Sig
410     (Normal "a",
411      Constraint
412        (TyparConstraint [Null (Normal "a"); Subtype (Normal "a",Var (Normal "b"))],
413         Generic (Id "read",[Var (Normal "a"); Var (Normal "b")])),
414      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
415   Generic (Id "list",[Var (Normal "a")]))
416 ;Constraint
417  (Sig
418     (Normal "a",
419      Constraint
420        (TyparConstraint [Null (Normal "a"); Subtype (Normal "a",Var (Normal "b"))],
421         Generic (Id "read",[Var (Normal "a")])),
422      Arrow [Var (Normal "a"); Var (Normal "b")],Function),
423   Generic (Id "list",[Var (Normal "a")]))
424 ;Arrow [Generic (Id "set", [Var (Normal "a")]);
425         Generic (Id "list", [Var (Normal "a")])]]
426let usedVarResults = 
427  let e = Set.empty
428  let a = Set.singleton (Normal "a")
429  let _a = Set.ofList [Anonymous;Normal "a"]
430  let ab = Set.ofList [Normal "a";Normal "b"]
431  let aab = Set.add (Choice (List.ofSeq ab)) a
432  let abab = Set.add (Choice (List.ofSeq ab)) ab
433  let _u = Set.singleton Anonymous
434  [e;e;e; a; e;e;e; 
435   a;a; Set.add (Structural "a") _u; e;e; a; 
436   Set.add (Structural "a") _a; e; e; e; e; e; e; e; e; e; e
437   _u; _u; _a; e; e; a; Set.add (Structural "a") _a; Set.add (Structural "a") _a; 
438   e; e; e; e; a; e;e;e;e;e;e;e;e;e;e;
439   a;a;a;a;a;a;a;a;a;
440   ab;a;a;a;a;aab; Set.add (Normal "c") ab
441   // memberpasses
442   a;a;a;a;a;a;a;a;a;a;a;
443   // typedefpasses
444   ab;ab;ab;ab;ab;ab;ab;ab;ab;ab;ab;ab;ab;ab;ab; ab;ab;ab;
445   // new stuff
446   a]
447let substs =
448  [Var (Normal "a")
449  ;Var (Structural "a")
450  ;Var Anonymous
451  ;Var (Choice [Normal "a"; Normal "b"; Structural "c"; Anonymous])
452  ;Id "foo"
453  ;NamedArg("foo", Id "string", false)
454  ;Generic(Id "list",[Var (Normal "a")])
455  ;Generic(Id "list",[Var (Normal "a");Var(Normal "b")])
456  ;Array(8,Id "int")
457  ;Array(8,Generic(Id "list",[Var (Normal "a")]))
458  ;Constraint( Null (Normal "a"), Id "foo")
459  ;Constraint( Null (Normal "a"), Generic(Id "list",[Var (Normal "a")]))
460  ]
461