aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ai-test.scm48
-rw-r--r--tests/prefabs-test.scm32
2 files changed, 12 insertions, 68 deletions
diff --git a/tests/ai-test.scm b/tests/ai-test.scm
deleted file mode 100644
index 02a9806..0000000
--- a/tests/ai-test.scm
+++ /dev/null
@@ -1,48 +0,0 @@
-;; Mock entity module for testing
-(module downstroke-entity *
- (import scheme (chicken base) (chicken keyword))
- (define (entity-ref entity key #!optional default)
- (get-keyword key entity (if (procedure? default) default (lambda () default))))
- (define (entity-set entity key val)
- (cons key (cons val (let loop ((lst entity))
- (if (null? lst) '()
- (if (eq? (car lst) key)
- (cddr lst)
- (cons (car lst) (cons (cadr lst) (loop (cddr lst))))))))))
- (define (entity-type e) (entity-ref e #:type #f)))
-
-;; Mock world module for testing
-(module downstroke-world *
- (import scheme (chicken base))
- (define (scene-entities s) s)
- (define (scene-find-tagged scene tag) #f))
-
-(import (srfi 64)
- states
- downstroke-entity
- downstroke-world)
-
-(include "ai.scm")
-(import downstroke-ai)
-
-(test-begin "ai")
-
-(test-group "find-player (tag-based)"
- (let* ((player (list #:type 'player #:x 100 #:y 100 #:width 16 #:height 16
- #:tags '(player)))
- (enemy (list #:type 'enemy #:x 200 #:y 100 #:width 16 #:height 16
- #:tags '(enemy)))
- (entities (list enemy player)))
- (test-equal "finds player by tags" player (find-player entities))
- (test-equal "returns #f with no player" #f (find-player (list enemy)))))
-
-(test-group "update-enemy-ai"
- (let* ((entity (list #:type 'enemy #:x 0 #:y 0 #:width 16 #:height 16
- #:disabled #t)))
- (test-equal "returns entity unchanged when disabled" entity
- (update-enemy-ai entity '())))
- (let* ((entity (list #:type 'enemy #:x 0 #:y 0 #:width 16 #:height 16)))
- (test-equal "returns entity unchanged when no ai-machine" entity
- (update-enemy-ai entity '()))))
-
-(test-end "ai")
diff --git a/tests/prefabs-test.scm b/tests/prefabs-test.scm
index f8cec0a..e635d0a 100644
--- a/tests/prefabs-test.scm
+++ b/tests/prefabs-test.scm
@@ -24,12 +24,6 @@
(define (entity-type entity) (entity-ref entity #:type #f)))
(import downstroke-entity)
-;; Mock downstroke-ai
-(module downstroke-ai *
- (import scheme (chicken base))
- (define (make-enemy-ai-machine) 'mock-ai-machine))
-(import downstroke-ai)
-
;; Load module under test
(include "entity.scm")
(import downstroke-entity)
@@ -45,7 +39,6 @@
(test-assert "physics-body entry exists" (assq 'physics-body m))
(test-assert "has-facing entry exists" (assq 'has-facing m))
(test-assert "animated entry exists" (assq 'animated m))
- (test-assert "ai-body entry exists" (assq 'ai-body m))
(let ((pb (cdr (assq 'physics-body m))))
(test-equal "physics-body has #:vx 0" 0 (cadr (memq #:vx pb)))
@@ -55,12 +48,7 @@
(let ((an (cdr (assq 'animated m))))
(test-equal "animated has #:anim-tick 0" 0 (cadr (memq #:anim-tick an)))
(test-equal "animated has #:tile-id 0" 0 (cadr (memq #:tile-id an)))
- (test-equal "animated has #:anim-name idle" 'idle (cadr (memq #:anim-name an))))
-
- (let ((ai (cdr (assq 'ai-body m))))
- (test-equal "ai-body has #:ai-machine #f" #f (cadr (memq #:ai-machine ai)))
- (test-equal "ai-body has #:disabled #f" #f (cadr (memq #:disabled ai)))
- (test-equal "ai-body has #:chase-origin-x 0" 0 (cadr (memq #:chase-origin-x ai))))))
+ (test-equal "animated has #:anim-name idle" 'idle (cadr (memq #:anim-name an))))))
(test-group "compose-prefab (via load-prefabs with temp file)"
@@ -176,14 +164,18 @@
#t
(entity-ref e #:initialized))))))
- (test-group "init-enemy-ai engine hook"
- (with-hook-registry
- "(npc ai-body has-facing #:type npc #:on-instantiate init-enemy-ai)"
- '()
- (lambda (reg)
+ (test-group "game hook via user-hooks (e.g. init-enemy-ai pattern)"
+ (let ((tmp "/tmp/test-prefabs-user-init.scm"))
+ (with-output-to-file tmp
+ (lambda ()
+ (display
+ "((mixins (ai-body #:ai-facing 1 #:ai-machine #f #:chase-origin-x 0 #:disabled #f))
+ (prefabs (npc ai-body has-facing #:type npc #:on-instantiate init-npc)))")))
+ (let ((reg (load-prefabs tmp (engine-mixins)
+ `((init-npc . ,(lambda (e) (entity-set e #:ai-machine 'from-user-hook)))))))
(let ((e (instantiate-prefab reg 'npc 0 0 16 16)))
- (test-equal "engine hook sets #:ai-machine via make-enemy-ai-machine"
- 'mock-ai-machine
+ (test-equal "user hook sets #:ai-machine"
+ 'from-user-hook
(entity-ref e #:ai-machine))))))
(test-group "no hook: entity returned unchanged"