Skip to content

Commit

Permalink
added tests for parametrized type aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
YarinHeffes committed Oct 16, 2024
1 parent db74f65 commit ffbef6e
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/alias-tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,65 @@

'("p" . "Point")
'("x" . "IFix")))

(deftest test-parametric-alias-definition ()

(check-coalton-types
"(define-alias (UnaryOperator :a) (:a -> :a))")

(check-coalton-types
"(define-alias (Collapse :a :b :c :d) (:d -> :c -> :b -> :a))"))

(deftest test-parametric-alias-the ()
(check-coalton-types
"(define-alias Index UFix)
(define-alias (Collection :a) (List :a))
(define l (the (Collection Index) (make-list 1 2 3 4)))"

'("l" . "(List UFix)")))

(deftest test-parametric-alias-declare ()
(check-coalton-types
"(define-alias (UnaryOperator :a) (:a -> :a))
(declare f (UnaryOperator Integer))
(define f 1+)"

'("f" . "(Integer -> Integer)"))

(check-coalton-types
"(define-alias (UnaryOperator :a) (:a -> :a))
(declare f ((Num :a) => (UnaryOperator :a)))
(define f 1+)"))

(deftest test-parametric-alias-constructors ()
(check-coalton-types
"(define-alias (Pair :a) (Tuple :a :a))
(define-type (Translation :a)
(Translation (Pair (Pair :a))))
(declare get-original-x-coordinate ((Translation :a) -> :a))
(define (get-original-x-coordinate (Translation (Tuple (Tuple x _) _))) x)
(define t (Translation (Tuple (Tuple 2 3) (Tuple 5 7))))
(define x (get-original-x-coordinate t))"

'("get-original-x-coordinate" . "(Translation :a -> :a)")
'("t" . "(Translation Integer)")
'("x" . "Integer"))

(check-coalton-types
"(define-alias (Pair :a) (Tuple :a :a))
(define-struct (Translation :a)
(from (Pair :a))
(to (Pair :a)))
(define t (Translation (Tuple 2 3) (Tuple 5 7)))
(define from (.from t))"

'("t" . "(Translation Integer)")
'("from" . "(Tuple Integer Integer)")))

0 comments on commit ffbef6e

Please sign in to comment.