forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

generators.rs123 lines, 5.2 KiBHistoryRawDownload
1//! Generators, colour labels and the clip switch on the window's side: the keys and menu rows
2//! exist and are wired, the label list names the palette, and the clip box wears the marks.
3
4use super::*;
5use crate::ui::menubar::{Entry, Title};
6use keymap::ActionId;
7
8const NEW: [ActionId; 5] = [
9 ActionId::NewSolid,
10 ActionId::NewGradient,
11 ActionId::NewCountdown,
12 ActionId::NewBars,
13 ActionId::NewAdjustment,
14];
15
16fn in_menu(title: Title, a: ActionId) -> bool {
17 fn walk(list: &[Entry], a: ActionId) -> bool {
18 list.iter().any(|e| match e {
19 Entry::Sub(_, inner) => walk(inner, a),
20 Entry::Act(x) | Entry::Switch(x) | Entry::Choice(x) => *x == a,
21 Entry::Rule => false,
22 })
23 }
24 walk(title.layout(), a)
25}
26
27#[test]
28fn file_new_offers_the_five_generators_and_the_clip_menu_has_label_and_enabled() {
29 for a in NEW {
30 assert!(in_menu(Title::File, a), "{a:?} is under File > New");
31 assert!(crate::menus::DOCK_ITEMS.contains(&a), "{a:?} is in the dock menu");
32 }
33 assert!(in_menu(Title::Clip, ActionId::ClipLabel));
34 assert!(in_menu(Title::Clip, ActionId::ClipEnabled));
35 assert!(MENU_ITEMS.contains(&ActionId::ClipLabel) && MENU_ITEMS.contains(&ActionId::ClipEnabled));
36}
37
38#[test]
39fn shift_e_switches_a_clip_and_the_rest_are_menu_only() {
40 let keymap = keymap::Keymap::defaults();
41 assert_eq!(keymap.display(ActionId::ClipEnabled), "Shift+E");
42 for a in NEW.into_iter().chain([ActionId::ClipLabel]) {
43 assert_eq!(keymap.display(a), "unbound", "{a:?}");
44 }
45}
46
47#[test]
48fn every_new_action_is_dispatched_and_marks_the_project_dirty() {
49 let act = src_text("player/actions.rs");
50 for a in NEW {
51 let name = format!("ActionId::{a:?}");
52 assert!(act.matches(&name).count() >= 2, "{name} is in the dirty list and the table");
53 }
54 assert!(act.contains("ActionId::ClipEnabled => self.toggle_clip_enabled(cx)"));
55 assert!(act.contains("ActionId::ClipLabel => self.open_label_list(cx)"));
56}
57
58#[test]
59fn a_new_generator_is_one_undo_step_on_a_lane_with_room() {
60 let src = src_text("player/generators.rs");
61 let at = src.find("fn new_generator").expect("new_generator");
62 let body = &src[at..];
63 assert!(body.contains("begin_batch") && body.contains("end_batch"), "one step for lane and clip");
64 assert!(body.contains("add_lane"), "a lane is added when none has room");
65 assert!(body.contains("reverse()"), "an adjustment layer looks from the top lane down");
66}
67
68#[test]
69fn the_label_list_names_the_palette_and_the_clip_box_wears_the_marks() {
70 let cards = src_text("player/cards.rs");
71 assert!(cards.contains("Pick::Label"));
72 assert_eq!(engine::project::LABEL_COUNT, 8);
73 assert_eq!(engine::project::label_name(1), Some("Violet"));
74 let clip = src_text("ui/bench_stance/clip.rs");
75 assert!(clip.contains("mark.label > 0") && clip.contains("mark.off"));
76 assert!(src_text("files.rs").contains("engine::generate::title"));
77}
78
79#[test]
80fn the_generator_card_is_mounted_in_the_clip_tab() {
81 let dock = src_text("ui/dock_stance.rs");
82 assert!(dock.contains("generator_card(room, cx)"));
83 let card = src_text("ui/cards/generator.rs");
84 assert!(card.contains("write_generator"));
85}
86
87/// Shift+E (and every other modified clip chord) must reach the keymap while a
88/// docked card such as Colour is open: the card reads bare keys and shift+arrow
89/// only.
90#[test]
91fn docked_card_leaves_modified_strokes_to_the_room() {
92 use crate::ui::stance::docked_card_ignores as ig;
93 assert!(ig("e", false, true, false), "shift+e");
94 assert!(ig("v", true, false, true), "ctrl+alt+v");
95 assert!(ig("delete", false, true, false), "shift+delete");
96 assert!(!ig("r", false, false, false), "bare r is the card's reset");
97 assert!(!ig("left", false, true, false), "shift+left is the eq card's");
98 assert!(!ig("escape", false, true, false));
99 let keymap = crate::keymap::Keymap::defaults();
100 assert_eq!(keymap.lookup("e", false, true, false), Some(ActionId::ClipEnabled));
101}
102
103/// Key routing rule: a docked card eats only the strokes it reads. Bare `s`
104/// (split), Space, and every other keymap letter reach the room while a card is
105/// open in the Clip tab; only a covering sheet or a menu blocks the keymap.
106#[test]
107fn docked_card_eats_only_the_keys_it_reads() {
108 let cards = src_text("player/cards.rs");
109 let at = cards.find("pub(crate) fn param_card_key").expect("param_card_key");
110 let end = cards[at..].find("export_moment_key(key, shift, cx)").expect("end");
111 let body = &cards[at..at + end];
112 // Every docked card's branch answers `false` for a key it does not read
113 // (eq, transform, silence, effects, mix, subtitle: `else { return false }`;
114 // colour and speed: `None => return false`).
115 assert!(body.matches("return false;").count() >= 6, "card branches report unread keys");
116 assert!(body.matches("None => return false").count() >= 2);
117 let stance = src_text("ui/stance.rs");
118 assert!(
119 stance.find("if this.docked_card_only()\n && this.context_menu.is_none()")
120 < stance.find("if this.card_open()\n || this.context_menu.is_some()"),
121 "a docked card hands unread keys to the keymap before the blanket modal guard"
122 );
123}