aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGene Pasquet <dev@etenil.net>2026-04-08 01:57:20 +0100
committerGene Pasquet <dev@etenil.net>2026-04-08 01:57:20 +0100
commit9e8b75f9949259ef01942cd3717b79b044efddf7 (patch)
treec6b71291ade57f0560a9bbf0db9f5b66bab65cb3 /tests
parent84840ede6646ed793b61cdd889d3f57ab05e9311 (diff)
Refactor update pipelines
Diffstat (limited to 'tests')
-rw-r--r--tests/entity-test.scm15
-rw-r--r--tests/world-test.scm42
2 files changed, 40 insertions, 17 deletions
diff --git a/tests/entity-test.scm b/tests/entity-test.scm
index 988d1c9..795aa1c 100644
--- a/tests/entity-test.scm
+++ b/tests/entity-test.scm
@@ -132,4 +132,19 @@
(let ((e '(#:type t #:x 0 #:skip-pipelines (fixture-skip))))
(test-equal "skipped" 0 (entity-ref (fixture-pipeline e) #:x))))
+(define-pipeline (guarded-pipeline guarded-skip) (ent)
+ guard: (entity-ref ent #:active? #f)
+ (entity-set ent #:x 99))
+
+(test-group "define-pipeline with guard:"
+ (let ((e '(#:type t #:x 0 #:active? #t)))
+ (test-equal "runs body when guard passes" 99
+ (entity-ref (guarded-pipeline e) #:x)))
+ (let ((e '(#:type t #:x 0)))
+ (test-equal "returns entity unchanged when guard fails" 0
+ (entity-ref (guarded-pipeline e) #:x)))
+ (let ((e '(#:type t #:x 0 #:active? #t #:skip-pipelines (guarded-skip))))
+ (test-equal "skip-pipelines takes precedence over guard" 0
+ (entity-ref (guarded-pipeline e) #:x))))
+
(test-end "entity")
diff --git a/tests/world-test.scm b/tests/world-test.scm
index 1b368c0..48f492a 100644
--- a/tests/world-test.scm
+++ b/tests/world-test.scm
@@ -154,8 +154,8 @@
'(a b c)
(map entity-type (scene-entities scene)))))
-;; Test: scene-update-entities applies function to all entities
-(test-group "scene-update-entities"
+;; Test: scene-map-entities applies function to all entities
+(test-group "scene-map-entities"
(let* ((e1 '(#:type player #:x 100 #:y 100))
(e2 '(#:type enemy #:x 200 #:y 200))
(scene (make-scene entities: (list e1 e2) tilemap: #f camera-target: #f))
@@ -164,7 +164,7 @@
(y (entity-ref entity #:y))
(type (entity-ref entity #:type)))
(list #:type type #:x (+ x 10) #:y y))))
- (scene2 (scene-update-entities scene move-right)))
+ (scene2 (scene-map-entities scene move-right)))
(test-equal "original scene unchanged"
100
@@ -179,12 +179,12 @@
100
(entity-ref (car (scene-entities scene2)) #:y))))
-;; Test: scene-update-entities with identity function
-(test-group "scene-update-entities-identity"
+;; Test: scene-map-entities with identity function
+(test-group "scene-map-entities-identity"
(let* ((e1 '(#:type player #:x 100))
(e2 '(#:type enemy #:x 200))
(scene (make-scene entities: (list e1 e2) tilemap: #f camera-target: #f))
- (scene2 (scene-update-entities scene (lambda (e) e))))
+ (scene2 (scene-map-entities scene (lambda (e) e))))
(test-equal "entity count unchanged" 2 (length (scene-entities scene2)))
(test-equal "first entity unchanged"
@@ -199,7 +199,7 @@
(test-equal "entity added" 1 (length (scene-entities scene)))
- (let ((scene (scene-update-entities scene
+ (let ((scene (scene-map-entities scene
(lambda (e)
(let ((x (entity-ref e #:x))
(y (entity-ref e #:y))
@@ -274,7 +274,7 @@
(test-equal "returns all friendly entities" 2 (length (scene-find-all-tagged s 'friendly)))
(test-equal "returns empty list when none match" '() (scene-find-all-tagged s 'boss))))
- (test-group "scene-sync-groups"
+ (test-group "sync-groups"
(let* ((gid 'g1)
(origin (list #:type 'group-origin #:group-origin? #t #:group-id gid
#:x 100 #:y 200 #:width 0 #:height 0))
@@ -282,14 +282,22 @@
#:x 0 #:y 0 #:width 8 #:height 8))
(m2 (list #:type 'part #:group-id gid #:group-local-x 0 #:group-local-y 7
#:x 0 #:y 0 #:width 8 #:height 8))
- (s (make-scene entities: (list origin m1 m2) tilemap: #f
- camera: (make-camera x: 0 y: 0) tileset-texture: #f camera-target: #f))
- (s2 (scene-sync-groups s)))
- (test-equal "original scene members unchanged" 0 (entity-ref (list-ref (scene-entities s) 1) #:x))
- (let ((es (scene-entities s2)))
- (test-equal "member 1 follows origin" 105 (entity-ref (list-ref es 1) #:x))
- (test-equal "member 1 y" 200 (entity-ref (list-ref es 1) #:y))
- (test-equal "member 2 x" 100 (entity-ref (list-ref es 2) #:x))
- (test-equal "member 2 y" 207 (entity-ref (list-ref es 2) #:y)))))
+ (entities (list origin m1 m2))
+ (result (sync-groups entities)))
+ (test-equal "original list unchanged" 0 (entity-ref (list-ref entities 1) #:x))
+ (test-equal "member 1 follows origin" 105 (entity-ref (list-ref result 1) #:x))
+ (test-equal "member 1 y" 200 (entity-ref (list-ref result 1) #:y))
+ (test-equal "member 2 x" 100 (entity-ref (list-ref result 2) #:x))
+ (test-equal "member 2 y" 207 (entity-ref (list-ref result 2) #:y))))
+
+ (test-group "scene-transform-entities"
+ (let* ((e1 '(#:type a #:x 1))
+ (e2 '(#:type b #:x 2))
+ (scene (make-scene entities: (list e1 e2) tilemap: #f camera-target: #f))
+ (scene2 (scene-transform-entities scene reverse)))
+ (test-equal "transforms entity list" 'b
+ (entity-type (car (scene-entities scene2))))
+ (test-equal "original scene unchanged" 'a
+ (entity-type (car (scene-entities scene))))))
(test-end "world-module")