| 1 | |
| 2 | |
| 3 | |
| 4 | use super::*; |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | #[test] |
| 11 | fn toolbar_fits_the_smallest_window() { |
| 12 | let toolbar = src_text("ui/toolbar.rs"); |
| 13 | let row = &toolbar[toolbar.find("pub(crate) fn toolbar(").expect("the toolbar")..]; |
| 14 | |
| 15 | |
| 16 | |
| 17 | let buttons = row.matches("action_control(").count(); |
| 18 | assert!(buttons >= 11, "the row's buttons moved; this scan is blind"); |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | assert!( |
| 28 | row.contains("\"controls-more\""), |
| 29 | "nothing pinned beside the scrolling row: the tail is unreachable at 640 px" |
| 30 | ); |
| 31 | assert_eq!(row.matches("overflow_x_scroll").count(), 1); |
| 32 | assert!( |
| 33 | row.find("\"controls-more\"") > row.find("overflow_x_scroll"), |
| 34 | "the pinned door is inside the row it is meant to outlive" |
| 35 | ); |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | assert_eq!( |
| 41 | row.matches("\n .child(control(").count(), |
| 42 | 0, |
| 43 | "a toolbar button bypassing the availability oracle" |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | #[test] |
| 51 | fn no_colour_is_written_outside_the_theme() { |
| 52 | let source = ui_source(); |
| 53 | let stray: Vec<&str> = source |
| 54 | .lines() |
| 55 | .filter(|l| l.contains("rgb(0x") || l.contains("rgba(0x")) |
| 56 | .collect(); |
| 57 | assert!(stray.is_empty(), "colour written outside the theme: {stray:?}"); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | #[test] |
| 65 | fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() { |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | let floor = 360. * TIMELINE_SHARE; |
| 72 | assert!( |
| 73 | timeline_fixed_h(true) + LANE_H <= floor, |
| 74 | "{} px of chrome and a lane will not fit {floor} px", |
| 75 | timeline_fixed_h(true) |
| 76 | ); |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | let uniform = [LaneKind::Video, LaneKind::Audio]; |
| 84 | assert_eq!(lanes_h_mixed(&uniform), lanes_h(2)); |
| 85 | assert_eq!(lanes_shown_mixed(&uniform, LANE_H), 1); |
| 86 | let mixed = [LaneKind::Video, LaneKind::Audio, LaneKind::Subtitle]; |
| 87 | assert_eq!( |
| 88 | lanes_h_mixed(&mixed), |
| 89 | 2. * LANE_H + SUB_LANE_H + 2. * 8., |
| 90 | "a caption lane is not counted as a full LANE_H row" |
| 91 | ); |
| 92 | |
| 93 | |
| 94 | assert_eq!(lanes_shown_mixed(&mixed, lanes_h(2)), 2); |
| 95 | |
| 96 | |
| 97 | assert_eq!(lanes_shown_mixed(&mixed, lanes_h_mixed(&mixed)), 3); |
| 98 | assert_eq!(rows_below_mixed(&mixed, lanes_h_mixed(&mixed), 0.), 0); |
| 99 | assert_eq!(rows_below_mixed(&mixed, lanes_h(2), 0.), 1); |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | assert_eq!(px_below(120., 0.), 120.); |
| 105 | assert_eq!(px_below(120., -40.), 80.); |
| 106 | assert_eq!(px_below(120., -120.), 0.); |
| 107 | assert_eq!(px_below(0., 0.), 0.); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | #[test] |
| 115 | fn a_second_message_queues_behind_the_first_instead_of_erasing_it() { |
| 116 | let mut q = std::collections::VecDeque::new(); |
| 117 | push_notice(&mut q, "NOTHING ADDED — no video stream".into()); |
| 118 | push_notice(&mut q, "NOTHING ADDED — the file is not there".into()); |
| 119 | assert_eq!(q.len(), 2); |
| 120 | assert_eq!(q.front().map(|n: &gpui::SharedString| n.as_ref()), Some("NOTHING ADDED — no video stream")); |
| 121 | |
| 122 | |
| 123 | |
| 124 | push_notice(&mut q, "NOTHING ADDED — the file is not there".into()); |
| 125 | assert_eq!(q.len(), 2); |
| 126 | |
| 127 | |
| 128 | |
| 129 | for i in 0..NOTICES_MAX + 3 { |
| 130 | push_notice(&mut q, format!("SCAN FAILED: {i}").into()); |
| 131 | } |
| 132 | assert_eq!(q.len(), NOTICES_MAX); |
| 133 | assert_eq!(q.back().map(|n: &gpui::SharedString| n.as_ref()), Some("SCAN FAILED: 10")); |
| 134 | |
| 135 | |
| 136 | let front = q.pop_front(); |
| 137 | assert_ne!(front, q.front().cloned()); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | #[test] |
| 144 | fn an_export_outcome_jumps_the_queue() { |
| 145 | let mut q = std::collections::VecDeque::new(); |
| 146 | push_notice(&mut q, "PROXY READY for a.mp4 — Proxies on cuts on it".into()); |
| 147 | push_notice(&mut q, "SUBTITLES b.srt — 1 track(s) in the palette".into()); |
| 148 | push_notice(&mut q, format!("{EXPORT_DONE}out.mp4").into()); |
| 149 | assert_eq!(q.len(), 3); |
| 150 | assert_eq!( |
| 151 | q.front().map(|n: &gpui::SharedString| n.as_ref()), |
| 152 | Some(format!("{EXPORT_DONE}out.mp4")).as_deref(), |
| 153 | "the export's result must be the notice showing, not third in line" |
| 154 | ); |
| 155 | |
| 156 | |
| 157 | let mut q = std::collections::VecDeque::new(); |
| 158 | push_notice(&mut q, "PROXY READY for a.mp4 — Proxies on cuts on it".into()); |
| 159 | push_notice(&mut q, "EXPORT FAILED: disk full".into()); |
| 160 | assert_eq!( |
| 161 | q.front().map(|n: &gpui::SharedString| n.as_ref()), |
| 162 | Some("EXPORT FAILED: disk full") |
| 163 | ); |
| 164 | } |
| 165 | |
| 166 | |
| 167 | |
| 168 | #[test] |
| 169 | fn a_message_wears_the_colour_its_own_words_say() { |
| 170 | assert_eq!(notice_tone("SCAN FAILED: no audio"), STATUS_ERROR()); |
| 171 | assert_eq!(notice_tone(&format!("{EXPORT_DONE}out.mp4")), STATUS_SUCCESS()); |
| 172 | assert_eq!(notice_tone("NOTHING DETACHED — not grouped"), STATUS_WARNING()); |
| 173 | assert_eq!(notice_tone("SNAP ON"), ACCENT_PRIMARY()); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | #[test] |
| 181 | fn an_inspector_section_occludes_no_timeline() { |
| 182 | let inspector = src_text("ui/inspector.rs"); |
| 183 | |
| 184 | |
| 185 | |
| 186 | let render = source_from("impl Render for Player"); |
| 187 | for card in [ |
| 188 | "eq_card", "color_card", "speed_card", "silence_card", "mix_card", "subtitle_style_card", |
| 189 | ] { |
| 190 | assert!( |
| 191 | inspector.contains(&format!("self.{card}(")), |
| 192 | "{card} is not a section of the inspector" |
| 193 | ); |
| 194 | assert!( |
| 195 | !render.contains(&format!("self.{card}(")), |
| 196 | "{card} is drawn from the root again -- it is an overlay over the timeline" |
| 197 | ); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | |
| 202 | assert!( |
| 203 | inspector.contains(".relative()"), |
| 204 | "the inspector is not a positioning context: its cards would cover the window" |
| 205 | ); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | #[test] |
| 212 | fn a_stateful_button_keeps_its_rect() { |
| 213 | use crate::ui::toolbar::{EXPORT_SLOT_W, SNAP_SLOT_W, VOLUME_SLOT_W}; |
| 214 | |
| 215 | |
| 216 | let fits = |slot: f32, word: &str| slot >= word.chars().count() as f32 * 7. + 16.; |
| 217 | for word in ["Export", "Cancel"] { |
| 218 | assert!(fits(EXPORT_SLOT_W, word), "{word} overflows its rect"); |
| 219 | } |
| 220 | for word in ["Snap on", "Snap off", "No subs", "Subs off"] { |
| 221 | assert!(fits(SNAP_SLOT_W, word), "{word} overflows its rect"); |
| 222 | } |
| 223 | for word in ["100%", "× 100%"] { |
| 224 | assert!(fits(VOLUME_SLOT_W, word), "{word} overflows its rect"); |
| 225 | } |
| 226 | |
| 227 | |
| 228 | let toolbar = src_text("ui/toolbar.rs"); |
| 229 | for (id, slot) in [ |
| 230 | ("\"export\"", "EXPORT_SLOT_W"), |
| 231 | ("\"snap\"", "SNAP_SLOT_W"), |
| 232 | ("\"subs\"", "SNAP_SLOT_W"), |
| 233 | ("\"volume\"", "VOLUME_SLOT_W"), |
| 234 | ("\"zoom-fit\"", "ZOOM_SLOT_W"), |
| 235 | ] { |
| 236 | let at = toolbar.find(id).unwrap_or_else(|| panic!("no {id} button")); |
| 237 | assert!( |
| 238 | toolbar[at..at + 120].contains(slot), |
| 239 | "{id} does not reserve {slot}" |
| 240 | ); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | #[test] |
| 245 | fn nothing_clickable_is_smaller_than_the_wcag_minimum() { |
| 246 | |
| 247 | |
| 248 | assert!(CONTROL_H >= HIT_MIN); |
| 249 | assert!(RULER_HIT_H >= HIT_MIN); |
| 250 | assert!(LANE_H >= HIT_MIN); |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | assert!(SUB_LANE_H >= HIT_MIN); |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | assert!(!trims(0.)); |
| 262 | assert!(!trims(EDGE_W)); |
| 263 | assert!(!trims(2. * EDGE_W), "a box that is all handle and no clip"); |
| 264 | assert!(!trims(3. * EDGE_W - 0.1)); |
| 265 | |
| 266 | |
| 267 | for width in [3. * EDGE_W, 24., 100., 4000.] { |
| 268 | assert!(trims(width)); |
| 269 | assert!( |
| 270 | width - 2. * EDGE_W >= EDGE_W, |
| 271 | "{width} px of box leaves no middle" |
| 272 | ); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | #[test] |
| 277 | fn a_lane_row_is_a_fixed_header_and_a_bed_that_can_be_hit() { |
| 278 | |
| 279 | |
| 280 | assert!(HEADER_W > 0. && HEADER_GAP >= 0.); |
| 281 | |
| 282 | |
| 283 | assert!( |
| 284 | CONTROL_H + RULER_HIT_H + 2. * LANE_H + 17. + 4. * 8. + 16. <= PANEL_H, |
| 285 | "the second lane does not fit the panel" |
| 286 | ); |
| 287 | |
| 288 | |
| 289 | assert!(LANE_H >= HIT_MIN); |
| 290 | |
| 291 | assert!(LABEL_H < LANE_H / 2.); |
| 292 | |
| 293 | |
| 294 | assert_eq!(panel_h(2), PANEL_H); |
| 295 | assert_eq!(panel_h(1), PANEL_H); |
| 296 | assert_eq!(panel_h(3), PANEL_H + LANE_H + 8.); |
| 297 | assert_eq!( |
| 298 | panel_h(LANES_MAX), |
| 299 | PANEL_H + lanes_h(LANES_MAX) - lanes_h(2) |
| 300 | ); |
| 301 | |
| 302 | |
| 303 | assert_eq!(panel_h(LANES_MAX + 1), panel_h(LANES_MAX)); |
| 304 | assert_eq!(panel_h(50), panel_h(LANES_MAX)); |
| 305 | assert_eq!(lanes_h(0), 0.); |
| 306 | assert_eq!(lanes_h(1), LANE_H); |
| 307 | assert_eq!(lanes_h(2), 2. * LANE_H + 8.); |
| 308 | } |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | #[test] |
| 314 | fn the_scroll_thumb_is_the_visible_share_at_its_own_place() { |
| 315 | use crate::scroll_thumb; |
| 316 | use crate::SCROLL_THUMB_MIN; |
| 317 | |
| 318 | |
| 319 | assert_eq!(scroll_thumb(400., 10., 0., 12.), (0., 400.)); |
| 320 | assert_eq!(scroll_thumb(400., 0., 0., 0.), (0., 400.)); |
| 321 | |
| 322 | |
| 323 | assert_eq!(scroll_thumb(400., 20., 0., 10.), (0., 200.)); |
| 324 | assert_eq!(scroll_thumb(400., 20., 10., 10.), (200., 200.)); |
| 325 | |
| 326 | |
| 327 | let (x, w) = scroll_thumb(400., 1_000_000., 999_000., 100.); |
| 328 | assert_eq!(w, SCROLL_THUMB_MIN); |
| 329 | assert_eq!(x, 400. - SCROLL_THUMB_MIN); |
| 330 | assert_eq!(scroll_thumb(400., 1_000_000., 0., 100.).0, 0.); |
| 331 | } |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | #[test] |
| 341 | fn a_beside_thumb_press_jumps_by_the_tracks_own_proportion() { |
| 342 | use crate::scroll_thumb; |
| 343 | |
| 344 | let bed = 400.; |
| 345 | |
| 346 | |
| 347 | let jump = |at: f32, thumb_w: f32| (at - thumb_w / 2.).max(0.) / bed; |
| 348 | for (duration, span) in [(100_f32, 20_f32), (1_000_000_f32, 100_f32)] { |
| 349 | let (_, thumb_w) = scroll_thumb(bed, f64::from(duration), 0., f64::from(span)); |
| 350 | let at = 3. * bed / 4.; |
| 351 | let start = jump(at, thumb_w) * duration; |
| 352 | |
| 353 | |
| 354 | |
| 355 | let (x, w) = scroll_thumb(bed, f64::from(duration), f64::from(start), f64::from(span)); |
| 356 | let centre = (x + w / 2.).min(bed - w / 2.); |
| 357 | assert!( |
| 358 | (centre - at.min(bed - w / 2.)).abs() < 1., |
| 359 | "thumb centre {centre} not at the press {at}" |
| 360 | ); |
| 361 | |
| 362 | |
| 363 | let grab = thumb_w / 2.; |
| 364 | assert_eq!(jump(at, 2. * grab) * duration, start); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | #[test] |
| 374 | fn the_scroll_strip_row_comes_and_goes_with_the_zoom() { |
| 375 | use crate::{SCROLL_HIT, Split, lanes_h, split_size, timeline_fixed_h, timeline_h}; |
| 376 | use gpui::{px, size}; |
| 377 | |
| 378 | |
| 379 | |
| 380 | assert_eq!( |
| 381 | timeline_fixed_h(true) - timeline_fixed_h(false), |
| 382 | 8. + SCROLL_HIT |
| 383 | ); |
| 384 | let window = size(px(1280.), px(720.)); |
| 385 | for scroll in [false, true] { |
| 386 | |
| 387 | |
| 388 | |
| 389 | assert_eq!(timeline_h(2, scroll) - timeline_fixed_h(scroll), lanes_h(2)); |
| 390 | assert_eq!( |
| 391 | timeline_h(6, scroll) - timeline_fixed_h(scroll), |
| 392 | lanes_h(6) |
| 393 | ); |
| 394 | |
| 395 | |
| 396 | let floor = split_size(Split::Timeline, Some(0.), 2, window, scroll); |
| 397 | let box_h = floor - timeline_fixed_h(scroll); |
| 398 | assert!( |
| 399 | 2 > lanes_shown_mixed(&[LaneKind::Video, LaneKind::Audio], box_h), |
| 400 | "no line to pay for at the floor" |
| 401 | ); |
| 402 | assert!( |
| 403 | box_h - LABEL_H - 8. >= LANE_H, |
| 404 | "the floor leaves {} px for a {LANE_H} px lane", |
| 405 | box_h - LABEL_H - 8. |
| 406 | ); |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | assert_eq!(box_h, LANE_H + LABEL_H + 8.); |
| 414 | } |
| 415 | |
| 416 | |
| 417 | |
| 418 | assert!( |
| 419 | timeline_fixed_h(true) + LANE_H + LABEL_H + 8. <= 360. * TIMELINE_SHARE, |
| 420 | "the strip-bearing floor will not fit the share" |
| 421 | ); |
| 422 | } |
| 423 | |
| 424 | |
| 425 | |
| 426 | #[test] |
| 427 | fn the_lane_thumb_is_the_visible_share_of_the_stack() { |
| 428 | use crate::lanes_thumb; |
| 429 | use crate::SCROLL_THUMB_MIN; |
| 430 | |
| 431 | |
| 432 | assert_eq!(lanes_thumb(200., 104., 200., 0.), (0., 200.)); |
| 433 | assert_eq!(lanes_thumb(200., 0., 0., 0.), (0., 200.)); |
| 434 | |
| 435 | |
| 436 | assert_eq!(lanes_thumb(200., 400., 200., 100.), (50., 100.)); |
| 437 | assert_eq!(lanes_thumb(200., 400., 200., 0.), (0., 100.)); |
| 438 | |
| 439 | |
| 440 | let (y, h) = lanes_thumb(200., 2000., 200., 1800.); |
| 441 | assert_eq!(h, SCROLL_THUMB_MIN); |
| 442 | assert_eq!(y, 200. - SCROLL_THUMB_MIN); |
| 443 | assert_eq!(lanes_thumb(200., 2000., 200., 0.).0, 0.); |
| 444 | assert_eq!(lanes_thumb(200., 1_000_000., 200., 0.).0, 0.); |
| 445 | } |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | #[test] |
| 452 | fn a_caption_box_wears_the_rate_its_window_plays_at() { |
| 453 | use crate::caption_rate; |
| 454 | |
| 455 | let sub = |frames: u32, out_us: i64| SubClip { |
| 456 | start: 0, |
| 457 | frames, |
| 458 | track: 0, |
| 459 | in_us: 0, |
| 460 | out_us, |
| 461 | link: None, |
| 462 | }; |
| 463 | |
| 464 | assert_eq!(caption_rate(sub(300, 10_000_000), 30.), None); |
| 465 | assert_eq!( |
| 466 | caption_rate(sub(100, 3_333_333), 30.), |
| 467 | None, |
| 468 | "placement rounding is not a re-timing" |
| 469 | ); |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | assert_eq!( |
| 476 | caption_rate(sub(31, 1_016_667), 30.), |
| 477 | None, |
| 478 | "half a frame off a one-second window is still unity" |
| 479 | ); |
| 480 | assert_eq!( |
| 481 | caption_rate(sub(150, 5_015_000), 30.), |
| 482 | None, |
| 483 | "a hair under five seconds rounds to 150 frames and stays unity" |
| 484 | ); |
| 485 | |
| 486 | assert_eq!( |
| 487 | caption_rate(sub(150, 10_000_000), 30.).map(|s| s.permille()), |
| 488 | Some(2000) |
| 489 | ); |
| 490 | |
| 491 | |
| 492 | assert_eq!( |
| 493 | caption_rate(sub(600, 10_000_000), 30.).map(|s| s.permille()), |
| 494 | Some(500) |
| 495 | ); |
| 496 | } |
| 497 | |
| 498 | |
| 499 | |
| 500 | #[test] |
| 501 | fn a_selection_holds_its_picks_in_click_order_and_anchors_the_last() { |
| 502 | use crate::Selection; |
| 503 | |
| 504 | let mut sel = Selection::new(); |
| 505 | assert!(sel.is_empty()); |
| 506 | assert_eq!(sel.anchor(), None); |
| 507 | |
| 508 | let (v, a, cap) = ( |
| 509 | (Lane::V1, 0), |
| 510 | (Lane::A1, 1), |
| 511 | (Lane::new(LaneKind::Subtitle, 0), 0), |
| 512 | ); |
| 513 | sel.set_one(v); |
| 514 | assert_eq!(sel.len(), 1); |
| 515 | assert_eq!(sel.anchor(), Some(v)); |
| 516 | |
| 517 | |
| 518 | sel.toggle(a); |
| 519 | sel.toggle(cap); |
| 520 | assert_eq!(sel.picks(), &[v, a, cap]); |
| 521 | assert_eq!(sel.anchor(), Some(cap), "the last pick is the anchor"); |
| 522 | assert!(sel.contains(a)); |
| 523 | |
| 524 | |
| 525 | |
| 526 | sel.toggle(a); |
| 527 | assert_eq!(sel.picks(), &[v, cap]); |
| 528 | assert!(!sel.contains(a)); |
| 529 | |
| 530 | |
| 531 | |
| 532 | sel.set_one(a); |
| 533 | assert_eq!(sel.picks(), &[a]); |
| 534 | |
| 535 | |
| 536 | let mut all = Selection::new(); |
| 537 | all.add(v); |
| 538 | all.add(a); |
| 539 | all.add(v); |
| 540 | assert_eq!(all.picks(), &[v, a], "a pick is never held twice"); |
| 541 | |
| 542 | sel.clear(); |
| 543 | assert!(sel.is_empty()); |
| 544 | assert_eq!(sel.anchor(), None); |
| 545 | } |
| 546 | |
| 547 | #[test] |
| 548 | fn a_click_marks_the_whole_group_and_nothing_else() { |
| 549 | let (v, a) = ((Lane::V1, 0), (Lane::A1, 0)); |
| 550 | |
| 551 | |
| 552 | assert!(marked(v, Some(1), &[v], &[Some(1)])); |
| 553 | assert!(marked(a, Some(1), &[v], &[Some(1)])); |
| 554 | |
| 555 | assert!(!marked((Lane::V1, 1), Some(2), &[v], &[Some(1)])); |
| 556 | assert!(!marked((Lane::A1, 1), Some(2), &[v], &[Some(1)])); |
| 557 | |
| 558 | |
| 559 | |
| 560 | assert!(marked(a, None, &[a], &[None])); |
| 561 | assert!(!marked(v, None, &[a], &[None])); |
| 562 | |
| 563 | |
| 564 | let cap = (Lane::new(LaneKind::Subtitle, 0), 0); |
| 565 | assert!(marked(cap, Some(1), &[cap, v], &[None, Some(1)])); |
| 566 | assert!(marked(a, Some(1), &[cap, v], &[None, Some(1)])); |
| 567 | |
| 568 | assert!(!marked(v, Some(1), &[], &[])); |
| 569 | } |
| 570 | |
| 571 | #[test] |
| 572 | fn a_name_is_dropped_rather_than_smeared_across_a_thin_clip() { |
| 573 | assert!(show_label(LABEL_MIN_W)); |
| 574 | assert!(show_label(400.)); |
| 575 | assert!(!show_label(LABEL_MIN_W - 0.1)); |
| 576 | |
| 577 | |
| 578 | let scale = Scale::default(); |
| 579 | assert!(show_label(scale.width_px(LABEL_MIN_W as f64 / PPS_DEFAULT))); |
| 580 | assert!(!show_label(scale.width_px(0.))); |
| 581 | } |
| 582 | |
| 583 | #[test] |
| 584 | fn an_envelope_stays_inside_the_box_it_is_drawn_in() { |
| 585 | |
| 586 | let peaks: Vec<(f32, f32)> = (0..40) |
| 587 | .map(|i| (-(i as f32) / 39., i as f32 / 39.)) |
| 588 | .collect(); |
| 589 | let (w, h) = (100., 30.); |
| 590 | let cols = envelope(&peaks, 0., 1., w, h); |
| 591 | assert_eq!(cols.len(), (w / WAVE_COL) as usize + 1); |
| 592 | for &(x, top, bottom) in &cols { |
| 593 | assert!((0. ..=w).contains(&x), "x {x} outside 0..{w}"); |
| 594 | assert!((0. ..=h).contains(&top), "top {top} outside 0..{h}"); |
| 595 | assert!( |
| 596 | (0. ..=h).contains(&bottom), |
| 597 | "bottom {bottom} outside 0..{h}" |
| 598 | ); |
| 599 | |
| 600 | |
| 601 | assert!( |
| 602 | bottom - top >= 1., |
| 603 | "column {top}..{bottom} is thinner than a pixel" |
| 604 | ); |
| 605 | } |
| 606 | |
| 607 | let height = |&(_, top, bottom): &(f32, f32, f32)| bottom - top; |
| 608 | assert!(height(cols.last().unwrap()) > height(cols.first().unwrap()) + 5.); |
| 609 | |
| 610 | assert!(envelope(&[], 0., 1., w, h).is_empty()); |
| 611 | assert!(envelope(&peaks, 0., 1., 0., h).is_empty()); |
| 612 | |
| 613 | assert!(!envelope(&peaks, 0., 99., w, h).is_empty()); |
| 614 | } |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | #[test] |
| 623 | fn an_envelope_never_costs_more_points_than_a_screen_can_show() { |
| 624 | let peaks: Vec<(f32, f32)> = (0..200).map(|i| (-(i as f32) / 199., 1.)).collect(); |
| 625 | |
| 626 | let huge = 5. * 30. / 8. * 1200.; |
| 627 | let cols = envelope(&peaks, 0., 5., huge, 30.); |
| 628 | assert!( |
| 629 | cols.len() <= WAVE_COLS_MAX + 1, |
| 630 | "{} columns for a {huge} px box", |
| 631 | cols.len() |
| 632 | ); |
| 633 | |
| 634 | |
| 635 | |
| 636 | let (x, w) = visible_slice(-huge / 2., huge, 1200.); |
| 637 | assert_eq!((x, w), (huge / 2., 1200.)); |
| 638 | assert_eq!(envelope(&peaks, 0., 5., w, 30.).len(), 601); |
| 639 | |
| 640 | |
| 641 | assert_eq!(visible_slice(2000., 500., 1200.), (0., 0.)); |
| 642 | assert_eq!(visible_slice(-3000., 500., 1200.), (500., 0.)); |
| 643 | assert_eq!(visible_slice(-40., 500., 0.), (0., 500.)); |
| 644 | |
| 645 | assert_eq!(visible_slice(-100., 500., 1200.), (100., 400.)); |
| 646 | assert_eq!(visible_slice(1000., 500., 1200.), (0., 200.)); |
| 647 | } |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | #[test] |
| 654 | fn a_trim_preview_lands_where_the_release_commits() { |
| 655 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 656 | session.set_gain(0.0); |
| 657 | for permille in SPEED_PRESETS { |
| 658 | |
| 659 | |
| 660 | session |
| 661 | .set_speed_live(Lane::V1, 0, Speed::from_permille(permille)) |
| 662 | .expect("a clip alone on its lane may be speeded"); |
| 663 | for edge in [Edge::Start, Edge::End] { |
| 664 | let clip = session.lane_clips(Lane::V1)[0]; |
| 665 | let (lo, hi) = session |
| 666 | .trim_room(Lane::V1, 0, edge) |
| 667 | .expect("clip 0 is there"); |
| 668 | |
| 669 | |
| 670 | for to in [lo, (lo + hi) / 2, hi] { |
| 671 | let preview = trimmed_clip(clip, edge, to, false); |
| 672 | |
| 673 | |
| 674 | if session.trim_clip(Lane::V1, 0, edge, to) { |
| 675 | assert_eq!( |
| 676 | preview, |
| 677 | session.lane_clips(Lane::V1)[0], |
| 678 | "{edge:?} to {to} at {permille} per mille" |
| 679 | ); |
| 680 | assert!(session.undo(), "the trim is one undo step"); |
| 681 | } else { |
| 682 | |
| 683 | |
| 684 | assert_eq!(preview, clip, "{edge:?} to {to} at {permille} per mille"); |
| 685 | } |
| 686 | assert_eq!(session.lane_clips(Lane::V1)[0], clip, "back where it was"); |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | #[test] |
| 698 | fn a_caption_trim_preview_lands_where_the_release_commits() { |
| 699 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 700 | session.set_gain(0.0); |
| 701 | let fps = session.meta().frame_rate; |
| 702 | let srt = Path::new(env!("CARGO_MANIFEST_DIR")) |
| 703 | .join("../engine/tests/data/test_subs.srt") |
| 704 | .canonicalize() |
| 705 | .expect("the subtitle fixture"); |
| 706 | session.import_subtitles(&srt).expect("the .srt imports"); |
| 707 | let lane = session.add_lane(LaneKind::Subtitle); |
| 708 | |
| 709 | |
| 710 | let out_us = session.subtitles()[0] |
| 711 | .cues |
| 712 | .iter() |
| 713 | .map(|c| c.end_us) |
| 714 | .max() |
| 715 | .expect("the fixture has cues"); |
| 716 | let whole = SubClip { |
| 717 | start: 0, |
| 718 | frames: frames_of_us(out_us, fps), |
| 719 | track: 0, |
| 720 | in_us: 0, |
| 721 | out_us, |
| 722 | link: None, |
| 723 | }; |
| 724 | session |
| 725 | .place_sub(lane, 30, whole) |
| 726 | .expect("an empty subtitle lane takes it"); |
| 727 | assert_eq!( |
| 728 | session.sub_lane(lane)[0].start, |
| 729 | 30, |
| 730 | "the frame the hand let go on wins over the placement's own start" |
| 731 | ); |
| 732 | for edge in [Edge::Start, Edge::End] { |
| 733 | let (lo, hi) = session |
| 734 | .trim_sub_room(lane, 0, edge) |
| 735 | .expect("placement 0 is there"); |
| 736 | for to in [lo, (lo + hi) / 2, hi] { |
| 737 | let placed = session.sub_lane(lane)[0]; |
| 738 | let preview = trimmed_sub(placed, edge, to); |
| 739 | session |
| 740 | .trim_sub(lane, 0, edge, to) |
| 741 | .expect("an edge inside its own room is never refused"); |
| 742 | let now = session.sub_lane(lane)[0]; |
| 743 | assert_eq!( |
| 744 | (preview.start, preview.frames), |
| 745 | (now.start, now.frames), |
| 746 | "{edge:?} to {to}" |
| 747 | ); |
| 748 | |
| 749 | |
| 750 | if (now.start, now.frames) != (placed.start, placed.frames) { |
| 751 | assert!(session.undo(), "the trim is one undo step"); |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | let before = session.sub_lane(lane)[0]; |
| 757 | session |
| 758 | .move_sub(lane, 0, lane, before.start) |
| 759 | .expect("a drop that changes nothing is not a refusal"); |
| 760 | assert_eq!(session.sub_lane(lane)[0], before); |
| 761 | |
| 762 | |
| 763 | let over = session |
| 764 | .place_sub(lane, before.start, whole) |
| 765 | .expect_err("two captions may not cover one frame"); |
| 766 | assert!(over.to_string().contains("already covers"), "{over}"); |
| 767 | } |
| 768 | |
| 769 | |
| 770 | |
| 771 | |
| 772 | #[test] |
| 773 | fn a_stills_trim_preview_grows_forward_like_the_commit() { |
| 774 | let mut session = PlaybackSession::open(asset("test_still.png")).expect("a picture opens"); |
| 775 | for edge in [Edge::Start, Edge::End] { |
| 776 | let clip = session.lane_clips(Lane::V1)[0]; |
| 777 | let (lo, hi) = session |
| 778 | .trim_room(Lane::V1, 0, edge) |
| 779 | .expect("clip 0 is there"); |
| 780 | for to in [lo, (lo + hi) / 2, hi] { |
| 781 | let preview = trimmed_clip(clip, edge, to, true); |
| 782 | match session.trim_clip(Lane::V1, 0, edge, to) { |
| 783 | true => { |
| 784 | assert_eq!( |
| 785 | preview, |
| 786 | session.lane_clips(Lane::V1)[0], |
| 787 | "a still {edge:?} to {to}" |
| 788 | ); |
| 789 | assert!(session.undo(), "the trim is one undo step"); |
| 790 | } |
| 791 | false => assert_eq!(preview, clip, "a still {edge:?} to {to}"), |
| 792 | } |
| 793 | assert_eq!(session.lane_clips(Lane::V1)[0], clip, "back where it was"); |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | #[test] |
| 802 | fn a_drop_moves_the_clip_that_was_picked_up_not_its_old_index() { |
| 803 | let at = |start: u32| Clip { |
| 804 | fade_in: 0, |
| 805 | fade_out: 0, |
| 806 | transition_out: 0, |
| 807 | start, |
| 808 | in_frame: 0, |
| 809 | out_frame: 30, |
| 810 | source: 0, |
| 811 | link: None, |
| 812 | eq: None, |
| 813 | color: None, |
| 814 | transform: None, |
| 815 | fit: FitPolicy::Fit, |
| 816 | speed: Speed::NORMAL, |
| 817 | }; |
| 818 | let lane = [at(0), at(30), at(60)]; |
| 819 | let dragged = lane[2]; |
| 820 | assert_eq!(live_idx(&lane, 2, dragged), Some(2), "nothing moved"); |
| 821 | |
| 822 | |
| 823 | let after = [at(0), at(60)]; |
| 824 | assert_eq!(live_idx(&after, 2, dragged), Some(1)); |
| 825 | assert_eq!(live_idx(&after, 1, dragged), Some(1)); |
| 826 | |
| 827 | |
| 828 | assert_eq!(live_idx(&[at(0)], 2, dragged), None); |
| 829 | assert_eq!(live_idx(&[], 0, dragged), None); |
| 830 | } |
| 831 | |
| 832 | #[test] |
| 833 | fn a_quiet_source_still_draws_as_a_shape() { |
| 834 | |
| 835 | let quiet: Vec<(f32, f32)> = vec![(-0.125, 0.125), (-0.0625, 0.0625)]; |
| 836 | let loud = normalise(quiet.clone()); |
| 837 | assert_eq!(loud[0], (-1., 1.)); |
| 838 | assert_eq!(loud[1], (-0.5, 0.5)); |
| 839 | |
| 840 | |
| 841 | assert_eq!(normalise(vec![(0., 0.)]), vec![(0., 0.)]); |
| 842 | assert!(normalise(Vec::new()).is_empty()); |
| 843 | } |
| 844 | |
| 845 | |
| 846 | |
| 847 | #[test] |
| 848 | fn the_fixtures_waveform_reaches_the_lane_as_a_shape() { |
| 849 | let asset = |name: &str| { |
| 850 | std::path::Path::new(env!("CARGO_MANIFEST_DIR")) |
| 851 | .join("../../assets") |
| 852 | .join(name) |
| 853 | }; |
| 854 | let peaks = normalise( |
| 855 | engine::waveform::peaks(asset("test_av.mp4"), 0, WAVE_BPS) |
| 856 | .expect("open the fixture") |
| 857 | .expect("test_av.mp4 has audio"), |
| 858 | ); |
| 859 | |
| 860 | assert!(peaks.len().abs_diff(5 * WAVE_BPS as usize) <= WAVE_BPS as usize); |
| 861 | let cols = envelope(&peaks, 0., 5., 600., 30.); |
| 862 | let height = |&(_, top, bottom): &(f32, f32, f32)| bottom - top; |
| 863 | let tallest = cols.iter().map(height).fold(0., f32::max); |
| 864 | let flattest = cols.iter().map(height).fold(f32::MAX, f32::min); |
| 865 | |
| 866 | |
| 867 | assert!(tallest > 25., "loudest column only {tallest} px of 30"); |
| 868 | assert!( |
| 869 | flattest < 8., |
| 870 | "quietest column {flattest} px -- no dips drawn" |
| 871 | ); |
| 872 | |
| 873 | assert!( |
| 874 | engine::waveform::peaks(asset("test_baseline.mp4"), 0, WAVE_BPS) |
| 875 | .expect("open the fixture") |
| 876 | .is_none() |
| 877 | ); |
| 878 | } |
| 879 | |
| 880 | #[test] |
| 881 | fn every_mark_on_a_clip_is_legible_on_it() { |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | for id in crate::ui::theme::PaletteId::ALL { |
| 888 | let p = id.palette(); |
| 889 | for (i, tint) in [p.CLIP_VIDEO, p.CLIP_AUDIO, p.CLIP_IMAGE, p.CLIP_TEXT] |
| 890 | .iter() |
| 891 | .enumerate() |
| 892 | { |
| 893 | |
| 894 | assert!( |
| 895 | contrast(p.FG_PRIMARY, *tint) >= 4.5, |
| 896 | "{id:?} source {i}: label contrast {:.2}", |
| 897 | contrast(p.FG_PRIMARY, *tint) |
| 898 | ); |
| 899 | |
| 900 | assert!( |
| 901 | contrast(p.FG_SECONDARY, *tint) >= 3., |
| 902 | "{id:?} source {i}: waveform contrast {:.2}", |
| 903 | contrast(p.FG_SECONDARY, *tint) |
| 904 | ); |
| 905 | } |
| 906 | |
| 907 | assert!(contrast(p.FG_PRIMARY, p.BG_SELECTED) >= 4.5, "{id:?}"); |
| 908 | assert!(contrast(p.FG_SECONDARY, p.BG_SELECTED) >= 3., "{id:?}"); |
| 909 | |
| 910 | |
| 911 | |
| 912 | assert!(contrast(p.CLIP_VIDEO, p.BG_TIMELINE) >= 1.5, "{id:?}"); |
| 913 | assert!(contrast(p.ACCENT_PLAYHEAD, p.BG_TIMELINE) >= 3., "{id:?}"); |
| 914 | assert!(contrast(p.ACCENT_PLAYHEAD, p.CLIP_VIDEO) >= 3., "{id:?}"); |
| 915 | } |
| 916 | |
| 917 | assert!((contrast(0xffffff, 0x000000) - 21.).abs() < 0.01); |
| 918 | } |
| 919 | |
| 920 | #[test] |
| 921 | fn source_tints_differ_per_source_and_cycle() { |
| 922 | |
| 923 | |
| 924 | |
| 925 | assert_ne!(source_tint(0), BG_RAISED()); |
| 926 | |
| 927 | |
| 928 | |
| 929 | for id in crate::ui::theme::PaletteId::ALL { |
| 930 | let p = id.palette(); |
| 931 | for (i, &tint) in p.SOURCE_TINTS.iter().enumerate() { |
| 932 | assert_ne!(tint, p.BG_RAISED, "{id:?} tint {i} is the panel"); |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | assert_ne!(source_tint(0), source_tint(1)); |
| 937 | assert_ne!(source_tint(1), source_tint(2)); |
| 938 | assert_ne!(source_tint(2), source_tint(3)); |
| 939 | |
| 940 | assert_eq!(source_tint(4), source_tint(0)); |
| 941 | assert_eq!(source_tint(9), source_tint(1)); |
| 942 | assert_eq!(source_tint(usize::MAX), SOURCE_TINTS()[usize::MAX % 4]); |
| 943 | } |
| 944 | |
| 945 | |
| 946 | |
| 947 | |
| 948 | |
| 949 | #[test] |
| 950 | fn source_tints_are_all_discernible() { |
| 951 | |
| 952 | |
| 953 | let apart = |a: u32, b: u32| { |
| 954 | (0..3) |
| 955 | .map(|i| { |
| 956 | let shift = i * 8; |
| 957 | ((a >> shift) & 0xff).abs_diff((b >> shift) & 0xff) |
| 958 | }) |
| 959 | .sum::<u32>() |
| 960 | }; |
| 961 | |
| 962 | |
| 963 | |
| 964 | for id in crate::ui::theme::PaletteId::ALL { |
| 965 | let p = id.palette(); |
| 966 | for (i, &tint) in p.SOURCE_TINTS.iter().enumerate() { |
| 967 | assert!( |
| 968 | apart(tint, p.BG_RAISED) >= 16, |
| 969 | "{id:?} tint {i} is {} from the panel it sits on", |
| 970 | apart(tint, p.BG_RAISED) |
| 971 | ); |
| 972 | for (j, &other) in p.SOURCE_TINTS.iter().enumerate().skip(i + 1) { |
| 973 | assert!( |
| 974 | apart(tint, other) >= 16, |
| 975 | "{id:?} tints {i} and {j} are only {} apart", |
| 976 | apart(tint, other) |
| 977 | ); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | |
| 982 | |
| 983 | assert!(apart(p.SOURCE_TINTS[0], p.SOURCE_TINTS[1]) >= 32, "{id:?}"); |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | #[test] |
| 992 | fn a_standalone_subtitle_wears_no_file_tint() { |
| 993 | let sources = [ |
| 994 | Source { |
| 995 | path: PathBuf::from("/films/a.mkv"), |
| 996 | audio_stream: 0, |
| 997 | }, |
| 998 | Source { |
| 999 | path: PathBuf::from("/films/b.mp4"), |
| 1000 | audio_stream: 0, |
| 1001 | }, |
| 1002 | |
| 1003 | |
| 1004 | Source { |
| 1005 | path: PathBuf::from("/films/a.mkv"), |
| 1006 | audio_stream: 1, |
| 1007 | }, |
| 1008 | ]; |
| 1009 | assert_eq!( |
| 1010 | file_tint(&sources, Path::new("/films/a.mkv")), |
| 1011 | Some(source_tint(0)) |
| 1012 | ); |
| 1013 | assert_eq!( |
| 1014 | file_tint(&sources, Path::new("/films/b.mp4")), |
| 1015 | Some(source_tint(1)) |
| 1016 | ); |
| 1017 | assert_eq!(file_tint(&sources, Path::new("/subs/a.eng.srt")), None); |
| 1018 | assert_eq!(file_tint(&[], Path::new("/films/a.mkv")), None); |
| 1019 | |
| 1020 | |
| 1021 | let here = std::fs::canonicalize(".").expect("the crate directory"); |
| 1022 | let sources = [Source { |
| 1023 | path: here.join("Cargo.toml"), |
| 1024 | audio_stream: 0, |
| 1025 | }]; |
| 1026 | assert_eq!( |
| 1027 | file_tint(&sources, Path::new("Cargo.toml")), |
| 1028 | Some(source_tint(0)), |
| 1029 | "a relative spelling of the source file wears the source's colour" |
| 1030 | ); |
| 1031 | } |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | |
| 1037 | |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | #[test] |
| 1042 | fn the_card_names_the_subtitle_it_leaves_off_and_counts_them_when_it_cannot() { |
| 1043 | let film = "/films/An Episode 01.mkv"; |
| 1044 | let two = [ |
| 1045 | sub(film, Some(1), "[ASS]"), |
| 1046 | sub(film, Some(2), "[ASS] [FOR DUB]"), |
| 1047 | ]; |
| 1048 | |
| 1049 | |
| 1050 | let named = subtitle_plan("[ASS] → embedded".to_string(), &two, &[0]); |
| 1051 | assert_eq!(named, "[ASS] → embedded; [ASS] [FOR DUB] — in the palette, on no track"); |
| 1052 | assert!( |
| 1053 | named.chars().count() <= SUB_PLAN_CHARS, |
| 1054 | "two tracks fit the value box: {named}" |
| 1055 | ); |
| 1056 | |
| 1057 | |
| 1058 | let many: Vec<_> = (0..35) |
| 1059 | .map(|i| { |
| 1060 | let mut track = sub("/films/A Remux.mkv", Some(i), "eng — Subtitles"); |
| 1061 | track.bitmap = (22..31).contains(&i); |
| 1062 | track.refused = (i == 31).then(|| "VobSub is pictures".to_string()); |
| 1063 | track |
| 1064 | }) |
| 1065 | .collect(); |
| 1066 | |
| 1067 | |
| 1068 | let picks: Vec<usize> = (0..31usize).collect(); |
| 1069 | let counted = subtitle_plan("22 tracks → embedded (…)".to_string(), &many, &picks); |
| 1070 | assert_eq!( |
| 1071 | counted, |
| 1072 | "22 of 35 → embedded; 9 pictures; 1 unread; 3 in the palette, on no track" |
| 1073 | ); |
| 1074 | assert!( |
| 1075 | counted.chars().count() <= SUB_PLAN_CHARS, |
| 1076 | "thirty-five tracks still fit the value box: {counted}" |
| 1077 | ); |
| 1078 | |
| 1079 | assert_eq!(subtitle_plan("none".to_string(), &[], &[]), "none"); |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | |
| 1085 | let placed = "S1 [ASS] — past the last picture".to_string(); |
| 1086 | assert_eq!( |
| 1087 | subtitle_plan(placed.clone(), &two, &[]), |
| 1088 | "S1 [ASS] — past the last picture; [ASS] [FOR DUB] — in the palette, on no track" |
| 1089 | ); |
| 1090 | |
| 1091 | |
| 1092 | |
| 1093 | assert!(!subtitle_plan(placed, &two[..1], &[]).contains("in the palette")); |
| 1094 | } |
| 1095 | |
| 1096 | |
| 1097 | |
| 1098 | |
| 1099 | |
| 1100 | #[test] |
| 1101 | fn subtitle_rows_group_a_source_however_they_were_added() { |
| 1102 | let tracks = [ |
| 1103 | sub("/films/a.mkv", Some(1), "eng"), |
| 1104 | sub("/films/b.mkv", Some(1), "eng"), |
| 1105 | sub("/films/a.mkv", Some(2), "fre"), |
| 1106 | sub("/subs/late.srt", None, "late.srt"), |
| 1107 | sub("/films/b.mkv", Some(3), "ger"), |
| 1108 | ]; |
| 1109 | let groups = subtitle_rows(&tracks); |
| 1110 | assert_eq!( |
| 1111 | groups.iter().map(|g| g.name.as_str()).collect::<Vec<_>>(), |
| 1112 | ["a", "b", "late"], |
| 1113 | "one group per file, in the order the files first appear" |
| 1114 | ); |
| 1115 | assert_eq!( |
| 1116 | groups |
| 1117 | .iter() |
| 1118 | .map(|g| g.rows.iter().map(|r| r.label.as_str()).collect::<Vec<_>>()) |
| 1119 | .collect::<Vec<_>>(), |
| 1120 | [vec!["eng", "fre"], vec!["eng", "ger"], vec!["late.srt"]], |
| 1121 | "a file's tracks are contiguous and in add order" |
| 1122 | ); |
| 1123 | |
| 1124 | |
| 1125 | assert_eq!( |
| 1126 | groups |
| 1127 | .iter() |
| 1128 | .map(|g| g.rows.iter().map(|r| r.number).collect::<Vec<_>>()) |
| 1129 | .collect::<Vec<_>>(), |
| 1130 | [vec![1, 2], vec![1, 2], vec![1]] |
| 1131 | ); |
| 1132 | |
| 1133 | |
| 1134 | let sources = [Source { |
| 1135 | path: PathBuf::from("/films/a.mkv"), |
| 1136 | audio_stream: 0, |
| 1137 | }]; |
| 1138 | assert_eq!( |
| 1139 | file_tint(&sources, &groups[0].path), |
| 1140 | Some(source_tint(0)), |
| 1141 | "the group carries the path the tint is asked by" |
| 1142 | ); |
| 1143 | assert_eq!(file_tint(&sources, &groups[2].path), None); |
| 1144 | |
| 1145 | |
| 1146 | |
| 1147 | assert_eq!( |
| 1148 | groups.iter().map(|g| g.rows.len()).collect::<Vec<_>>(), |
| 1149 | [2, 2, 1] |
| 1150 | ); |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | assert_eq!(groups[2].name, "late"); |
| 1155 | assert_eq!(groups[2].path, PathBuf::from("/subs/late.srt")); |
| 1156 | } |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | |
| 1162 | |
| 1163 | #[test] |
| 1164 | fn a_groups_fold_key_survives_a_track_arriving_or_leaving_its_file() { |
| 1165 | let before = [ |
| 1166 | sub("/films/a.mkv", Some(1), "eng"), |
| 1167 | sub("/films/b.mkv", Some(1), "eng"), |
| 1168 | ]; |
| 1169 | let after_add = [ |
| 1170 | sub("/films/a.mkv", Some(1), "eng"), |
| 1171 | sub("/films/b.mkv", Some(1), "eng"), |
| 1172 | sub("/films/a.mkv", Some(2), "fre"), |
| 1173 | ]; |
| 1174 | let (before_groups, after_groups) = (subtitle_rows(&before), subtitle_rows(&after_add)); |
| 1175 | assert_eq!(before_groups[0].path, after_groups[0].path, "a's key held"); |
| 1176 | assert_eq!(before_groups[1].path, after_groups[1].path, "b's key held"); |
| 1177 | |
| 1178 | assert_eq!(after_groups[0].rows.len(), 2); |
| 1179 | assert_eq!(after_groups[1].rows.len(), 1); |
| 1180 | |
| 1181 | let after_remove = subtitle_rows(&before); |
| 1182 | assert_eq!(after_remove[0].path, before_groups[0].path); |
| 1183 | assert_eq!(after_remove[0].rows.len(), 1); |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | |
| 1188 | |
| 1189 | #[test] |
| 1190 | fn the_picked_subtitle_is_named_with_the_film_it_came_out_of() { |
| 1191 | let tracks = [ |
| 1192 | sub("/films/a.mkv", Some(1), "eng"), |
| 1193 | sub("/films/b.mkv", Some(1), "eng"), |
| 1194 | sub("/films/a.mkv", Some(2), "eng"), |
| 1195 | sub("/films/b.mkv", Some(2), "und"), |
| 1196 | sub("/subs/late.srt", None, "late.srt"), |
| 1197 | ]; |
| 1198 | let name = |track| sub_pick_name(&tracks, track).expect("a track that is there"); |
| 1199 | |
| 1200 | |
| 1201 | assert_eq!(name(0), "eng 1 — a"); |
| 1202 | assert_eq!(name(2), "eng 2 — a"); |
| 1203 | assert_eq!(name(1), "eng 1 — b"); |
| 1204 | assert_ne!(name(0), name(1), "two films' eng tracks read apart"); |
| 1205 | for picked in [name(0), name(1), name(2)] { |
| 1206 | assert!(picked.contains(" — a") || picked.contains(" — b")); |
| 1207 | } |
| 1208 | |
| 1209 | |
| 1210 | assert_eq!(name(3), "unknown language 2 — b"); |
| 1211 | |
| 1212 | |
| 1213 | assert_eq!(name(4), "late.srt"); |
| 1214 | |
| 1215 | assert_eq!(sub_pick_name(&tracks, 5), None); |
| 1216 | assert_eq!(sub_pick_name(&[], 0), None); |
| 1217 | } |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | |
| 1222 | |
| 1223 | #[test] |
| 1224 | fn the_subtitles_toggle_says_what_is_placed_and_never_the_picked_row() { |
| 1225 | for on in [true, false] { |
| 1226 | let text = subtitle_toggle_notice(on, 2); |
| 1227 | assert!(text.contains('2'), "{text} counts the captions placed"); |
| 1228 | assert!( |
| 1229 | !text.contains("track(s)") && !text.contains(" — a"), |
| 1230 | "{text} names no palette row" |
| 1231 | ); |
| 1232 | } |
| 1233 | |
| 1234 | assert!(subtitle_toggle_notice(false, 2).contains("still placed")); |
| 1235 | |
| 1236 | let none = subtitle_toggle_notice(true, 0); |
| 1237 | assert!(!none.contains('0'), "{none} counts nothing at nothing"); |
| 1238 | assert!(none.contains("drag"), "{none} says the next move"); |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | #[test] |
| 1250 | fn the_text_tab_carries_the_add_subtitles_door() { |
| 1251 | let library = src_text("ui/library.rs"); |
| 1252 | let at = library |
| 1253 | .find("\"add-subtitles\"") |
| 1254 | .expect("no add-subtitles control in the library column"); |
| 1255 | let block = &library[at..(at + 1600).min(library.len())]; |
| 1256 | assert!( |
| 1257 | block.contains("ActionId::ImportSubtitles"), |
| 1258 | "the button is a door of its own rather than the action: {block}" |
| 1259 | ); |
| 1260 | assert!( |
| 1261 | block.contains("pick_and_add_subtitles"), |
| 1262 | "the button does not open the subtitle chooser: {block}" |
| 1263 | ); |
| 1264 | |
| 1265 | |
| 1266 | assert!( |
| 1267 | library[..at].ends_with("self.action_control(\n "), |
| 1268 | "the add-subtitles button is not oracle-gated" |
| 1269 | ); |
| 1270 | |
| 1271 | |
| 1272 | assert!( |
| 1273 | crate::LibraryTab::Text.empty().contains("Add subtitles"), |
| 1274 | "{}", |
| 1275 | crate::LibraryTab::Text.empty() |
| 1276 | ); |
| 1277 | } |
| 1278 | |
| 1279 | |
| 1280 | |
| 1281 | |
| 1282 | |
| 1283 | |
| 1284 | |
| 1285 | |
| 1286 | #[test] |
| 1287 | fn a_subtitle_group_header_is_never_gated_on_window_height() { |
| 1288 | let timeline = src_text("ui/timeline.rs"); |
| 1289 | assert!( |
| 1290 | !timeline.contains("sub_headers_fit"), |
| 1291 | "the header is still gated on the viewport's height" |
| 1292 | ); |
| 1293 | let at = timeline |
| 1294 | .find("let headed = ") |
| 1295 | .expect("no `headed` computed in subtitle_section"); |
| 1296 | let line = &timeline[at..(at + 80).min(timeline.len())]; |
| 1297 | assert!( |
| 1298 | line.contains("several_files") && !line.contains("viewport"), |
| 1299 | "headed depends on something other than the file count: {line}" |
| 1300 | ); |
| 1301 | |
| 1302 | |
| 1303 | let head_at = timeline |
| 1304 | .find("subtitle-group-head") |
| 1305 | .expect("no id on the group header"); |
| 1306 | let block = &timeline[head_at..(head_at + 2400).min(timeline.len())]; |
| 1307 | assert!(block.contains("sub_folded.remove"), "no fold-open path: {block}"); |
| 1308 | assert!(block.contains("sub_folded.insert"), "no fold-shut path: {block}"); |
| 1309 | assert!( |
| 1310 | block.contains("\"1 track\"") || block.contains("tracks"), |
| 1311 | "the header does not say how many tracks it holds: {block}" |
| 1312 | ); |
| 1313 | } |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | |
| 1319 | |
| 1320 | #[test] |
| 1321 | fn a_subtitle_row_names_the_flat_track_it_was_made_from() { |
| 1322 | let mut tracks = vec![ |
| 1323 | sub("/films/a.mkv", Some(1), "eng"), |
| 1324 | sub("/films/b.mkv", Some(1), "eng"), |
| 1325 | sub("/films/a.mkv", Some(2), "fre"), |
| 1326 | ]; |
| 1327 | |
| 1328 | tracks[1].bitmap = true; |
| 1329 | tracks[1].refused = Some("PGS subtitles are pictures".to_string()); |
| 1330 | let groups = subtitle_rows(&tracks); |
| 1331 | let flat: Vec<(usize, &str)> = groups |
| 1332 | .iter() |
| 1333 | .flat_map(|g| g.rows.iter().map(|r| (r.track, r.label.as_str()))) |
| 1334 | .collect(); |
| 1335 | assert_eq!(flat, [(0, "eng"), (2, "fre"), (1, "eng")]); |
| 1336 | for (track, label) in flat { |
| 1337 | assert_eq!( |
| 1338 | tracks[track].label, label, |
| 1339 | "row {track} picks the track it names" |
| 1340 | ); |
| 1341 | } |
| 1342 | |
| 1343 | let refused = &groups[1].rows[0]; |
| 1344 | assert_eq!( |
| 1345 | refused.refused.as_deref(), |
| 1346 | Some("PGS subtitles are pictures") |
| 1347 | ); |
| 1348 | assert_eq!(refused.detail, "PGS subtitles are pictures"); |
| 1349 | assert!(refused.bitmap); |
| 1350 | |
| 1351 | assert_eq!(groups[0].rows[1].track, 2); |
| 1352 | } |
| 1353 | |
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | |
| 1358 | #[test] |
| 1359 | fn removing_a_subtitle_row_carries_the_pick_with_it() { |
| 1360 | |
| 1361 | assert_eq!(sub_pick_after_removal(2, 0, 2), 1); |
| 1362 | assert_eq!(sub_pick_after_removal(2, 1, 2), 1); |
| 1363 | |
| 1364 | assert_eq!(sub_pick_after_removal(0, 2, 2), 0); |
| 1365 | assert_eq!(sub_pick_after_removal(1, 2, 2), 1); |
| 1366 | |
| 1367 | assert_eq!(sub_pick_after_removal(1, 1, 2), 1); |
| 1368 | |
| 1369 | |
| 1370 | assert_eq!(sub_pick_after_removal(2, 2, 2), 1); |
| 1371 | |
| 1372 | |
| 1373 | assert_eq!(sub_pick_after_removal(0, 0, 0), 0); |
| 1374 | } |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | |
| 1379 | |
| 1380 | |
| 1381 | #[test] |
| 1382 | fn a_click_on_a_regrouped_row_picks_the_track_that_row_shows() { |
| 1383 | let tracks = [ |
| 1384 | sub("/films/a.mkv", Some(1), "eng"), |
| 1385 | sub("/films/b.mkv", Some(1), "eng"), |
| 1386 | sub("/films/a.mkv", Some(2), "fre"), |
| 1387 | sub("/subs/late.srt", None, "late.srt"), |
| 1388 | sub("/films/b.mkv", Some(3), "ger"), |
| 1389 | ]; |
| 1390 | let rows: Vec<_> = subtitle_rows(&tracks) |
| 1391 | .into_iter() |
| 1392 | .flat_map(|group| { |
| 1393 | group |
| 1394 | .rows |
| 1395 | .into_iter() |
| 1396 | .map(move |row| (group.path.clone(), row)) |
| 1397 | }) |
| 1398 | .collect(); |
| 1399 | |
| 1400 | assert_eq!( |
| 1401 | rows.iter().map(|(_, row)| row.track).collect::<Vec<_>>(), |
| 1402 | [0, 2, 1, 4, 3] |
| 1403 | ); |
| 1404 | for (path, row) in &rows { |
| 1405 | |
| 1406 | |
| 1407 | let picked = &tracks[row.track]; |
| 1408 | assert_eq!(&picked.path, path, "row {} picks another file", row.track); |
| 1409 | assert_eq!(lang_human(&picked.label), row.label); |
| 1410 | |
| 1411 | |
| 1412 | let echo = sub_pick_name(&tracks, row.track).expect("the row's own track"); |
| 1413 | let stem = path.file_stem().expect("a fixture path").to_string_lossy(); |
| 1414 | assert!( |
| 1415 | echo.contains(&*stem), |
| 1416 | "picked {}, echoed {echo}", |
| 1417 | path.display() |
| 1418 | ); |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | |
| 1423 | |
| 1424 | #[test] |
| 1425 | fn an_untagged_language_says_it_is_unknown() { |
| 1426 | assert_eq!(lang_human("und"), "unknown language"); |
| 1427 | assert_eq!(lang_human("eng"), "eng"); |
| 1428 | assert_eq!(lang_human("fre — Commentary"), "fre — Commentary"); |
| 1429 | |
| 1430 | let groups = subtitle_rows(&[sub("/films/a.mkv", Some(1), "und")]); |
| 1431 | assert_eq!(groups[0].rows[0].label, "unknown language"); |
| 1432 | |
| 1433 | |
| 1434 | |
| 1435 | |
| 1436 | let titled = |language: &str, name: &str, label: &str| engine::subtitle::SubtitleTrack { |
| 1437 | path: PathBuf::from("/films/a.mkv"), |
| 1438 | track: Some(1), |
| 1439 | language: language.into(), |
| 1440 | name: name.into(), |
| 1441 | label: label.into(), |
| 1442 | cues: Vec::new(), |
| 1443 | bitmap: false, |
| 1444 | refused: None, |
| 1445 | }; |
| 1446 | for (language, name, label, title) in [ |
| 1447 | ("fra", "Signs", "fra — Signs", "fra — Signs"), |
| 1448 | ("und", "Signs", "Signs", "Signs"), |
| 1449 | ("und", "", "und", "unknown language"), |
| 1450 | ("", "late.srt", "late.srt", "late.srt"), |
| 1451 | ("", "", "eng", "eng"), |
| 1452 | ] { |
| 1453 | let rows = subtitle_rows(&[titled(language, name, label)]); |
| 1454 | assert_eq!(rows[0].rows[0].label, title, "{language:?} {name:?}"); |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | |
| 1462 | |
| 1463 | |
| 1464 | |
| 1465 | |
| 1466 | |
| 1467 | |
| 1468 | #[test] |
| 1469 | fn an_empty_timeline_has_nothing_to_play() { |
| 1470 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 1471 | |
| 1472 | session.set_gain(0.0); |
| 1473 | |
| 1474 | |
| 1475 | assert!(!session.is_empty()); |
| 1476 | assert!(!nothing_to_play(Some(&session))); |
| 1477 | |
| 1478 | |
| 1479 | while session.delete_clip(Lane::V1, 0) {} |
| 1480 | while session.delete_clip(Lane::A1, 0) {} |
| 1481 | assert!(session.is_empty(), "the timeline is empty"); |
| 1482 | assert_eq!(session.timeline_duration(), 0.0); |
| 1483 | |
| 1484 | |
| 1485 | |
| 1486 | for _ in 0..40 { |
| 1487 | while session.try_frame().is_some() {} |
| 1488 | std::thread::sleep(Duration::from_millis(10)); |
| 1489 | } |
| 1490 | assert!( |
| 1491 | session.is_eos(), |
| 1492 | "an empty timeline is done before it starts" |
| 1493 | ); |
| 1494 | |
| 1495 | |
| 1496 | |
| 1497 | assert!(nothing_to_play(Some(&session))); |
| 1498 | assert!(nothing_to_play(None)); |
| 1499 | assert!(!session.is_playing(), "and nothing was started"); |
| 1500 | } |
| 1501 | |
| 1502 | |
| 1503 | |
| 1504 | #[test] |
| 1505 | fn the_slider_lands_on_the_grid_the_keys_move_on() { |
| 1506 | let mut volume = Volume::default(); |
| 1507 | |
| 1508 | volume.set_along(0.); |
| 1509 | assert_eq!(volume.gain(), 0.0); |
| 1510 | assert_eq!(volume.label(), "Vol 0%"); |
| 1511 | volume.set_along(1.5); |
| 1512 | assert_eq!(volume.gain(), 1.0); |
| 1513 | assert_eq!(volume.along(), 1.0); |
| 1514 | |
| 1515 | |
| 1516 | |
| 1517 | volume.set_along(0.5); |
| 1518 | assert_eq!(volume.label(), "Vol 50%"); |
| 1519 | volume.step(true); |
| 1520 | assert_eq!(volume.label(), "Vol 55%"); |
| 1521 | volume.step(false); |
| 1522 | assert_eq!(volume.gain(), 0.5); |
| 1523 | |
| 1524 | |
| 1525 | |
| 1526 | volume.set_along(0.333); |
| 1527 | assert_eq!(volume.label(), "Vol 33%"); |
| 1528 | assert_eq!(volume.along(), 0.33); |
| 1529 | |
| 1530 | |
| 1531 | volume.muted = true; |
| 1532 | volume.set_along(0.8); |
| 1533 | assert_eq!(volume.gain(), 0.0); |
| 1534 | assert_eq!(volume.label(), "Muted 80%"); |
| 1535 | volume.muted = false; |
| 1536 | assert_eq!(volume.gain(), 0.8); |
| 1537 | } |
| 1538 | |
| 1539 | |
| 1540 | |
| 1541 | |
| 1542 | #[test] |
| 1543 | fn the_volume_slider_lands_where_it_paints() { |
| 1544 | let bar = Bounds { |
| 1545 | origin: point(px(420.), px(508.)), |
| 1546 | size: size(px(VOLUME_W), px(CONTROL_H)), |
| 1547 | }; |
| 1548 | let at = |x: f32| { |
| 1549 | let mut volume = Volume::default(); |
| 1550 | volume.set_along(frac_along(px(x), bar)); |
| 1551 | volume |
| 1552 | }; |
| 1553 | assert_eq!(at(420.).gain(), 0.0, "the left end is silence"); |
| 1554 | assert_eq!(at(420. + VOLUME_W).gain(), 1.0, "the right end is full"); |
| 1555 | assert_eq!(at(-4000.).gain(), 0.0, "off the left clamps"); |
| 1556 | assert_eq!(at(9999.).gain(), 1.0, "off the right clamps"); |
| 1557 | |
| 1558 | |
| 1559 | for step in 0..=(VOLUME_W as u32) { |
| 1560 | let along = step as f32 / VOLUME_W; |
| 1561 | let volume = at(420. + along * VOLUME_W); |
| 1562 | let painted = volume.along(); |
| 1563 | let slack = 0.5 / f32::from(Volume::MAX_STEPS) + 1e-4; |
| 1564 | assert!( |
| 1565 | (painted - along).abs() <= slack, |
| 1566 | "pressed at {along}, paints at {painted}" |
| 1567 | ); |
| 1568 | } |
| 1569 | } |
| 1570 | |
| 1571 | |
| 1572 | |
| 1573 | |
| 1574 | |
| 1575 | #[test] |
| 1576 | fn a_dragged_divider_stops_before_either_panel_disappears() { |
| 1577 | use crate::ui::theme::INSPECTOR_MIN_W; |
| 1578 | use crate::{ |
| 1579 | SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, TOOLBAR_H, inspector_w, library_w, |
| 1580 | split_drag_size, split_size, timeline_fixed_h, timeline_h, |
| 1581 | }; |
| 1582 | use gpui::{point, px, size}; |
| 1583 | |
| 1584 | let window = size(px(1280.), px(720.)); |
| 1585 | |
| 1586 | |
| 1587 | |
| 1588 | |
| 1589 | assert_eq!(split_size(Split::Library, None, 2, window, false), library_w(1280.)); |
| 1590 | assert_eq!( |
| 1591 | split_size(Split::Inspector, None, 2, window, false), |
| 1592 | inspector_w(1280.) |
| 1593 | ); |
| 1594 | assert_eq!( |
| 1595 | split_size(Split::Timeline, None, 2, window, false), |
| 1596 | timeline_h(2, false).min(720. * TIMELINE_SHARE) |
| 1597 | ); |
| 1598 | assert_eq!( |
| 1599 | split_size(Split::Timeline, None, 2, window, true), |
| 1600 | timeline_h(2, true).min(720. * TIMELINE_SHARE) |
| 1601 | ); |
| 1602 | |
| 1603 | assert_eq!(split_size(Split::Library, Some(300.), 2, window, false), 300.); |
| 1604 | assert_eq!(split_size(Split::Timeline, Some(300.), 2, window, false), 300.); |
| 1605 | |
| 1606 | assert_eq!( |
| 1607 | split_size(Split::Library, Some(0.), 2, window, false), |
| 1608 | LIBRARY_MIN_W |
| 1609 | ); |
| 1610 | assert_eq!( |
| 1611 | split_size(Split::Library, Some(9000.), 2, window, false), |
| 1612 | 1280. * SIDE_MAX_FRAC |
| 1613 | ); |
| 1614 | assert_eq!( |
| 1615 | split_size(Split::Inspector, Some(-40.), 2, window, false), |
| 1616 | INSPECTOR_MIN_W |
| 1617 | ); |
| 1618 | |
| 1619 | |
| 1620 | |
| 1621 | |
| 1622 | |
| 1623 | |
| 1624 | |
| 1625 | let floor = split_size(Split::Timeline, Some(0.), 2, window, true); |
| 1626 | assert_eq!(floor, timeline_fixed_h(true) + LANE_H + LABEL_H + 8.); |
| 1627 | |
| 1628 | |
| 1629 | |
| 1630 | let lanes_box = floor - timeline_fixed_h(true); |
| 1631 | assert!( |
| 1632 | 2 > lanes_shown_mixed(&[LaneKind::Video, LaneKind::Audio], lanes_box), |
| 1633 | "no line to pay for at the floor" |
| 1634 | ); |
| 1635 | assert!( |
| 1636 | lanes_box - LABEL_H - 8. >= LANE_H, |
| 1637 | "the floor leaves {} px for a {LANE_H} px lane", |
| 1638 | lanes_box - LABEL_H - 8. |
| 1639 | ); |
| 1640 | |
| 1641 | |
| 1642 | assert_eq!( |
| 1643 | split_size(Split::Timeline, Some(0.), 1, window, true), |
| 1644 | timeline_fixed_h(true) + LANE_H |
| 1645 | ); |
| 1646 | |
| 1647 | |
| 1648 | assert_eq!(split_size(Split::Timeline, Some(126.), 2, window, true), floor); |
| 1649 | |
| 1650 | assert!(floor <= 360. * TIMELINE_SHARE, "{floor} px will not fit"); |
| 1651 | assert_eq!( |
| 1652 | split_size(Split::Timeline, Some(9000.), 2, window, true), |
| 1653 | 720. * TIMELINE_MAX_SHARE |
| 1654 | ); |
| 1655 | |
| 1656 | |
| 1657 | |
| 1658 | let narrow = size(px(600.), px(360.)); |
| 1659 | assert_eq!( |
| 1660 | split_size(Split::Inspector, Some(9000.), 2, narrow, false), |
| 1661 | INSPECTOR_MIN_W |
| 1662 | ); |
| 1663 | |
| 1664 | |
| 1665 | |
| 1666 | |
| 1667 | assert_eq!( |
| 1668 | split_drag_size(Split::Library, point(px(300.), px(400.)), window), |
| 1669 | 300. - SPLIT_W / 2. |
| 1670 | ); |
| 1671 | assert_eq!( |
| 1672 | split_drag_size(Split::Inspector, point(px(1000.), px(400.)), window), |
| 1673 | 280. - SPLIT_W / 2. |
| 1674 | ); |
| 1675 | |
| 1676 | |
| 1677 | assert_eq!( |
| 1678 | split_drag_size(Split::Timeline, point(px(300.), px(500.)), window), |
| 1679 | 220. - TOOLBAR_H - SPLIT_W / 2. |
| 1680 | ); |
| 1681 | } |
| 1682 | |
| 1683 | |
| 1684 | |
| 1685 | |
| 1686 | #[test] |
| 1687 | fn every_seam_in_the_layout_has_a_divider_on_it() { |
| 1688 | let render = src_text("render.rs"); |
| 1689 | for split in ["Split::Library", "Split::Inspector", "Split::Timeline"] { |
| 1690 | assert!( |
| 1691 | render.contains(&format!("divider({split}")), |
| 1692 | "{split} has no divider to drag" |
| 1693 | ); |
| 1694 | } |
| 1695 | |
| 1696 | |
| 1697 | let interact = src_text("interact.rs"); |
| 1698 | assert!( |
| 1699 | interact.contains("cursor_col_resize") && interact.contains("cursor_row_resize"), |
| 1700 | "a divider with no resize cursor on it" |
| 1701 | ); |
| 1702 | |
| 1703 | for (file, stale) in [ |
| 1704 | ("ui/inspector.rs", "inspector_w("), |
| 1705 | ("ui/toolbar.rs", "library_w("), |
| 1706 | ("render.rs", "library_w("), |
| 1707 | ] { |
| 1708 | assert!( |
| 1709 | !src_text(file).contains(stale), |
| 1710 | "{file} still measures a panel with {stale}" |
| 1711 | ); |
| 1712 | } |
| 1713 | } |