use spanda::timeline::{At, Timeline};
use spanda::traits::Update;
use spanda::tween::Tween;
#[test]
fn at_start_and_end_compose_correctly() {
let mut tl = Timeline::new().add("base", Tween::new(0.0_f32, 1.0).duration(0.5).build(), 0.0);
tl.add_at(
"second",
Tween::new(0.0_f32, 1.0).duration(0.5).build(),
0.5,
At::End,
);
tl.add_at(
"third",
Tween::new(0.0_f32, 1.0).duration(0.3).build(),
0.3,
At::Start,
);
tl.play();
let dt = 0.01;
let mut total = 0.0;
while tl.update(dt) {
total += dt;
if total > 5.0 {
panic!("Timeline did not complete");
}
}
assert!(total > 0.0, "Timeline completed too quickly");
}
#[test]
fn at_label_syncs_animations() {
let mut tl = Timeline::new().add("fade", Tween::new(0.0_f32, 1.0).duration(0.5).build(), 0.2);
tl.add_at(
"scale",
Tween::new(1.0_f32, 2.0).duration(0.3).build(),
0.3,
At::Label("fade"),
);
tl.play();
let dt = 0.01;
let mut total = 0.0;
while tl.update(dt) {
total += dt;
if total > 5.0 {
panic!("Timeline did not complete");
}
}
assert!(
total >= 0.5 && total <= 0.8,
"Expected completion ~0.7s, got {total}"
);
}
#[test]
fn at_offset_creates_gap() {
let mut tl = Timeline::new().add("a", Tween::new(0.0_f32, 1.0).duration(0.5).build(), 0.0);
tl.add_at(
"b",
Tween::new(0.0_f32, 1.0).duration(0.3).build(),
0.3,
At::Offset(0.2),
);
tl.play();
let dt = 0.01;
let mut total = 0.0;
while tl.update(dt) {
total += dt;
if total > 5.0 {
panic!("Timeline did not complete");
}
}
assert!(total > 0.0, "Timeline should have taken some time");
}