The sweep says what it covers, and asserts what it says
Browse files at this commit3e1c94d40dad7e422d1c28b79aa08d26efe82039Parent: b1724e2- test
- the sweep says what it covers, and asserts what it says
1 changed file +211 -11
- crates/engine/src/sweep.rs +211 -11
crates/engine/src/sweep.rsmodified+211 -11
| @@ -1,7 +1,19 @@ | |||
| 1 | -//! The re-timing sweep: every mutating op, against every grouping shape, | 1 | +//! The re-timing sweep: every op that moves or removes timeline time, against |
| 2 | -//! under the universal laws. The "there might be other bugs" catcher -- a | 2 | +//! every grouping shape, under the universal laws -- `delete_in`/`delete_sub_in`, |
| 3 | -//! red cell here is an op whose shape has drifted from the law, found | 3 | +//! `set_speed`/`set_speed_live`, `split`/`regroup`, `move_clip`/`trim`, |
| 4 | -//! before a user finds it. | 4 | +//! `move_sub`/`trim_sub`, `paste`, `ripple_delete`/`cut_regions`, |
| 5 | +//! `lift`/`lift_sub`, `place`/`place_take`/`place_sub`, `delete(idx)` and | ||
| 6 | +//! `retime`. The "there might be other bugs" catcher -- a red cell here is an | ||
| 7 | +//! op whose shape has drifted from the law, found before a user finds it. | ||
| 8 | +//! | ||
| 9 | +//! Left out, by name rather than by omission: `group`/`ungroup`/`group_all` | ||
| 10 | +//! move no time at all (id bookkeeping alone -- their own law is | ||
| 11 | +//! `links_are_consistent`, asked directly by their unit tests and by | ||
| 12 | +//! [`group_all_refuses_a_merge_that_doubles_up_a_lane`](crate::project::tests::group_all_refuses_a_merge_that_doubles_up_a_lane)), | ||
| 13 | +//! and `remove_lane`/`move_lane`/`remove_source`/`remove_subtitles`/`append_clip` | ||
| 14 | +//! touch the lane *list* or the source table, never a placement's span -- | ||
| 15 | +//! outside this module's law and covered by their own unit tests in | ||
| 16 | +//! `project.rs`. | ||
| 5 | //! | 17 | //! |
| 6 | //! The laws are the four nothing downstream can live without: | 18 | //! The laws are the four nothing downstream can live without: |
| 7 | //! | 19 | //! |
| @@ -21,7 +33,7 @@ | |||
| 21 | //! so its cells assert the no-move shape directly instead of through a map. | 33 | //! so its cells assert the no-move shape directly instead of through a map. |
| 22 | 34 | ||
| 23 | use crate::map::TimelineMap; | 35 | use crate::map::TimelineMap; |
| 24 | -use crate::project::{Lane, LaneKind, Speed, SubClip}; | 36 | +use crate::project::{Edge, Lane, LaneKind, Rate, Speed, SubClip}; |
| 25 | use crate::scale::FitPolicy; | 37 | use crate::scale::FitPolicy; |
| 26 | use crate::subtitle::SubtitleTrack; | 38 | use crate::subtitle::SubtitleTrack; |
| 27 | use crate::{Clip, Project}; | 39 | use crate::{Clip, Project}; |
| @@ -151,17 +163,30 @@ fn the_sweep_delete_from_every_anchor() { | |||
| 151 | assert!(deleted, "{shape}/{anchor}: the delete happened"); | 163 | assert!(deleted, "{shape}/{anchor}: the delete happened"); |
| 152 | laws(&p, &format!("{shape}/{anchor} after delete")); | 164 | laws(&p, &format!("{shape}/{anchor} after delete")); |
| 153 | if shape == "ungrouped" { | 165 | if shape == "ungrouped" { |
| 154 | - // The lone-clip law: the span leaves EVERY lane. | 166 | + // `Project::single` links its V1 and A1 clips from the start |
| 155 | - assert!(p.lane(Lane::A1).is_empty() || p.lane(Lane::V1).is_empty(), "{shape}/{anchor}"); | 167 | + // (the source is grouped with itself), so the lone-clip law |
| 168 | + // really is a conjunction: the span leaves EVERY lane. | ||
| 169 | + assert!(p.lane(Lane::A1).is_empty() && p.lane(Lane::V1).is_empty(), "{shape}/{anchor}"); | ||
| 156 | } else { | 170 | } else { |
| 157 | // The group law: every member gone, from every anchor. | 171 | // The group law: every member gone, from every anchor. |
| 158 | assert!(p.lane(Lane::V1).is_empty(), "{shape}/{anchor}: V1 emptied"); | 172 | assert!(p.lane(Lane::V1).is_empty(), "{shape}/{anchor}: V1 emptied"); |
| 159 | assert!(p.lane(Lane::A1).is_empty(), "{shape}/{anchor}: A1 emptied"); | 173 | assert!(p.lane(Lane::A1).is_empty(), "{shape}/{anchor}: A1 emptied"); |
| 160 | if let Some(s1) = s1 { | 174 | if let Some(s1) = s1 { |
| 161 | - assert!( | 175 | + // Only "aligned"'s one caption is grouped; "offset" |
| 162 | - p.sub_lane(s1).is_empty() || p.sub_lane(s1).iter().all(|s| s.start >= 60), | 176 | + // groups just its first caption, leaving the ungrouped |
| 163 | - "{shape}/{anchor}: the caption gone with the group" | 177 | + // follower to close up behind the hole the delete cuts. |
| 164 | - ); | 178 | + match shape { |
| 179 | + "aligned" => assert!( | ||
| 180 | + p.sub_lane(s1).is_empty(), | ||
| 181 | + "{shape}/{anchor}: the caption gone with the group" | ||
| 182 | + ), | ||
| 183 | + "offset" => assert_eq!( | ||
| 184 | + p.sub_lane(s1).iter().map(|s| (s.start, s.end())).collect::<Vec<_>>(), | ||
| 185 | + vec![(60, 90)], | ||
| 186 | + "{shape}/{anchor}: the grouped caption gone, the follower closed up behind it" | ||
| 187 | + ), | ||
| 188 | + _ => unreachable!("the sweep names three grouped shapes with captions"), | ||
| 189 | + } | ||
| 165 | } | 190 | } |
| 166 | } | 191 | } |
| 167 | undo_round_trip(p, pre, &format!("{shape}/{anchor} delete")); | 192 | undo_round_trip(p, pre, &format!("{shape}/{anchor} delete")); |
| @@ -291,3 +316,178 @@ fn the_sweep_paste_is_the_named_exception() { | |||
| 291 | undo_round_trip(p, pre, &format!("{shape} paste")); | 316 | undo_round_trip(p, pre, &format!("{shape} paste")); |
| 292 | } | 317 | } |
| 293 | } | 318 | } |
| 319 | + | ||
| 320 | +/// The scoped and whole-timeline ripples: [`Project::ripple_delete`] and | ||
| 321 | +/// [`Project::cut_regions`] both close a hole across every lane they touch, | ||
| 322 | +/// clips and captions alike -- a span safely inside every shape's geometry | ||
| 323 | +/// (never on a clip or caption edge, so the cell asks the general law and not | ||
| 324 | +/// one shape's particular boundary). | ||
| 325 | +#[test] | ||
| 326 | +fn the_sweep_ripple_delete_and_cut_regions_close_every_lane() { | ||
| 327 | + for shape in SHAPES { | ||
| 328 | + let (mut p, _s1) = project(shape); | ||
| 329 | + let pre = p.parts(); | ||
| 330 | + assert!(p.ripple_delete(70, 10), "{shape}: the ripple cuts"); | ||
| 331 | + laws(&p, &format!("{shape} after ripple_delete")); | ||
| 332 | + undo_round_trip(p, pre, &format!("{shape} ripple_delete")); | ||
| 333 | + | ||
| 334 | + let (mut p, _s1) = project(shape); | ||
| 335 | + let pre = p.parts(); | ||
| 336 | + assert!( | ||
| 337 | + p.cut_regions(&[(70, 10)], &p.lanes()).is_ok(), | ||
| 338 | + "{shape}: the scoped cut lands" | ||
| 339 | + ); | ||
| 340 | + laws(&p, &format!("{shape} after cut_regions")); | ||
| 341 | + undo_round_trip(p, pre, &format!("{shape} cut_regions")); | ||
| 342 | + } | ||
| 343 | +} | ||
| 344 | + | ||
| 345 | +/// The two single-lane, group-blind lifts: [`Project::lift`] and | ||
| 346 | +/// [`Project::lift_sub`] take one placement off its own lane and leave a gap | ||
| 347 | +/// -- no other lane moves, grouped or not, which the law asks by checking | ||
| 348 | +/// every OTHER lane is untouched. | ||
| 349 | +#[test] | ||
| 350 | +fn the_sweep_lift_and_lift_sub_leave_a_gap_alone() { | ||
| 351 | + for shape in SHAPES { | ||
| 352 | + let (mut p, s1) = project(shape); | ||
| 353 | + let before_a1 = p.lane(Lane::A1).to_vec(); | ||
| 354 | + let pre = p.parts(); | ||
| 355 | + assert!(p.lift(Lane::V1, 0), "{shape}: the lift takes V1's clip"); | ||
| 356 | + assert!(p.lane(Lane::V1).is_empty(), "{shape}: V1 left a gap"); | ||
| 357 | + assert_eq!(p.lane(Lane::A1).to_vec(), before_a1, "{shape}: A1 never asked"); | ||
| 358 | + laws(&p, &format!("{shape} after lift")); | ||
| 359 | + undo_round_trip(p, pre, &format!("{shape} lift")); | ||
| 360 | + | ||
| 361 | + let Some(s1) = s1 else { continue }; | ||
| 362 | + let (mut p, s1) = (project(shape).0, s1); | ||
| 363 | + let before_v1 = p.lane(Lane::V1).to_vec(); | ||
| 364 | + let pre = p.parts(); | ||
| 365 | + assert!(p.lift_sub(s1, 0), "{shape}: the lift takes the caption"); | ||
| 366 | + assert_eq!(p.lane(Lane::V1).to_vec(), before_v1, "{shape}: V1 never asked"); | ||
| 367 | + laws(&p, &format!("{shape} after lift_sub")); | ||
| 368 | + undo_round_trip(p, pre, &format!("{shape} lift_sub")); | ||
| 369 | + } | ||
| 370 | +} | ||
| 371 | + | ||
| 372 | +/// The caption's own two edits: [`Project::move_sub`] carries its group's | ||
| 373 | +/// clips along it, one delta for all of them (exactly as a clip's | ||
| 374 | +/// [`Project::move_clip`] does), and [`Project::trim_sub`] drags its group's | ||
| 375 | +/// edge along with its own window, one delta each member clamps to its own | ||
| 376 | +/// room (`Project::follow_group`) -- the same law, not a caption exception. | ||
| 377 | +#[test] | ||
| 378 | +fn the_sweep_move_sub_and_trim_sub_keep_their_own_law() { | ||
| 379 | + for shape in ["aligned", "offset"] { | ||
| 380 | + let (mut p, s1) = project(shape); | ||
| 381 | + let s1 = s1.expect("aligned and offset both carry a caption"); | ||
| 382 | + let pre = p.parts(); | ||
| 383 | + let v1_before = p.lane(Lane::V1)[0]; | ||
| 384 | + let sub_before = p.sub_lane(s1)[0].start; | ||
| 385 | + let to = sub_before + 5; | ||
| 386 | + assert!(p.move_sub(s1, 0, s1, to).is_ok(), "{shape}: room to drag"); | ||
| 387 | + laws(&p, &format!("{shape} after move_sub")); | ||
| 388 | + let v1_after = p.lane(Lane::V1)[0]; | ||
| 389 | + assert_eq!( | ||
| 390 | + i64::from(v1_after.start) - i64::from(v1_before.start), | ||
| 391 | + i64::from(p.sub_lane(s1)[0].start) - i64::from(sub_before), | ||
| 392 | + "{shape}: the grouped clip rode the same delta as the caption" | ||
| 393 | + ); | ||
| 394 | + undo_round_trip(p, pre, &format!("{shape} move_sub")); | ||
| 395 | + | ||
| 396 | + // A caption in a group drags its group's edge along with its own | ||
| 397 | + // (`Project::follow_group`) -- exactly like `move_sub` above, not the | ||
| 398 | + // "own window alone" case this cell first assumed. | ||
| 399 | + let (mut p, s1) = project(shape); | ||
| 400 | + let s1 = s1.unwrap(); | ||
| 401 | + let pre = p.parts(); | ||
| 402 | + let end = p.sub_lane(s1)[0].end(); | ||
| 403 | + assert!( | ||
| 404 | + p.trim_sub(s1, 0, Edge::End, end - 5, 30.0).is_ok(), | ||
| 405 | + "{shape}: room to trim" | ||
| 406 | + ); | ||
| 407 | + laws(&p, &format!("{shape} after trim_sub")); | ||
| 408 | + undo_round_trip(p, pre, &format!("{shape} trim_sub")); | ||
| 409 | + } | ||
| 410 | +} | ||
| 411 | + | ||
| 412 | +/// The three overwrite doors -- [`Project::place`], [`Project::place_take`] | ||
| 413 | +/// and [`Project::place_sub`] -- are [`the_sweep_paste_is_the_named_exception`]'s | ||
| 414 | +/// own shape: they land over whatever is there and nothing else on the lane | ||
| 415 | +/// ripples, media or captions. | ||
| 416 | +#[test] | ||
| 417 | +fn the_sweep_place_doors_overwrite_without_rippling() { | ||
| 418 | + for shape in SHAPES { | ||
| 419 | + let (mut p, _s1) = project(shape); | ||
| 420 | + let pre = p.parts(); | ||
| 421 | + assert!(p.place(Lane::V1, 10, clip(10, 0, 20)), "{shape}: place lands"); | ||
| 422 | + laws(&p, &format!("{shape} after place")); | ||
| 423 | + undo_round_trip(p, pre, &format!("{shape} place")); | ||
| 424 | + | ||
| 425 | + let (mut p, _s1) = project(shape); | ||
| 426 | + // `add_lane` costs no undo step of its own (it is metadata until | ||
| 427 | + // something places on it), so `pre` is read after it -- the lane | ||
| 428 | + // list itself is part of what undo restores. | ||
| 429 | + let v2 = p.add_lane(LaneKind::Video); | ||
| 430 | + let pre = p.parts(); | ||
| 431 | + assert!(p.place_take(v2, 10, clip(10, 0, 20)), "{shape}: place_take lands"); | ||
| 432 | + laws(&p, &format!("{shape} after place_take")); | ||
| 433 | + undo_round_trip(p, pre, &format!("{shape} place_take")); | ||
| 434 | + | ||
| 435 | + let (mut p, _s1) = project(shape); | ||
| 436 | + let s1 = p.add_lane(LaneKind::Subtitle); | ||
| 437 | + let pre = p.parts(); | ||
| 438 | + assert!(p.place_sub(s1, 5, caption(5, 10)).is_ok(), "{shape}: place_sub lands"); | ||
| 439 | + laws(&p, &format!("{shape} after place_sub")); | ||
| 440 | + undo_round_trip(p, pre, &format!("{shape} place_sub")); | ||
| 441 | + } | ||
| 442 | +} | ||
| 443 | + | ||
| 444 | +/// [`Project::delete`] is sugar for [`Project::delete_in`] on `V1` -- the | ||
| 445 | +/// single-lane front-end door the app's own delete key is wired to. One cell | ||
| 446 | +/// pinning the delegation rather than the whole delete sweep again. | ||
| 447 | +#[test] | ||
| 448 | +fn the_sweep_delete_by_index_is_delete_in_on_v1() { | ||
| 449 | + let (mut a, _) = project("clips"); | ||
| 450 | + let (mut b, _) = project("clips"); | ||
| 451 | + assert_eq!(a.delete(0), b.delete_in(Lane::V1, 0)); | ||
| 452 | + laws(&a, "delete(idx)"); | ||
| 453 | + assert_eq!(a.parts(), b.parts(), "delete(idx) and delete_in(V1, idx) agree"); | ||
| 454 | +} | ||
| 455 | + | ||
| 456 | +/// [`Project::set_speed_live`] is the drag sample of [`Project::set_speed`]: | ||
| 457 | +/// every sample only regrades the rate, and the whole gesture undoes in the | ||
| 458 | +/// one step the press took ([`a_whole_colour_drag_undoes_in_one_step`]'s law, | ||
| 459 | +/// for a rate instead of a grade). | ||
| 460 | +#[test] | ||
| 461 | +fn the_sweep_speed_live_drags_in_one_step() { | ||
| 462 | + for shape in SHAPES { | ||
| 463 | + let (mut p, _s1) = project(shape); | ||
| 464 | + let pre = p.parts(); | ||
| 465 | + assert!(p.set_speed(Lane::V1, 0, Speed::from_permille(1100)).is_ok(), "{shape}: the press"); | ||
| 466 | + for permille in [1200, 1300, 1400] { | ||
| 467 | + assert!( | ||
| 468 | + p.set_speed_live(Lane::V1, 0, Speed::from_permille(permille)).is_ok(), | ||
| 469 | + "{shape}: a live sample" | ||
| 470 | + ); | ||
| 471 | + laws(&p, &format!("{shape} after a live speed sample")); | ||
| 472 | + } | ||
| 473 | + undo_round_trip(p, pre, &format!("{shape} speed drag")); | ||
| 474 | + } | ||
| 475 | +} | ||
| 476 | + | ||
| 477 | +/// [`Project::retime`] moves every frame number without being an edit anyone | ||
| 478 | +/// made ([`Project::retime`]'s own words) -- no history step to its name, so | ||
| 479 | +/// the sweep asks it the order and consistency laws alone, never the undo | ||
| 480 | +/// round trip the rest of this module leans on. | ||
| 481 | +#[test] | ||
| 482 | +fn the_sweep_retime_keeps_the_lanes_ordered() { | ||
| 483 | + for shape in SHAPES { | ||
| 484 | + let (mut p, _s1) = project(shape); | ||
| 485 | + let steps = p.history_len(); | ||
| 486 | + // Old timeline frames per new one: 1:2 doubles every span, a slow-down | ||
| 487 | + // wide enough that the geometry the sweep builds still fits. | ||
| 488 | + let k = Rate::from_fps(1.0, 2.0).expect("a namable rate"); | ||
| 489 | + p.retime(k, &[10_000]); | ||
| 490 | + assert_eq!(p.history_len(), steps, "retime costs no undo step"); | ||
| 491 | + laws(&p, &format!("{shape} after retime")); | ||
| 492 | + } | ||
| 493 | +} | ||