aboutsummaryrefslogtreecommitdiff
path: root/tests/world-test.scm
diff options
context:
space:
mode:
authorGene Pasquet <dev@etenil.net>2026-04-17 16:30:34 +0100
committerGene Pasquet <dev@etenil.net>2026-04-17 16:30:34 +0100
commit8251c85a4a588504d38a2fad05e4b0fe1cdccb9d (patch)
treec3fcedb7331caf798f2355c7549b35aa3aaf6ac8 /tests/world-test.scm
parent5de3b9cf122542f2a0c1c906c8ce8add20e5c8c6 (diff)
Convert entities to alists
Diffstat (limited to 'tests/world-test.scm')
-rw-r--r--tests/world-test.scm75
1 files changed, 40 insertions, 35 deletions
diff --git a/tests/world-test.scm b/tests/world-test.scm
index bfbb336..a66103e 100644
--- a/tests/world-test.scm
+++ b/tests/world-test.scm
@@ -41,6 +41,11 @@
(include "entity.scm")
(import downstroke-entity)
+(import (only (list-utils alist) plist->alist))
+
+;; Test helper: build an alist entity from plist-style keyword args.
+(define (entity . kws) (plist->alist kws))
+
;; Load the module source directly
(include "world.scm")
;; Now import it to access the exported functions
@@ -111,7 +116,7 @@
;; Test: scene with entities and tilemap
(test-group "scene-with-data"
(let* ((player (entity-set (make-entity 100 100 16 16) #:type 'player))
- (enemy '(#:type enemy #:x 200 #:y 200))
+ (enemy (entity #:type 'enemy #:x 200 #:y 200))
(tilemap "mock-tilemap")
(scene (make-scene entities: (list player enemy)
tilemap: tilemap
@@ -130,7 +135,7 @@
(test-group "scene-add-entity"
(let* ((player (make-entity 100 100 16 16))
(scene (make-scene entities: (list player) tilemap: #f camera-target: #f))
- (enemy '(#:type enemy #:x 200 #:y 200)))
+ (enemy (entity #:type 'enemy #:x 200 #:y 200)))
(test-equal "initial entity count" 1 (length (scene-entities scene)))
@@ -143,9 +148,9 @@
;; Test: scene-add-entity appends to end
(test-group "scene-add-entity-order"
- (let* ((e1 '(#:type a #:x 1))
- (e2 '(#:type b #:x 2))
- (e3 '(#:type c #:x 3))
+ (let* ((e1 (entity #:type 'a #:x 1))
+ (e2 (entity #:type 'b #:x 2))
+ (e3 (entity #:type 'c #:x 3))
(scene (make-scene entities: (list e1) tilemap: #f camera-target: #f))
(scene (scene-add-entity scene e2))
(scene (scene-add-entity scene e3)))
@@ -156,14 +161,14 @@
;; 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))
+ (let* ((e1 (entity #:type 'player #:x 100 #:y 100))
+ (e2 (entity #:type 'enemy #:x 200 #:y 200))
(scene (make-scene entities: (list e1 e2) tilemap: #f camera-target: #f))
- (move-right (lambda (scene entity)
- (let ((x (entity-ref entity #:x))
- (y (entity-ref entity #:y))
- (type (entity-ref entity #:type)))
- (list #:type type #:x (+ x 10) #:y y))))
+ (move-right (lambda (scene ent)
+ (let ((x (entity-ref ent #:x))
+ (y (entity-ref ent #:y))
+ (type (entity-ref ent #:type)))
+ (entity #:type type #:x (+ x 10) #:y y))))
(scene2 (scene-map-entities scene move-right)))
(test-equal "original scene unchanged"
@@ -181,8 +186,8 @@
;; Test: scene-map-entities with identity function
(test-group "scene-map-entities-identity"
- (let* ((e1 '(#:type player #:x 100))
- (e2 '(#:type enemy #:x 200))
+ (let* ((e1 (entity #:type 'player #:x 100))
+ (e2 (entity #:type 'enemy #:x 200))
(scene (make-scene entities: (list e1 e2) tilemap: #f camera-target: #f))
(scene2 (scene-map-entities scene (lambda (scene e) e))))
@@ -204,8 +209,8 @@
(let ((x (entity-ref e #:x))
(y (entity-ref e #:y))
(type (entity-type e)))
- (list #:type type #:x (* x 2) #:y (* y 2)
- #:width 16 #:height 16))))))
+ (entity #:type type #:x (* x 2) #:y (* y 2)
+ #:width 16 #:height 16))))))
(test-equal "entity x doubled" 20 (entity-ref (car (scene-entities scene)) #:x))
(test-equal "entity y doubled" 40 (entity-ref (car (scene-entities scene)) #:y)))))
@@ -227,8 +232,8 @@
;; Test: scene-filter-entities
(test-group "scene-filter-entities"
- (let* ((e1 (list #:type 'player #:x 0 #:y 0 #:width 16 #:height 16))
- (e2 (list #:type 'enemy #:x 0 #:y 0 #:width 16 #:height 16))
+ (let* ((e1 (entity #:type 'player #:x 0 #:y 0 #:width 16 #:height 16))
+ (e2 (entity #:type 'enemy #:x 0 #:y 0 #:width 16 #:height 16))
(scene (make-scene entities: (list e1 e2)
tilemap: test-tilemap
camera: (make-camera x: 0 y: 0)
@@ -244,20 +249,20 @@
(test-group "camera-follow"
(let* ((cam (make-camera x: 0 y: 0))
- (entity (list #:type 'player #:x 400 #:y 300 #:width 16 #:height 16))
- (cam2 (camera-follow cam entity 600 400)))
+ (ent (entity #:type 'player #:x 400 #:y 300 #:width 16 #:height 16))
+ (cam2 (camera-follow cam ent 600 400)))
(test-equal "original camera unchanged" 0 (camera-x cam))
(test-equal "centers camera x on entity" 100 (camera-x cam2))
(test-equal "centers camera y on entity" 100 (camera-y cam2)))
(let* ((cam (make-camera x: 0 y: 0))
- (entity (list #:type 'player #:x 50 #:y 30 #:width 16 #:height 16))
- (cam2 (camera-follow cam entity 600 400)))
+ (ent (entity #:type 'player #:x 50 #:y 30 #:width 16 #:height 16))
+ (cam2 (camera-follow cam ent 600 400)))
(test-equal "clamps camera x to 0 when entity near origin" 0 (camera-x cam2))
(test-equal "clamps camera y to 0 when entity near origin" 0 (camera-y cam2))))
(test-group "scene-find-tagged"
- (let* ((p (list #:type 'player #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(player)))
- (e (list #:type 'enemy #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(enemy npc)))
+ (let* ((p (entity #:type 'player #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(player)))
+ (e (entity #:type 'enemy #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(enemy npc)))
(s (make-scene entities: (list p e) tilemap: #f
camera: (make-camera x: 0 y: 0) tileset-texture: #f camera-target: #f)))
(test-equal "finds entity with matching tag" p (scene-find-tagged s 'player))
@@ -266,9 +271,9 @@
(test-equal "returns #f when tag not found" #f (scene-find-tagged s 'boss))))
(test-group "scene-find-all-tagged"
- (let* ((p1 (list #:type 'player #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(player friendly)))
- (p2 (list #:type 'ally #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(ally friendly)))
- (e (list #:type 'enemy #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(enemy)))
+ (let* ((p1 (entity #:type 'player #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(player friendly)))
+ (p2 (entity #:type 'ally #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(ally friendly)))
+ (e (entity #:type 'enemy #:x 0 #:y 0 #:width 16 #:height 16 #:tags '(enemy)))
(s (make-scene entities: (list p1 p2 e) tilemap: #f
camera: (make-camera x: 0 y: 0) tileset-texture: #f camera-target: #f)))
(test-equal "returns all friendly entities" 2 (length (scene-find-all-tagged s 'friendly)))
@@ -276,12 +281,12 @@
(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))
- (m1 (list #:type 'part #:group-id gid #:group-local-x 5 #:group-local-y 0
- #: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))
+ (origin (entity #:type 'group-origin #:group-origin? #t #:group-id gid
+ #:x 100 #:y 200 #:width 0 #:height 0))
+ (m1 (entity #:type 'part #:group-id gid #:group-local-x 5 #:group-local-y 0
+ #:x 0 #:y 0 #:width 8 #:height 8))
+ (m2 (entity #:type 'part #:group-id gid #:group-local-x 0 #:group-local-y 7
+ #:x 0 #:y 0 #:width 8 #:height 8))
(entities (list origin m1 m2))
(result (sync-groups entities)))
(test-equal "original list unchanged" 0 (entity-ref (list-ref entities 1) #:x))
@@ -291,8 +296,8 @@
(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))
+ (let* ((e1 (entity #:type 'a #:x 1))
+ (e2 (entity #: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