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