@@ -68,7 +68,7 @@ sorts =
68
68
" sort variables"
69
69
[ test " sort variable in pattern" (app con1 [varX]) (app con1 [dSome]) $
70
70
sortErr (FoundSortVariable " sort me!" )
71
- , test " sort variable in subject" (app con1 [dSub ]) (app con1 [varZ ]) $
71
+ , test " sort variable in subject" (app con1 [varZ ]) (app con1 [dSub ]) $
72
72
sortErr (FoundSortVariable " me, too!" )
73
73
, test " several sort variables" (app con3 [varX, varY]) (app con3 [dSome, varZ]) $
74
74
sortErr (FoundSortVariable " sort me!" )
@@ -85,7 +85,7 @@ sorts =
85
85
constructors :: TestTree
86
86
constructors =
87
87
testGroup
88
- " Unifying constructors"
88
+ " Matching constructors"
89
89
[ test
90
90
" same constructors, one variable argument"
91
91
(app con1 [var " X" someSort])
@@ -176,7 +176,7 @@ varsAndValues =
176
176
, let v1 = var " X" someSort
177
177
v2 = var " Y" aSubsort
178
178
in test " two variables (v2 subsort v1)" v1 v2 $
179
- success [(" X" , someSort, v2)]
179
+ success [(" X" , someSort, inj aSubsort someSort v2)]
180
180
, let v1 = var " X" aSubsort
181
181
v2 = var " Y" someSort
182
182
in test " two variables (v1 subsort v2)" v1 v2 $
@@ -276,22 +276,22 @@ internalLists =
276
276
" Concrete lists of different length fail to match"
277
277
two
278
278
three
279
- (failed $ DifferentValues two three )
279
+ (failed $ DifferentValues emptyList $ klist [headElem] Nothing )
280
280
, test
281
281
" Empty and non-empty list fail to match (symbolic tail)"
282
282
headList
283
283
emptyList
284
284
(failed $ DifferentValues headList emptyList)
285
285
, test
286
- " Empty and non- empty list fail to match (symbolic init)"
286
+ " Non-empty and empty list fail to match (symbolic init)"
287
287
tailList
288
288
emptyList
289
289
(failed $ DifferentValues tailList emptyList)
290
290
, test
291
- " Unification failures may swap the argument lists "
291
+ " Empty and non-empty list fail to match (symbolic init) "
292
292
emptyList
293
293
tailList
294
- (failed $ DifferentValues tailList emptyList)
294
+ (failed $ DifferentValues emptyList tailList )
295
295
, test
296
296
" Head list and tail list produce indeterminate unification"
297
297
headList
@@ -350,7 +350,7 @@ internalLists =
350
350
(replicate 3 headElem)
351
351
(Just (var " LIST2" listSort, replicate 3 lastElem))
352
352
in test
353
- " Unifies two lists with symbolic middle (binding LIST1)"
353
+ " Match two lists with symbolic middle (binding LIST1)"
354
354
list1
355
355
list2
356
356
(success [(" LIST1" , listSort, klist [] (Just (var " LIST2" listSort, [lastElem])))])
@@ -363,10 +363,12 @@ internalLists =
363
363
(replicate 3 headElem)
364
364
(Just (var " LIST2" listSort, replicate 3 lastElem))
365
365
in test
366
- " Unifies two lists with symbolic middle (binding LIST1) , reverse direction"
366
+ " Match two lists with symbolic middle, reverse direction indeterminate "
367
367
list2
368
368
list1
369
- (success [(" LIST1" , listSort, klist [] (Just (var " LIST2" listSort, [lastElem])))])
369
+ ( remainder
370
+ [(klist [] (Just (var " LIST2" listSort, [lastElem])), klist [] (Just (var " LIST1" listSort, [] )))]
371
+ )
370
372
]
371
373
where
372
374
headElem = [trm | \dv{SomeSort{}}("head") |]
@@ -389,23 +391,30 @@ internalMaps =
389
391
concreteKMapWithTwoItems
390
392
(success [] )
391
393
, test
392
- " Can match a concrete and symbolic map"
393
- concreteKMapWithOneItem
394
+ " Can match a symbolic and concrete map"
394
395
symbolicKMapWithOneItem
395
- (success [(" A" , kmapElementSort, [trm | \dv{SortTestKMapItem{}}("value")|])])
396
+ concreteKMapWithOneItem
397
+ (success [(" B" , kmapElementSort, [trm | \dv{SortTestKMapItem{}}("value")|])])
396
398
, test
397
- " Can match a concrete and symbolic map with two elements"
398
- concreteKMapWithTwoItems
399
+ " Can match a symbolic and concrete map with two elements"
399
400
symbolicKMapWithTwoItems
401
+ concreteKMapWithTwoItems
400
402
( success
401
403
[ (" A" , kmapElementSort, [trm | \dv{SortTestKMapItem{}}("value")|])
402
404
, (" B" , kmapElementSort, [trm | \dv{SortTestKMapItem{}}("value2")|])
403
405
]
404
406
)
405
407
, test
406
- " Can match {\" key\" |-> \" value \" , ...REST} with {A |-> \" value \" }"
407
- concreteKMapWithOneItemAndRest
408
+ " Can match {\" key\" |-> A , ...REST} with {\" key \" |-> B }"
409
+ concreteKeySymbolicValueKMapWithRest
408
410
symbolicKMapWithOneItem
411
+ ( success
412
+ [(" REST" , kmapSort, emptyKMap), (" A" , kmapElementSort, [trm | B:SortTestKMapItem{} |])]
413
+ )
414
+ , test
415
+ " Can match {\" key\" |-> A, ...REST} with {\" key\" |-> \" value\" }"
416
+ concreteKeySymbolicValueKMapWithRest
417
+ concreteKMapWithOneItem
409
418
( success
410
419
[(" REST" , kmapSort, emptyKMap), (" A" , kmapElementSort, [trm | \dv{SortTestKMapItem{}}("value")|])]
411
420
)
@@ -428,28 +437,27 @@ internalMaps =
428
437
)
429
438
]
430
439
)
431
- , -- TODO: re-enable once we re-factor the map matching
432
- -- this would not produce a matchign substitution and should therefore fail
440
+ , -- this would not produce a matching substitution and should therefore fail
433
441
-- at match time
434
- -- , test
435
- -- "Fails to match {\"key\" |-> \"value\", A |-> \"value2\"} with {\"key\" |-> \"value\", ...REST}"
436
- -- concreteAndSymbolicKMapWithTwoItems
437
- -- concreteKMapWithOneItemAndRest
438
- -- ( failed $
439
- -- DifferentSymbols
440
- -- ( KMap
441
- -- testKMapDefinition
442
- -- [
443
- -- ( [trm| A:SortTestKMapKey{}|]
444
- -- , [trm| \dv{SortTestKMapItem{}}("value2") |]
445
- -- )
446
- -- ]
447
- -- Nothing
448
- -- )
449
- -- (KMap testKMapDefinition [] (Just [trm| REST:SortTestKMap{}|]))
450
- -- )
451
442
test
452
- " Can match {\" f()\" |-> \" value\" , ...REST} with {\" f()\" |-> B}"
443
+ " Fails to match {\" key\" |-> \" value\" , A |-> \" value2\" } with {\" key\" |-> \" value\" , ...REST}"
444
+ concreteAndSymbolicKMapWithTwoItems
445
+ concreteKMapWithOneItemAndRest
446
+ ( failed $
447
+ DifferentSymbols
448
+ ( KMap
449
+ testKMapDefinition
450
+ [
451
+ ( [trm | A:SortTestKMapKey{}|]
452
+ , [trm | \dv{SortTestKMapItem{}}("value2") |]
453
+ )
454
+ ]
455
+ Nothing
456
+ )
457
+ (KMap testKMapDefinition [] (Just [trm | REST:SortTestKMap{}|]))
458
+ )
459
+ , test
460
+ " Can match {\" f()\" |-> \" value\" , ...REST} with {\" f()\" |-> \" value\" }"
453
461
functionKMapWithOneItemAndRest
454
462
functionKMapWithOneItem
455
463
( success
@@ -461,23 +469,18 @@ internalMaps =
461
469
[]
462
470
Nothing
463
471
)
464
- ,
465
- ( " B"
466
- , SortApp " SortTestKMapItem" []
467
- , [trm | \dv{SortTestKMapItem{}}("value") |]
468
- )
469
472
]
470
473
)
471
474
, test
472
475
" Empty and non-empty concrete map fail to match"
473
476
emptyKMap
474
477
concreteKMapWithOneItem
475
- (failed $ KeyNotFound [ trm | \dv{SortTestKMapKey{}}("key")|] emptyKMap)
478
+ (failed $ DifferentSymbols emptyKMap concreteKMapWithOneItem )
476
479
, test
477
480
" Concrete maps of different length fail to match"
478
481
concreteKMapWithTwoItems
479
482
concreteKMapWithOneItem
480
- (failed $ KeyNotFound [trm | \dv{SortTestKMapKey{}}("key2")|] concreteKMapWithOneItem )
483
+ (failed $ KeyNotFound [trm | \dv{SortTestKMapKey{}}("key2")|] emptyKMap )
481
484
, test
482
485
" Symbolic non-empty map and empty map fail to match"
483
486
symbolicKMapWithOneItem
0 commit comments