From f65b0354dfc5f73f8fb804265b09fcf1834f2582 Mon Sep 17 00:00:00 2001 From: codegirl-007 Date: Fri, 14 Aug 2026 22:43:42 -0700 Subject: [PATCH] Test that set_sprite_clip caches clip_def on sprites. Locks spawn/switch cache fill and that a bad clip name leaves the prior cache intact. --- engine/animation_test.odin | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/engine/animation_test.odin b/engine/animation_test.odin index 40df1bc..4ce7a31 100644 --- a/engine/animation_test.odin +++ b/engine/animation_test.odin @@ -118,6 +118,32 @@ set_sprite_clip_switch_and_guards :: proc(t: ^testing.T) { testing.expect_value(t, sprite.time, f32(0.09)) } +@(test) +set_sprite_clip_caches_clip_def :: proc(t: ^testing.T) { + data := make_test_character() + defer destroy_test_character(&data) + + sprite := spawn_sprite(&data, {}, "idle", 0) + testing.expect(t, sprite.has_clip, "spawn should cache a valid clip") + testing.expect_value(t, sprite.clip, "idle") + testing.expect(t, sprite.clip_def.loop, "idle clip loops") + testing.expect_value(t, sprite.clip_def.fps, f32(10)) + testing.expect_value(t, len(sprite.clip_def.frames), 3) + + set_sprite_clip(&sprite, "once") + testing.expect(t, sprite.has_clip, "switch should refresh cache") + testing.expect_value(t, sprite.clip, "once") + testing.expect(t, !sprite.clip_def.loop, "once clip does not loop") + testing.expect_value(t, sprite.clip_def.fps, f32(10)) + testing.expect_value(t, len(sprite.clip_def.frames), 3) + + set_sprite_clip(&sprite, "nope") + testing.expect(t, sprite.has_clip, "bad clip must leave cache intact") + testing.expect_value(t, sprite.clip, "once") + testing.expect(t, !sprite.clip_def.loop, "cached once clip preserved") + testing.expect_value(t, len(sprite.clip_def.frames), 3) +} + @(test) spawn_sprite_valid_and_invalid :: proc(t: ^testing.T) { data := make_test_character()