diff options
| author | Gene Pasquet <dev@etenil.net> | 2026-04-17 16:30:34 +0100 |
|---|---|---|
| committer | Gene Pasquet <dev@etenil.net> | 2026-04-17 16:30:34 +0100 |
| commit | 8251c85a4a588504d38a2fad05e4b0fe1cdccb9d (patch) | |
| tree | c3fcedb7331caf798f2355c7549b35aa3aaf6ac8 /tests/tween-test.scm | |
| parent | 5de3b9cf122542f2a0c1c906c8ce8add20e5c8c6 (diff) | |
Convert entities to alists
Diffstat (limited to 'tests/tween-test.scm')
| -rw-r--r-- | tests/tween-test.scm | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/tests/tween-test.scm b/tests/tween-test.scm index f0622fb..962d325 100644 --- a/tests/tween-test.scm +++ b/tests/tween-test.scm @@ -4,6 +4,11 @@ (include "tween.scm") (import downstroke-entity downstroke-tween) +(import (only (list-utils alist) plist->alist)) + +;; Test helper: build an alist entity from plist-style keyword args. +(define (entity . kws) (plist->alist kws)) + (test-begin "tween") (test-group "ease functions" @@ -35,7 +40,7 @@ (test-group "make-tween / tween-step" (test-group "linear completes to target" - (let* ((ent (list #:type 'a #:x 0 #:y 10)) + (let* ((ent (entity #:type 'a #:x 0 #:y 10)) (tw (make-tween ent props: '((#:x . 100)) duration: 100 delay: 0 ease: 'linear))) (receive (tw2 e2) (tween-step tw ent 100) (test-assert "finished" (tween-finished? tw2)) @@ -43,7 +48,7 @@ (test-equal "y preserved" 10 (entity-ref e2 #:y))))) (test-group "delay holds props" - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 50)) duration: 100 delay: 40 ease: 'linear))) (receive (tw2 e2) (tween-step tw ent 30) (test-assert "not finished" (not (tween-finished? tw2))) @@ -55,14 +60,14 @@ (test-assert "past delay, moved" (> (entity-ref e4 #:x) 0))))))) (test-group "midpoint linear" - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 100)) duration: 100 delay: 0 ease: 'linear))) (receive (_ e2) (tween-step tw ent 50) (test-equal "halfway x" 50.0 (entity-ref e2 #:x))))) (test-group "on-complete runs once" (let ((calls 0)) - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 10)) duration: 10 delay: 0 ease: 'linear on-complete: (lambda (_) (set! calls (+ calls 1)))))) (receive (tw2 e2) (tween-step tw ent 10) @@ -72,7 +77,7 @@ (test-equal "entity stable" e3 e2)))))) (test-group "idempotent after finish" - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 20)) duration: 10 delay: 0 ease: 'linear))) (receive (tw2 e2) (tween-step tw ent 10) (receive (tw3 e3) (tween-step tw2 e2 999) @@ -81,7 +86,7 @@ (test-group "repeat" (test-group "repeat: 1 plays twice" - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 100)) duration: 100 ease: 'linear repeat: 1))) (receive (tw2 e2) (tween-step tw ent 100) @@ -92,7 +97,7 @@ (test-equal "x at target again" 100.0 (entity-ref e3 #:x)))))) (test-group "repeat: -1 never finishes" - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 10)) duration: 10 ease: 'linear repeat: -1))) (let loop ((tw tw) (ent ent) (i 0)) @@ -102,14 +107,14 @@ (loop tw2 e2 (+ i 1))))))) (test-group "repeat: 0 is default (no repeat)" - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 50)) duration: 50 ease: 'linear))) (receive (tw2 _e2) (tween-step tw ent 50) (test-assert "finished immediately" (tween-finished? tw2))))) (test-group "on-complete fires after last repeat" (let ((calls 0)) - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 10)) duration: 10 ease: 'linear repeat: 1 on-complete: (lambda (_) (set! calls (+ calls 1)))))) @@ -120,7 +125,7 @@ (test-group "on-complete does not fire with repeat: -1" (let ((calls 0)) - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 10)) duration: 10 ease: 'linear repeat: -1 on-complete: (lambda (_) (set! calls (+ calls 1)))))) @@ -131,7 +136,7 @@ (test-group "yoyo" (test-group "yoyo: #t with repeat: 1 reverses" - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 100)) duration: 100 ease: 'linear repeat: 1 yoyo?: #t))) (receive (tw2 e2) (tween-step tw ent 100) @@ -143,7 +148,7 @@ (test-equal "x back to start" 0.0 (entity-ref e4 #:x))))))) (test-group "yoyo: #t with repeat: -1 ping-pongs forever" - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 100)) duration: 100 ease: 'linear repeat: -1 yoyo?: #t))) ;; Forward @@ -158,7 +163,7 @@ (test-assert "still active" (tween-active? tw4))))))) (test-group "yoyo: #f with repeat: 1 replays same direction" - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 100)) duration: 100 ease: 'linear repeat: 1 yoyo?: #f))) (receive (tw2 e2) (tween-step tw ent 100) @@ -169,7 +174,7 @@ (test-assert "not finished mid-repeat" (not (tween-finished? tw3))))))) (test-group "yoyo: #t without repeat has no effect" - (let* ((ent (list #:type 'a #:x 0)) + (let* ((ent (entity #:type 'a #:x 0)) (tw (make-tween ent props: '((#:x . 100)) duration: 100 ease: 'linear repeat: 0 yoyo?: #t))) (receive (tw2 e2) (tween-step tw ent 100) @@ -178,40 +183,40 @@ (test-group "step-tweens pipeline" (test-group "advances #:tween on entity" - (let* ((ent (list #:type 'a #:x 0 - #:tween (make-tween (list #:x 0) props: '((#:x . 100)) - duration: 100 ease: 'linear))) - (e2 (step-tweens ent #f 50))) + (let* ((ent (entity #:type 'a #:x 0 + #:tween (make-tween (entity #:x 0) props: '((#:x . 100)) + duration: 100 ease: 'linear))) + (e2 (step-tweens #f ent 50))) (test-equal "x moved to midpoint" 50.0 (entity-ref e2 #:x)) (test-assert "tween still attached" (entity-ref e2 #:tween #f)))) (test-group "removes #:tween when finished" - (let* ((ent (list #:type 'a #:x 0 - #:tween (make-tween (list #:x 0) props: '((#:x . 100)) - duration: 100 ease: 'linear))) - (e2 (step-tweens ent #f 100))) + (let* ((ent (entity #:type 'a #:x 0 + #:tween (make-tween (entity #:x 0) props: '((#:x . 100)) + duration: 100 ease: 'linear))) + (e2 (step-tweens #f ent 100))) (test-equal "x at target" 100.0 (entity-ref e2 #:x)) (test-equal "tween removed" #f (entity-ref e2 #:tween #f)))) (test-group "no-op without #:tween" - (let* ((ent (list #:type 'a #:x 42)) - (e2 (step-tweens ent #f 100))) + (let* ((ent (entity #:type 'a #:x 42)) + (e2 (step-tweens #f ent 100))) (test-equal "x unchanged" 42 (entity-ref e2 #:x)))) (test-group "keeps repeating tween attached" - (let* ((ent (list #:type 'a #:x 0 - #:tween (make-tween (list #:x 0) props: '((#:x . 100)) - duration: 100 ease: 'linear repeat: -1 yoyo?: #t))) - (e2 (step-tweens ent #f 100))) + (let* ((ent (entity #:type 'a #:x 0 + #:tween (make-tween (entity #:x 0) props: '((#:x . 100)) + duration: 100 ease: 'linear repeat: -1 yoyo?: #t))) + (e2 (step-tweens #f ent 100))) (test-equal "x at target" 100.0 (entity-ref e2 #:x)) (test-assert "tween still attached (repeating)" (entity-ref e2 #:tween #f)))) (test-group "respects #:skip-pipelines" - (let* ((ent (list #:type 'a #:x 0 - #:skip-pipelines '(tweens) - #:tween (make-tween (list #:x 0) props: '((#:x . 100)) - duration: 100 ease: 'linear))) - (e2 (step-tweens ent #f 100))) + (let* ((ent (entity #:type 'a #:x 0 + #:skip-pipelines '(tweens) + #:tween (make-tween (entity #:x 0) props: '((#:x . 100)) + duration: 100 ease: 'linear))) + (e2 (step-tweens #f ent 100))) (test-equal "x unchanged (skipped)" 0 (entity-ref e2 #:x)) (test-assert "tween still there" (entity-ref e2 #:tween #f))))) |
