forge
Explore
Log in

Don't you dare go Hollow

A reindex the entry carries is a step, and it round-trips

Browse files at this commit

4ed8c97e8bac7308796ca0e6af6d8be7a8fca043Ahmet Kaan GümüşParent: 87acb80
  • test
    • a reindex the entry carries is a step, and it round-trips
Show full message
🐛 test(subtitles): a reindex the entry carries is a step, and it round-trips

The app lane's `remove_subtitles` snapshots before it walks the placements
down, and its `Snapshot` carries the palette beside the lanes and the
settings -- so a history step across a reindex is safe, and the old
expectation ("no step survives a reindex the snapshots do not know
about") pins exactly the defect that lane removed. It failed
deterministically on the merged tree.

The test now asserts the round trip it was reaching for: the undo puts
the removed row back and the placement goes on naming the same words,
and the redo takes it off again -- which is where the rest of the test
starts. Lane: lane-bughunt-app.

`cargo test -p engine --test subtitles -- --test-threads=1`: 22 passed.
crates/engine/tests/subtitles.rsmodified+183 -34
@@ -179,7 +179,10 @@ fn a_block_holding_the_erase_after_the_picture_still_draws_the_picture() {
179179
180180 let tracks = subtitle::of_matroska(&file).expect("the walk");
181181 let cue = &tracks[0].cues[0];
182- let image = cue.image.as_ref().expect("the packed block is still a picture");
182+ let image = cue
183+ .image
184+ .as_ref()
185+ .expect("the packed block is still a picture");
183186 assert_eq!((image.width, image.height), (8, 4));
184187 let rgba = image.rgba().expect("it decodes");
185188 assert_eq!(
@@ -378,7 +381,11 @@ fn a_subtitle_row_can_be_removed_and_the_survivors_round_trip() {
378381 .into_owned()
379382 })
380383 .collect();
381- assert_eq!(names, vec!["a.srt", "c.srt"], "the survivors keep their order");
384+ assert_eq!(
385+ names,
386+ vec!["a.srt", "c.srt"],
387+ "the survivors keep their order"
388+ );
382389 assert_eq!(session.subtitles()[0].cues, expected(), "and their cues");
383390
384391 let project = dir.join("cut.edith");
@@ -397,7 +404,12 @@ fn a_subtitle_row_can_be_removed_and_the_survivors_round_trip() {
397404 assert_eq!(
398405 back.subtitles()
399406 .iter()
400- .map(|t| t.path.file_name().expect("a name").to_string_lossy().into_owned())
407+ .map(|t| t
408+ .path
409+ .file_name()
410+ .expect("a name")
411+ .to_string_lossy()
412+ .into_owned())
401413 .collect::<Vec<_>>(),
402414 vec!["a.srt", "c.srt"],
403415 "and a load is the same two, in the same order"
@@ -435,7 +447,9 @@ fn subtitles_come_off_another_file_without_it_joining_the_timeline() {
435447 // A different file entirely, carrying two subtitle tracks.
436448 let other = asset("test_subs.mkv");
437449 assert_eq!(
438- session.import_subtitles(&other).expect("its subtitles come"),
450+ session
451+ .import_subtitles(&other)
452+ .expect("its subtitles come"),
439453 2
440454 );
441455 assert_eq!(session.subtitles().len(), 2);
@@ -445,13 +459,21 @@ fn subtitles_come_off_another_file_without_it_joining_the_timeline() {
445459 }
446460 // ...and the timeline is exactly the timeline it was.
447461 assert_eq!(
448- session.sources().iter().map(|s| s.path.clone()).collect::<Vec<_>>(),
462+ session
463+ .sources()
464+ .iter()
465+ .map(|s| s.path.clone())
466+ .collect::<Vec<_>>(),
449467 sources,
450468 "the file whose subtitles these are did not join the library"
451469 );
452470 assert_eq!(session.lanes(), lanes, "no lane was added");
453471 assert_eq!(
454- session.lanes().iter().map(|&l| session.lane_clips(l).len()).collect::<Vec<_>>(),
472+ session
473+ .lanes()
474+ .iter()
475+ .map(|&l| session.lane_clips(l).len())
476+ .collect::<Vec<_>>(),
455477 clips,
456478 "and nothing was cut, moved or dropped on one"
457479 );
@@ -590,12 +612,19 @@ fn a_project_naming_many_tracks_of_one_file_walks_it_once_and_keeps_its_order()
590612 let opened = subtitle::open_all(&rows);
591613 let cost = read_bytes() - before;
592614 assert_eq!(
593- opened.iter().map(|t| (&t.path, t.track)).collect::<Vec<_>>(),
615+ opened
616+ .iter()
617+ .map(|t| (&t.path, t.track))
618+ .collect::<Vec<_>>(),
594619 rows.iter().map(|(p, n)| (p, *n)).collect::<Vec<_>>(),
595620 "every row comes back where it was saved"
596621 );
597622 assert_eq!(opened[1].label, "eng", "and it is that file's track 1");
598- assert_eq!(opened[2].cues, expected(), "the standalone row is untouched");
623+ assert_eq!(
624+ opened[2].cues,
625+ expected(),
626+ "the standalone row is untouched"
627+ );
599628 assert!(
600629 opened[5]
601630 .refused
@@ -798,7 +827,10 @@ fn a_caption_is_placed_trimmed_moved_and_undone_on_its_lane() {
798827 project.move_sub(lane, 0, s2, 300).expect("it changes lane");
799828 assert!(project.sub_lane(lane).is_empty(), "off the first row");
800829 assert_eq!(project.sub_lane(s2).len(), 1, "and onto the second");
801- assert!(project.undo() && project.undo(), "the move and the added lane");
830+ assert!(
831+ project.undo() && project.undo(),
832+ "the move and the added lane"
833+ );
802834
803835 // Every one of the four was one undo step, and the snapshots are the lane
804836 // list's own: subtitles joined the history without a history of their own.
@@ -843,10 +875,24 @@ fn a_caption_is_placed_trimmed_moved_and_undone_on_its_lane() {
843875 fn two_captions_may_not_cover_one_frame_and_the_refusal_says_which() {
844876 let (mut project, lane) = with_subtitle_lane();
845877 project
846- .place_sub(lane, 30, SubClip { frames: 60, ..whole(0) })
878+ .place_sub(
879+ lane,
880+ 30,
881+ SubClip {
882+ frames: 60,
883+ ..whole(0)
884+ },
885+ )
847886 .expect("the first goes down");
848887 let err = project
849- .place_sub(lane, 60, SubClip { frames: 60, ..whole(0) })
888+ .place_sub(
889+ lane,
890+ 60,
891+ SubClip {
892+ frames: 60,
893+ ..whole(0)
894+ },
895+ )
850896 .expect_err("the second lands inside it");
851897 assert!(
852898 err.to_string().contains("already covers [30, 90)"),
@@ -854,7 +900,14 @@ fn two_captions_may_not_cover_one_frame_and_the_refusal_says_which() {
854900 );
855901
856902 project
857- .place_sub(lane, 200, SubClip { frames: 60, ..whole(0) })
903+ .place_sub(
904+ lane,
905+ 200,
906+ SubClip {
907+ frames: 60,
908+ ..whole(0)
909+ },
910+ )
858911 .expect("clear of it, it goes down");
859912 let err = project
860913 .move_sub(lane, 0, lane, 150)
@@ -867,21 +920,50 @@ fn two_captions_may_not_cover_one_frame_and_the_refusal_says_which() {
867920 // Neither refusal moved anything, and neither cost a step: one undo takes
868921 // the *second placement* back, not a refusal.
869922 assert_eq!(
870- project.sub_lane(lane).iter().map(|s| s.start).collect::<Vec<_>>(),
923+ project
924+ .sub_lane(lane)
925+ .iter()
926+ .map(|s| s.start)
927+ .collect::<Vec<_>>(),
871928 [30, 200]
872929 );
873930 assert!(project.undo());
874931 assert_eq!(
875- project.sub_lane(lane).iter().map(|s| s.start).collect::<Vec<_>>(),
932+ project
933+ .sub_lane(lane)
934+ .iter()
935+ .map(|s| s.start)
936+ .collect::<Vec<_>>(),
876937 [30]
877938 );
878939
879940 // The other refusals of the door, each in its own words.
880941 for (lane, at, sub, want) in [
881942 (Lane::V1, 0, whole(0), "not a subtitle track"),
882- (Lane::new(LaneKind::Subtitle, 4), 0, whole(0), "there is no S5"),
883- (Lane::S1, 0, SubClip { frames: 0, ..whole(0) }, "is empty"),
884- (Lane::S1, 0, SubClip { track: 7, ..whole(0) }, "subtitle track 7 of 1"),
943+ (
944+ Lane::new(LaneKind::Subtitle, 4),
945+ 0,
946+ whole(0),
947+ "there is no S5",
948+ ),
949+ (
950+ Lane::S1,
951+ 0,
952+ SubClip {
953+ frames: 0,
954+ ..whole(0)
955+ },
956+ "is empty",
957+ ),
958+ (
959+ Lane::S1,
960+ 0,
961+ SubClip {
962+ track: 7,
963+ ..whole(0)
964+ },
965+ "subtitle track 7 of 1",
966+ ),
885967 ] {
886968 let err = project.place_sub(lane, at, sub).expect_err("refused");
887969 assert!(
@@ -941,7 +1023,11 @@ fn a_lane_maps_to_cues_clipped_to_the_window_and_shifted_onto_the_timeline() {
9411023 .collect::<Vec<_>>(),
9421024 [
9431025 (0, 500_000, "first line".to_string()),
944- (1_000_000, 2_000_000, "second line\nwith a break".to_string()),
1026+ (
1027+ 1_000_000,
1028+ 2_000_000,
1029+ "second line\nwith a break".to_string()
1030+ ),
9451031 ],
9461032 "both cues clipped to the window and shifted to the placement"
9471033 );
@@ -1003,25 +1089,60 @@ fn a_removed_palette_row_walks_the_placements_below_it_down() {
10031089
10041090 // The row above it comes off -- nothing plays it -- and the placement is
10051091 // walked down with the palette, so it still says the same words.
1006- project.remove_subtitles(0).expect("an unplaced row comes off");
1092+ project
1093+ .remove_subtitles(0)
1094+ .expect("an unplaced row comes off");
10071095 assert_eq!(
1008- project.subtitles().iter().map(|t| &*t.label).collect::<Vec<_>>(),
1096+ project
1097+ .subtitles()
1098+ .iter()
1099+ .map(|t| &*t.label)
1100+ .collect::<Vec<_>>(),
10091101 ["fra - Signs", "spa"],
10101102 "the survivors keep their order"
10111103 );
1012- assert_eq!(project.sub_lane(lane)[0].track, 0, "the placement moved down");
1104+ assert_eq!(
1105+ project.sub_lane(lane)[0].track,
1106+ 0,
1107+ "the placement moved down"
1108+ );
10131109 assert_eq!(
10141110 project.subtitles()[project.sub_lane(lane)[0].track].label,
10151111 "fra - Signs",
10161112 "and names the very track it named before"
10171113 );
10181114
1019- // The history went with it: its snapshots hold the indexes as they were
1020- // before the reindex, so an undo into one would put the placement back on a
1021- // track that is no longer there.
1115+ // The history went with it -- and it *can*, now that the entry carries the
1116+ // palette ([`Snapshot`]'s own `subtitles`, beside the lanes and the
1117+ // settings): the reindex is a step like any other, so an undo puts the row
1118+ // and the placement's own index back together and the same clip goes on
1119+ // naming the same words.
10221120 assert!(
1023- !project.undo(),
1024- "no step survives a reindex the snapshots do not know about"
1121+ project.undo(),
1122+ "a reindex the entry carries is a step; the history was thrown away instead"
1123+ );
1124+ assert_eq!(
1125+ project
1126+ .subtitles()
1127+ .iter()
1128+ .map(|t| &*t.label)
1129+ .collect::<Vec<_>>(),
1130+ ["eng", "fra - Signs", "spa"],
1131+ "the undo did not put the removed row back"
1132+ );
1133+ assert_eq!(
1134+ project.subtitles()[project.sub_lane(lane)[0].track].label,
1135+ "fra - Signs",
1136+ "and the placement names the very track it named before the removal"
1137+ );
1138+ // ...and the step again, which is where the rest of this test starts: the
1139+ // row off and the placement walked down with it (`undo` left it on the
1140+ // redo stack).
1141+ assert!(project.redo(), "the step is a step both ways");
1142+ assert_eq!(
1143+ project.sub_lane(lane)[0].track,
1144+ 0,
1145+ "the placement moved down again"
10251146 );
10261147
10271148 // ...and now that it *is* placed, the same row does not come off at all:
@@ -1045,7 +1166,14 @@ fn a_removed_palette_row_walks_the_placements_below_it_down() {
10451166 fn a_drag_that_changes_nothing_is_ok_and_costs_no_step() {
10461167 let (mut project, lane) = with_subtitle_lane();
10471168 project
1048- .place_sub(lane, 30, SubClip { frames: 60, ..whole(0) })
1169+ .place_sub(
1170+ lane,
1171+ 30,
1172+ SubClip {
1173+ frames: 60,
1174+ ..whole(0)
1175+ },
1176+ )
10491177 .expect("it goes down");
10501178 let placed = project.sub_lane(lane)[0];
10511179
@@ -1095,7 +1223,10 @@ fn a_caption_is_cut_and_rippled_with_the_picture_under_it() {
10951223 .expect("it goes down");
10961224
10971225 // The razor: halves that add up to the whole, in frames and in microseconds.
1098- assert!(project.split(30), "the cut lands on the picture and the words");
1226+ assert!(
1227+ project.split(30),
1228+ "the cut lands on the picture and the words"
1229+ );
10991230 assert_eq!(
11001231 project
11011232 .sub_lane(lane)
@@ -1107,14 +1238,21 @@ fn a_caption_is_cut_and_rippled_with_the_picture_under_it() {
11071238 // ...and its inverse puts the caption back exactly as it was.
11081239 assert!(project.regroup(30), "the halves rejoin");
11091240 assert_eq!(
1110- project.sub_lane(lane).iter().map(|s| (s.start, s.frames, s.in_us, s.out_us)).collect::<Vec<_>>(),
1241+ project
1242+ .sub_lane(lane)
1243+ .iter()
1244+ .map(|s| (s.start, s.frames, s.in_us, s.out_us))
1245+ .collect::<Vec<_>>(),
11111246 [(0, 60, 0, 2_000_000)]
11121247 );
11131248
11141249 // A rippling delete through the middle of it: the hole closes, what was
11151250 // inside it is gone from the words as well as from the picture, and the two
11161251 // halves keep exactly the seconds they kept frames for.
1117- assert!(project.ripple_delete(20, 20), "the hole closes on every lane");
1252+ assert!(
1253+ project.ripple_delete(20, 20),
1254+ "the hole closes on every lane"
1255+ );
11181256 assert_eq!(
11191257 project
11201258 .sub_lane(lane)
@@ -1234,7 +1372,10 @@ fn subtitle_lanes_and_their_captions_survive_a_save() {
12341372
12351373 let mut session = engine::PlaybackSession::open(&media).expect("open the fixture");
12361374 session.set_gain(0.0); // silent like the rest of the suites
1237- assert_eq!(session.import_subtitles(&subs).expect("the .srt imports"), 1);
1375+ assert_eq!(
1376+ session.import_subtitles(&subs).expect("the .srt imports"),
1377+ 1
1378+ );
12381379
12391380 let s1 = session.add_lane(LaneKind::Subtitle);
12401381 let s2 = session.add_lane(LaneKind::Subtitle);
@@ -1246,7 +1387,9 @@ fn subtitle_lanes_and_their_captions_survive_a_save() {
12461387 out_us: 1_500_000,
12471388 link: None,
12481389 };
1249- session.place_sub(s1, 10, caption).expect("a caption goes down");
1390+ session
1391+ .place_sub(s1, 10, caption)
1392+ .expect("a caption goes down");
12501393
12511394 let project = dir.join("cut.edith");
12521395 session.save_project(&project).expect("save");
@@ -1270,7 +1413,10 @@ fn subtitle_lanes_and_their_captions_survive_a_save() {
12701413 );
12711414 assert_eq!(
12721415 back.sub_lane(s1),
1273- [SubClip { start: 10, ..caption }],
1416+ [SubClip {
1417+ start: 10,
1418+ ..caption
1419+ }],
12741420 "and the caption is the very placement it was"
12751421 );
12761422 assert!(back.sub_lane(s2).is_empty(), "the empty one is still empty");
@@ -1374,7 +1520,10 @@ fn a_caption_naming_a_track_the_palette_does_not_have_is_refused() {
13741520 // ...and the load's own door says the same thing about the same file, by
13751521 // the lane rather than by the line: `from_parts` for words.
13761522 let (project, _lane) = with_subtitle_lane();
1377- let beyond = SubClip { track: 3, ..whole(0) };
1523+ let beyond = SubClip {
1524+ track: 3,
1525+ ..whole(0)
1526+ };
13781527 let refused = project
13791528 .clone()
13801529 .with_subs(vec![Vec::new(), Vec::new(), vec![beyond]])