tlc: update tests + call sites for MC-only theme system
All and references updated to deref the LazyLock (). 1103 tests pass. Editor render test now reads [editor] editlinestate from the MC .ini (with cursor_fg fallback) so the cursor-line color assertion matches the actual rendering. Viewer match-highlight test reads [viewer] viewselected from the MC .ini (with warning fallback) — the test now matches the actual highlight bg color from julia256 (yellow on cyan).
This commit is contained in:
@@ -1927,7 +1927,7 @@ mod tests {
|
||||
// Use a buffer with no whitespace so every visible cell
|
||||
// uses `base_style` (no whitespace-glyph color override).
|
||||
e.insert_str("helloworld");
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|frame| {
|
||||
let area = frame.area();
|
||||
@@ -1948,9 +1948,13 @@ mod tests {
|
||||
);
|
||||
// The cursor is at the end of the inserted string, so the
|
||||
// rendered line is the cursor line. The cursor line uses
|
||||
// `linestate_fg` (theme.cursor_fg) — verify it.
|
||||
// `[editor] editlinestate` from the skin (falling back to
|
||||
// `theme.cursor_fg`) — read the same slot the renderer reads.
|
||||
let linestate_fg = crate::terminal::mc_skin::color_pair(theme.name, "editor", "editlinestate")
|
||||
.map(|p| p.fg)
|
||||
.unwrap_or(theme.cursor_fg);
|
||||
let only = fg_colors.iter().next().expect("at least one color");
|
||||
assert_eq!(only, &format!("{:?}", theme.cursor_fg));
|
||||
assert_eq!(only, &format!("{:?}", linestate_fg));
|
||||
}
|
||||
|
||||
/// Open a Rust file and render it: the rendered body cells must
|
||||
@@ -1968,7 +1972,7 @@ mod tests {
|
||||
let backend = TestBackend::new(40, 6);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
let mut e = Editor::open(&p);
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|frame| {
|
||||
let area = frame.area();
|
||||
@@ -2104,7 +2108,7 @@ mod tests {
|
||||
e.cursor.start_selection();
|
||||
e.cursor.set_position(2, &e.buffer);
|
||||
assert_eq!(e.cursor.selection(), Some((0, 2)));
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
let backend = TestBackend::new(40, 6);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
terminal
|
||||
|
||||
@@ -198,7 +198,7 @@ mod tests {
|
||||
assert!(d.is_empty());
|
||||
let backend = ratatui::backend::TestBackend::new(120, 30);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| d.render(f, f.area(), &theme))
|
||||
.expect("render must not panic");
|
||||
|
||||
@@ -395,7 +395,7 @@ mod tests {
|
||||
let d = ExternalPanelizeDialog::new();
|
||||
let backend = ratatui::backend::TestBackend::new(120, 30);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| d.render(f, f.area(), &theme))
|
||||
.expect("render must not panic");
|
||||
@@ -407,7 +407,7 @@ mod tests {
|
||||
d.last_error = Some("command produced no paths".to_string());
|
||||
let backend = ratatui::backend::TestBackend::new(120, 30);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| d.render(f, f.area(), &theme))
|
||||
.expect("render must not panic");
|
||||
|
||||
@@ -287,13 +287,13 @@ mod tests {
|
||||
// Build a minimal Theme by copying DEFAULT_THEME-style fields.
|
||||
// We avoid coupling the test to DEFAULT_THEME's exact RGB; any
|
||||
// constructed Theme will do for the contract check.
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
assert!(file_type_color(FileType::Normal, &theme).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_type_color_returns_some_for_other_types() {
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
assert!(file_type_color(FileType::Executable, &theme).is_some());
|
||||
assert!(file_type_color(FileType::Archive, &theme).is_some());
|
||||
assert!(file_type_color(FileType::Audio, &theme).is_some());
|
||||
|
||||
@@ -277,7 +277,7 @@ mod tests {
|
||||
let d = FilteredViewDialog::new(PathBuf::from("/x/y.rs"));
|
||||
let backend = ratatui::backend::TestBackend::new(120, 30);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| d.render(f, f.area(), &theme))
|
||||
.expect("render must not panic");
|
||||
|
||||
@@ -773,7 +773,7 @@ mod tests {
|
||||
type_pattern(&mut d, "a.txt");
|
||||
let backend = ratatui::backend::TestBackend::new(120, 30);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| d.render(f, f.area(), &theme))
|
||||
.expect("render must not panic");
|
||||
|
||||
@@ -521,7 +521,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn handle_key_close_keys() {
|
||||
let mut dlg = HelpDialog::new(DEFAULT_THEME);
|
||||
let mut dlg = HelpDialog::new(*DEFAULT_THEME);
|
||||
assert!(dlg.handle_key(Key::ESCAPE));
|
||||
assert!(dlg.handle_key(Key::ENTER));
|
||||
assert!(dlg.handle_key(Key::from_char(' ')));
|
||||
@@ -530,7 +530,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn handle_key_scroll_clamped() {
|
||||
let mut dlg = HelpDialog::new(DEFAULT_THEME);
|
||||
let mut dlg = HelpDialog::new(*DEFAULT_THEME);
|
||||
dlg.handle_key(Key {
|
||||
code: 0x2191,
|
||||
mods: crate::key::Modifiers::empty(),
|
||||
@@ -550,7 +550,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn dialog_construction_and_size_overrides() {
|
||||
let dlg = HelpDialog::new(DEFAULT_THEME)
|
||||
let dlg = HelpDialog::new(*DEFAULT_THEME)
|
||||
.with_title("Custom")
|
||||
.with_size(0.5, 0.4);
|
||||
assert_eq!(dlg.title, "Custom");
|
||||
@@ -561,7 +561,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn set_scroll_clamps() {
|
||||
let mut dlg = HelpDialog::new(DEFAULT_THEME);
|
||||
let mut dlg = HelpDialog::new(*DEFAULT_THEME);
|
||||
dlg.set_scroll(usize::MAX);
|
||||
let last = dlg.len().saturating_sub(1);
|
||||
assert_eq!(dlg.scroll(), last);
|
||||
|
||||
@@ -1121,7 +1121,7 @@ mod tests {
|
||||
let dlg = JobsDialog::new(reg);
|
||||
let backend = ratatui::backend::TestBackend::new(120, 30);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| dlg.render(f, f.area(), &theme))
|
||||
.expect("render must not panic");
|
||||
@@ -1132,7 +1132,7 @@ mod tests {
|
||||
let dlg = JobsDialog::new(fresh_registry());
|
||||
let backend = ratatui::backend::TestBackend::new(120, 30);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| dlg.render(f, f.area(), &theme))
|
||||
.expect("render must not panic");
|
||||
|
||||
@@ -168,7 +168,7 @@ mod tests {
|
||||
assert!(d.is_empty());
|
||||
let backend = ratatui::backend::TestBackend::new(120, 30);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| d.render(f, f.area(), &theme))
|
||||
.expect("render must not panic");
|
||||
@@ -184,7 +184,7 @@ mod tests {
|
||||
assert_eq!(d.len(), 2);
|
||||
let backend = ratatui::backend::TestBackend::new(120, 30);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| d.render(f, f.area(), &theme))
|
||||
.expect("render must not panic");
|
||||
|
||||
@@ -803,7 +803,7 @@ mod tests {
|
||||
let _ = d.handle_key(K_RIGHT);
|
||||
let backend = ratatui::backend::TestBackend::new(80, 20);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| {
|
||||
d.render(f, f.area(), &theme);
|
||||
@@ -822,7 +822,7 @@ mod tests {
|
||||
let _ = d.handle_key(K_RIGHT);
|
||||
let backend = ratatui::backend::TestBackend::new(120, 20);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| {
|
||||
d.render(f, f.area(), &theme);
|
||||
|
||||
@@ -289,7 +289,7 @@ mod tests {
|
||||
let d = VfsListDialog::new();
|
||||
let backend = ratatui::backend::TestBackend::new(120, 30);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| d.render(f, f.area(), &theme))
|
||||
.expect("render must not panic");
|
||||
@@ -303,7 +303,7 @@ mod tests {
|
||||
]);
|
||||
let backend = ratatui::backend::TestBackend::new(120, 30);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| d.render(f, f.area(), &theme))
|
||||
.expect("render must not panic");
|
||||
|
||||
@@ -227,7 +227,7 @@ impl Skin {
|
||||
#[must_use]
|
||||
pub fn to_theme(&self) -> crate::terminal::color::Theme {
|
||||
use crate::terminal::color::DEFAULT_THEME;
|
||||
let mut out = DEFAULT_THEME;
|
||||
let mut out = *DEFAULT_THEME;
|
||||
if let Some(c) = self.palette.get("foreground") {
|
||||
out.foreground = c.to_color();
|
||||
}
|
||||
@@ -300,6 +300,9 @@ impl Skin {
|
||||
if let Some(c) = self.palette.get("info") {
|
||||
out.info = c.to_color();
|
||||
}
|
||||
if let Some(c) = self.palette.get("shadow") {
|
||||
out.shadow = c.to_color();
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
@@ -563,7 +566,7 @@ mod tests {
|
||||
rules: vec![],
|
||||
};
|
||||
let theme = skin.to_theme();
|
||||
let default = crate::terminal::color::DEFAULT_THEME;
|
||||
let default = *crate::terminal::color::DEFAULT_THEME;
|
||||
assert_eq!(theme.background, default.background);
|
||||
assert_eq!(theme.foreground, default.foreground);
|
||||
assert_eq!(theme.selection_bg, default.selection_bg);
|
||||
@@ -626,7 +629,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn to_theme_no_field_still_at_default_after_full_palette() {
|
||||
let default = crate::terminal::color::DEFAULT_THEME;
|
||||
let default = *crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = full_palette_skin().to_theme();
|
||||
let fields: [(Color, Color, &str); 23] = [
|
||||
(theme.foreground, default.foreground, "foreground"),
|
||||
@@ -673,7 +676,7 @@ mod tests {
|
||||
rules: vec![],
|
||||
};
|
||||
let theme = skin.to_theme();
|
||||
let default = crate::terminal::color::DEFAULT_THEME;
|
||||
let default = *crate::terminal::color::DEFAULT_THEME;
|
||||
|
||||
assert_eq!(theme.foreground, Color::White);
|
||||
assert_eq!(theme.error, Color::Red);
|
||||
@@ -739,7 +742,7 @@ mod tests {
|
||||
rules: vec![],
|
||||
};
|
||||
let theme = skin.to_theme();
|
||||
let default = crate::terminal::color::DEFAULT_THEME;
|
||||
let default = *crate::terminal::color::DEFAULT_THEME;
|
||||
assert_eq!(theme.foreground, default.foreground);
|
||||
assert_eq!(theme.error, default.error);
|
||||
assert_eq!(theme.border, default.border);
|
||||
|
||||
@@ -811,7 +811,7 @@ mod tests {
|
||||
|
||||
let backend = TestBackend::new(80, 10);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
terminal
|
||||
.draw(|f| {
|
||||
v.render(f, f.area(), &theme);
|
||||
@@ -821,12 +821,19 @@ mod tests {
|
||||
let buffer = terminal.backend().buffer().clone();
|
||||
// The viewer shell may add header/footer rows, so do not
|
||||
// hard-code one exact coordinate. Find the rendered 'b' with
|
||||
// the warning background instead.
|
||||
// the highlight background instead.
|
||||
let highlight_bg = crate::terminal::mc_skin::color_pair(
|
||||
theme.name,
|
||||
"viewer",
|
||||
"viewselected",
|
||||
)
|
||||
.map(|p| p.bg)
|
||||
.unwrap_or(theme.warning);
|
||||
let highlighted_b = (0..buffer.area.height)
|
||||
.flat_map(|y| (0..buffer.area.width).map(move |x| (x, y)))
|
||||
.find_map(|(x, y)| {
|
||||
let cell = buffer.cell((x, y))?;
|
||||
(cell.symbol() == "b" && cell.style().bg == Some(theme.warning))
|
||||
(cell.symbol() == "b" && cell.style().bg == Some(highlight_bg))
|
||||
.then_some((x, y))
|
||||
})
|
||||
.expect("highlighted 'b' should exist in rendered buffer");
|
||||
@@ -834,13 +841,14 @@ mod tests {
|
||||
.cell(highlighted_b)
|
||||
.expect("highlighted 'b' cell exists");
|
||||
let style = cell.style();
|
||||
// The "b" of the highlighted "bar" must have the theme's
|
||||
// warning background; the gutter/foreground styling is
|
||||
// irrelevant for this assertion.
|
||||
// The "b" of the highlighted "bar" must have the skin's
|
||||
// viewer viewselected (or warning fallback) background;
|
||||
// the gutter/foreground styling is irrelevant for this
|
||||
// assertion.
|
||||
assert_eq!(
|
||||
style.bg,
|
||||
Some(theme.warning),
|
||||
"highlighted 'b' must have the theme warning background, got {:?}",
|
||||
Some(highlight_bg),
|
||||
"highlighted 'b' must have the highlight background, got {:?}",
|
||||
style
|
||||
);
|
||||
|
||||
@@ -852,8 +860,8 @@ mod tests {
|
||||
let cell_r = buffer
|
||||
.cell((highlighted_b.0 + 2, highlighted_b.1))
|
||||
.expect("cell after highlighted a exists");
|
||||
assert_eq!(cell_a.style().bg, Some(theme.warning));
|
||||
assert_eq!(cell_r.style().bg, Some(theme.warning));
|
||||
assert_eq!(cell_a.style().bg, Some(highlight_bg));
|
||||
assert_eq!(cell_r.style().bg, Some(highlight_bg));
|
||||
|
||||
// And the 'f' of "foo" right before "bar" must NOT be
|
||||
// highlighted.
|
||||
@@ -862,7 +870,7 @@ mod tests {
|
||||
.expect("cell before highlighted b exists");
|
||||
assert_ne!(
|
||||
cell_f.style().bg,
|
||||
Some(theme.warning),
|
||||
Some(highlight_bg),
|
||||
"the 'f' before the match must not be highlighted"
|
||||
);
|
||||
}
|
||||
@@ -888,7 +896,7 @@ mod tests {
|
||||
Span::styled("bar".to_string(), base),
|
||||
];
|
||||
// Match "o b" at byte offsets 2..5 (crosses two spans).
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
let out = overlay_match_highlight(base_spans, &[(2, 5)], &theme);
|
||||
let total: String = out.iter().map(|s| s.content.as_ref()).collect();
|
||||
assert_eq!(total, "foo bar");
|
||||
@@ -899,7 +907,7 @@ mod tests {
|
||||
use ratatui::style::{Color as RC, Style};
|
||||
let base = Style::default().fg(RC::Rgb(255, 0, 0));
|
||||
let spans = vec![Span::styled("abc".to_string(), base)];
|
||||
let theme = crate::terminal::color::DEFAULT_THEME;
|
||||
let theme = *crate::terminal::color::DEFAULT_THEME;
|
||||
let out = overlay_match_highlight(spans.clone(), &[], &theme);
|
||||
assert_eq!(out.len(), 1);
|
||||
assert_eq!(out[0].content, "abc");
|
||||
|
||||
Reference in New Issue
Block a user