use super::*;
#[test]
fn clicking_the_position_readout_does_not_open_problems() {
use ratatui::{Terminal, backend::TestBackend};
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let mut term = Terminal::new(TestBackend::new(56, 20)).unwrap();
term.draw(|f| app.render(f)).unwrap();
let buf = term.backend().buffer();
let row = buf.area.height - 1;
let text: String = (0..buf.area.width)
.map(|x| buf[(x, row)].symbol().chars().next().unwrap_or(' '))
.collect();
let ln_col =
text.find("Ln ")
.unwrap_or_else(|| panic!("no position readout in status row {text:?}")) as u16;
let rx = ln_col.saturating_sub(1);
assert!(
app.status_diag_rect.right() <= rx,
"the diagnostics hit rect must stop where the right cluster starts \
(rect {:?} reaches {}, cluster starts at {}); row reads {text:?}",
app.status_diag_rect,
app.status_diag_rect.right(),
rx
);
let col_at = text.find("Col ").unwrap() as u16;
assert!(
!rect_contains(app.status_diag_rect, col_at, row),
"clicking the column readout opened PROBLEMS"
);
}
#[test]
fn sync_markdown_lint_flags_a_second_top_level_heading() {
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("a.md");
std::fs::write(&file, "# Title\n\nBody.\n\n# Another\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.open_pinned(&file).unwrap();
let changed = app.sync_markdown_lint();
assert!(changed, "a fresh markdown tab must lint on first sync");
assert_eq!(app.editor.diagnostics_path(), Some(file.as_path()));
assert!(
app.editor
.diagnostic_spans_for_test()
.iter()
.any(|line| !line.is_empty()),
"MD025 should have produced at least one squiggle"
);
let merged = app.merged_diagnostics(&file);
assert!(merged.iter().any(|d| d.message.contains("MD025")));
}
#[test]
fn sync_markdown_lint_is_quiet_for_a_clean_document_and_reruns_only_on_edit() {
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("clean.md");
std::fs::write(&file, "# Title\n\nA clean paragraph.\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.open_pinned(&file).unwrap();
assert!(!app.sync_markdown_lint());
assert!(
app.merged_diagnostics(&file).is_empty(),
"a clean document must not be flagged"
);
assert!(!app.sync_markdown_lint());
app.editor.goto_bottom();
app.editor
.insert_str_as("\n# Second Title\n", crate::provenance::Seat::Navigator);
assert!(
app.sync_markdown_lint(),
"an edit that introduces a second H1 must re-lint and report a change"
);
assert!(
app.merged_diagnostics(&file)
.iter()
.any(|d| d.message.contains("MD025")),
"the second H1 must be flagged after the edit"
);
}
#[test]
fn sync_markdown_lint_settles_after_a_split_pane_is_edited() {
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("doc.md");
std::fs::write(&file, "# Title\n\n# Second Title\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.open_pinned(&file).unwrap();
app.split_editor();
app.editor.cursor_row = 0;
app.editor.cursor_col = 7;
app.editor.insert_char('!');
assert!(
app.sync_markdown_lint(),
"the first lint stores diagnostics"
);
assert!(
app.merged_diagnostics(&file)
.iter()
.any(|d| d.message.contains("MD025")),
"the edited pane still has two H1s"
);
assert!(
!app.sync_markdown_lint(),
"nothing changed since the last tick"
);
assert!(!app.sync_markdown_lint(), "and it stays settled");
}
#[test]
fn sync_markdown_lint_stands_down_only_for_files_rumdl_reports_on() {
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("a.md");
let other = tmp.path().join("b.md");
std::fs::write(&file, "# Title\n\nBody.\n\n# Another\n").unwrap();
std::fs::write(&other, "# Title\n\nBody.\n\n# Another\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.open_pinned(&other).unwrap();
app.editor.open_pinned(&file).unwrap();
let has_md025 = |app: &App, path: &std::path::Path| {
app.merged_diagnostics(path)
.iter()
.any(|d| d.message.contains("MD025"))
};
assert!(app.sync_markdown_lint());
assert!(has_md025(&app, &file), "the built-in lint reports MD025");
assert!(has_md025(&app, &other));
let lsp = || app.lsp.as_ref().expect("a test App has an LSP manager");
lsp().set_document_servers_for_test(&file, &["marksman", "rumdl"]);
lsp().set_document_servers_for_test(&other, &["marksman"]);
assert!(app.sync_markdown_lint(), "standing down is a change");
assert!(!has_md025(&app, &file), "withdrawn where rumdl reports");
assert!(
app.editor
.diagnostic_spans_for_test()
.iter()
.all(|line| line.is_empty()),
"and its squiggle is gone from the open tab"
);
assert!(has_md025(&app, &other), "kept where rumdl does not report");
assert!(!app.sync_markdown_lint(), "and it stays quiet");
app.lsp
.as_ref()
.unwrap()
.set_document_servers_for_test(&file, &["marksman"]);
assert!(
app.sync_markdown_lint(),
"with rumdl gone the lint runs again"
);
assert!(has_md025(&app, &file));
}
#[test]
fn sync_markdown_lint_relints_a_pane_with_the_same_seq_but_other_text() {
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("doc.md");
std::fs::write(&file, "# Title\n\nplain\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.open_pinned(&file).unwrap();
app.split_editor();
app.editor.cursor_row = 2;
app.editor.cursor_col = 0;
for c in "#Bad".chars() {
app.editor.insert_char(c);
}
let seq_bad = app.editor.edit_seq;
app.focus_editor_group(true);
app.editor.cursor_row = 2;
app.editor.cursor_col = 5;
while app.editor.edit_seq < seq_bad {
app.editor.insert_char('!');
}
assert_eq!(app.editor.edit_seq, seq_bad, "same seq, different text");
assert!(!app.editor.lines.iter().any(|l| l.starts_with("#B")));
let md018 = |app: &App| {
app.merged_diagnostics(&file)
.iter()
.any(|d| d.message.contains("MD018"))
};
app.focus_editor_group(false);
app.sync_markdown_lint();
assert!(md018(&app), "the focused pane has `#Bad`");
app.focus_editor_group(true);
app.sync_markdown_lint();
assert!(
!md018(&app),
"the other pane has no MD018, so it must be re-linted"
);
}
#[test]
fn sync_markdown_lint_covers_inactive_split_groups() {
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("doc.md");
std::fs::write(&file, "# Title\n\n# Second Title\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.open_pinned(&file).unwrap();
app.split_editor(); let other = tmp.path().join("other.txt");
std::fs::write(&other, "plain\n").unwrap();
app.editor.open_pinned(&other).unwrap();
let md_idx = app
.editor
.iter_tabs()
.position(|e| e.path.as_deref() == Some(file.as_path()))
.expect("the active group still holds doc.md before the close");
app.editor.close_tab(md_idx);
assert!(
!app.editor
.iter_tabs()
.any(|e| e.path.as_deref() == Some(file.as_path())),
"doc.md must now live ONLY in the inactive group"
);
let held_inactive = app
.editor_layout
.inactive_groups()
.into_iter()
.flat_map(|g| g.editors.iter())
.any(|e| e.path.as_deref() == Some(file.as_path()));
assert!(held_inactive, "the inactive group holds doc.md");
app.sync_markdown_lint();
assert!(
app.merged_diagnostics(&file)
.iter()
.any(|d| d.message.contains("MD025")),
"a markdown tab in an inactive pane must still be linted"
);
app.sync_markdown_lint();
assert!(
app.merged_diagnostics(&file)
.iter()
.any(|d| d.message.contains("MD025")),
"the tab is still open, so its diagnostics must survive the sweep"
);
}
#[test]
fn sync_markdown_lint_skips_non_markdown_files() {
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("a.rs");
std::fs::write(&file, "#Not a heading, this is Rust\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.open_pinned(&file).unwrap();
assert!(!app.sync_markdown_lint());
assert!(app.merged_diagnostics(&file).is_empty());
}
#[test]
fn problems_panel_aggregates_the_store_across_files() {
use crate::lsp::manager::DiagnosticSeverity;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let a = tmp.path().join("a.rs");
let mut s1 = std::collections::HashMap::new();
s1.insert(
String::from("rustc"),
vec![
diag(0, 1, DiagnosticSeverity::Error),
diag(2, 3, DiagnosticSeverity::Warning),
],
);
app.lsp_diagnostics.insert(a, s1);
let b = tmp.path().join("b.rs");
let mut s2 = std::collections::HashMap::new();
s2.insert(
String::from("rustc"),
vec![diag(0, 1, DiagnosticSeverity::Error)],
);
app.lsp_diagnostics.insert(b, s2);
app.rebuild_problems();
assert_eq!(
app.problems.total_count(),
3,
"two files, three diagnostics"
);
assert_eq!(app.problems.error_count(), 2);
assert_eq!(app.problems.warning_count(), 1);
}
#[test]
fn clicking_the_problems_tab_switches_the_panel_view() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
assert_eq!(app.bottom_panel_tab, BottomPanelTab::Terminal);
let r = app.problems_tab_rect;
assert!(r.width > 0, "the PROBLEMS tab must have a hit rect");
left_click(&mut app, r.x, r.y);
assert_eq!(
app.bottom_panel_tab,
BottomPanelTab::Problems,
"a click on the PROBLEMS tab activates that view",
);
let t = app.terminal_tab_rect;
left_click(&mut app, t.x, t.y);
assert_eq!(app.bottom_panel_tab, BottomPanelTab::Terminal);
}
#[test]
fn typing_in_the_problems_panel_filters_and_esc_clears_before_leaving() {
use crate::lsp::manager::{Diagnostic, DiagnosticSeverity};
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("hello.rs");
std::fs::write(&file, "fn a() {}\nfn b() {}\nfn run() {}\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let mut by_server = std::collections::HashMap::new();
by_server.insert(
String::from("rustc"),
vec![
Diagnostic {
start_line: 0,
start_char: 0,
end_line: 0,
end_char: 1,
severity: DiagnosticSeverity::Error,
message: String::from("mismatched types"),
tags: Default::default(),
code: None,
origin: None,
},
Diagnostic {
start_line: 2,
start_char: 3,
end_line: 2,
end_char: 6,
severity: DiagnosticSeverity::Warning,
message: String::from("function `run` is never used"),
tags: Default::default(),
code: None,
origin: None,
},
],
);
app.lsp_diagnostics.insert(file.clone(), by_server);
app.rebuild_problems();
app.bottom_panel_tab = BottomPanelTab::Problems;
app.focus_pane(Pane::Terminal);
for c in "mismatch".chars() {
app.handle_key(key(KeyCode::Char(c), KeyModifiers::NONE))
.unwrap();
}
assert_eq!(
app.problems.text_filter, "mismatch",
"plain typing must reach the panel's filter"
);
app.handle_key(key(KeyCode::Backspace, KeyModifiers::NONE))
.unwrap();
assert_eq!(app.problems.text_filter, "mismatc", "Backspace pops");
app.handle_key(key(KeyCode::Esc, KeyModifiers::NONE))
.unwrap();
assert!(app.problems.text_filter.is_empty(), "Esc clears the filter");
assert!(
app.focus == Pane::Terminal,
"the first Esc only clears; the pane keeps focus"
);
app.handle_key(key(KeyCode::Esc, KeyModifiers::NONE))
.unwrap();
assert!(app.focus == Pane::Editor, "the second Esc leaves the panel");
}
#[test]
fn clicking_a_problem_row_opens_that_file_at_the_line() {
use crate::lsp::manager::DiagnosticSeverity;
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("hello.rs");
std::fs::write(&file, "fn a() {}\nfn b() {}\nfn run() {}\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let mut by_server = std::collections::HashMap::new();
by_server.insert(
String::from("rustc"),
vec![crate::lsp::manager::Diagnostic {
start_line: 2,
start_char: 3,
end_line: 2,
end_char: 6,
severity: DiagnosticSeverity::Warning,
message: String::from("function `run` is never used"),
tags: Default::default(),
code: None,
origin: None,
}],
);
app.lsp_diagnostics.insert(file.clone(), by_server);
app.rebuild_problems();
app.bottom_panel_tab = BottomPanelTab::Problems;
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let list = app.problems.last_area;
left_click(&mut app, list.x + 4, list.y + 2);
assert_eq!(
app.editor.path.as_deref(),
Some(file.as_path()),
"clicking the row opens the file",
);
assert_eq!(app.editor.cursor_row, 2, "and jumps to the diagnostic line");
}
#[test]
fn clicking_a_related_location_row_opens_that_place() {
let tmp = tempfile::tempdir().unwrap();
let main = tmp.path().join("src/main.rs");
let lib = tmp.path().join("src/lib.rs");
std::fs::create_dir_all(tmp.path().join("src")).unwrap();
std::fs::write(&main, "fn main() {}\n").unwrap();
std::fs::write(&lib, "fn a() {}\nlet s = \"😀\"; let first = &v[0];\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let wire = lsp_types::Diagnostic {
message: "cannot borrow `v` as mutable".into(),
related_information: Some(vec![lsp_types::DiagnosticRelatedInformation {
location: lsp_types::Location {
uri: lsp_types::Url::from_file_path(&lib).unwrap(),
range: lsp_types::Range::new(
lsp_types::Position::new(1, 27),
lsp_types::Position::new(1, 28),
),
},
message: "immutable borrow occurs here".into(),
}]),
..Default::default()
};
let d = crate::lsp::client::convert_diagnostic("rust-analyzer", &wire);
let by_server = std::collections::HashMap::from([(String::from("rust-analyzer"), vec![d])]);
app.lsp_diagnostics.insert(main, by_server);
app.rebuild_problems();
assert_eq!(
app.problems.groups()[0].items[0].related[0].rel_path,
"src/lib.rs"
);
app.bottom_panel_tab = BottomPanelTab::Problems;
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let list = app.problems.last_area;
left_click(&mut app, list.x + 10, list.y + 3);
assert_eq!(app.editor.path.as_deref(), Some(lib.as_path()));
assert_eq!(
(app.editor.cursor_row, app.editor.cursor_col),
(1, 26),
"on the `v` the borrow takes"
);
}
#[test]
fn hints_stay_out_of_the_problems_list_and_its_count() {
use crate::lsp::manager::{Diagnostic, DiagnosticSeverity, DiagnosticTags};
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let a = tmp.path().join("a.ts");
let unused = DiagnosticTags {
unnecessary: true,
deprecated: false,
};
let mut by_server = std::collections::HashMap::new();
by_server.insert(
String::from("vtsls"),
vec![
diag(0, 1, DiagnosticSeverity::Error),
Diagnostic {
tags: unused,
..diag(2, 5, DiagnosticSeverity::Hint)
},
diag(6, 9, DiagnosticSeverity::Hint),
diag(10, 12, DiagnosticSeverity::Warning),
],
);
app.lsp_diagnostics.insert(a.clone(), by_server);
app.rebuild_problems();
assert_eq!(
app.problems.total_count(),
2,
"only the error and the warning count"
);
let listed: Vec<DiagnosticSeverity> = app
.problems
.groups()
.iter()
.flat_map(|g| g.items.iter().map(|i| i.severity))
.collect();
assert_eq!(
listed,
vec![DiagnosticSeverity::Error, DiagnosticSeverity::Warning]
);
assert_eq!(
app.merged_diagnostics(&a).len(),
4,
"the editor still gets every hint, for its hover and Ctrl+."
);
}
#[test]
fn a_file_with_only_hints_has_no_problems_group_but_information_is_listed() {
use crate::lsp::manager::DiagnosticSeverity;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let hints = tmp.path().join("hints.py");
let info = tmp.path().join("info.py");
let mut h = std::collections::HashMap::new();
h.insert(
String::from("ty"),
vec![
diag(0, 3, DiagnosticSeverity::Hint),
diag(4, 7, DiagnosticSeverity::Hint),
],
);
app.lsp_diagnostics.insert(hints, h);
let mut i = std::collections::HashMap::new();
i.insert(
String::from("ty"),
vec![diag(0, 3, DiagnosticSeverity::Information)],
);
app.lsp_diagnostics.insert(info.clone(), i);
app.rebuild_problems();
let paths: Vec<&std::path::PathBuf> = app.problems.groups().iter().map(|g| &g.path).collect();
assert_eq!(paths, vec![&info]);
assert_eq!(app.problems.total_count(), 1);
}
#[test]
fn the_problems_count_paints_an_orange_pill_in_the_tab_strip() {
use crate::lsp::manager::DiagnosticSeverity;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let a = tmp.path().join("a.rs");
let mut s1 = std::collections::HashMap::new();
s1.insert(
String::from("rustc"),
vec![diag(0, 1, DiagnosticSeverity::Error)],
);
app.lsp_diagnostics.insert(a, s1);
app.rebuild_problems();
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let buf = term.backend().buffer();
let strip = app.problems_tab_rect;
let orange = crate::gradient::rgb_color(crate::gradient::GRAD_TR);
let painted = (strip.x..strip.x + strip.width).any(|x| buf[(x, strip.y)].bg == orange);
assert!(painted, "the problem count wears an orange pill");
let cap_r = (strip.x..strip.x + strip.width)
.any(|x| buf[(x, strip.y)].symbol() == "\u{e0b4}" && buf[(x, strip.y)].fg == orange);
assert!(cap_r, "the pill has a rounded orange right cap");
}
#[test]
fn build_scan_installs_problems_replaces_per_pane_and_merges_with_lsp() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let cwd = tmp.path().join("proj");
std::fs::create_dir(&cwd).unwrap();
let cargo_out = "error[E0308]: mismatched types\n --> src/main.rs:12:5\n";
assert!(app.apply_build_scan(0, Some(&cwd), "cargo build", cargo_out));
let expected = cwd.join("src/main.rs");
let groups = app.problems.groups().to_vec();
let g = groups
.iter()
.find(|g| g.path == expected)
.expect("the resolved file must group in PROBLEMS");
assert_eq!(g.items.len(), 1);
assert_eq!(g.items[0].source, "rustc");
assert_eq!((g.items[0].line, g.items[0].col), (11, 4));
assert!(app.apply_build_scan(1, Some(&cwd), "make", "main.c:7:3: error: boom\n"));
assert_eq!(app.problems.groups().len(), 2);
assert!(app.apply_build_scan(0, Some(&cwd), "cargo build", " Finished dev profile\n"));
let groups = app.problems.groups().to_vec();
assert_eq!(groups.len(), 1, "pane 0's fixed errors must vanish");
assert!(groups[0].path.ends_with("main.c"));
assert!(!app.apply_build_scan(5, Some(&cwd), "true", "all good\n"));
app.clear_build_diagnostics();
assert!(app.problems.groups().is_empty());
assert!(app.status.contains("Cleared 1 build diagnostic"));
}
#[test]
fn a_custom_matcher_from_matchers_json_feeds_problems() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.matchers = std::sync::Arc::new(crate::problem_matchers::MatcherSet::from_json(
r##"[ { "name": "mylint",
"pattern": "^(?P<file>\\S+):(?P<line>\\d+):(?P<col>\\d+) (?P<severity>\\w+) (?P<message>.+)$",
"severity_map": { "E": "error" },
"applies_to": "mylint*" } ]"##,
));
let cwd = tmp.path().join("proj");
std::fs::create_dir(&cwd).unwrap();
let out = "src/a.py:12:5 E undefined name 'x'\n";
assert!(app.apply_build_scan(0, Some(&cwd), "mylint src/", out));
let groups = app.problems.groups().to_vec();
let g = groups
.iter()
.find(|g| g.path == cwd.join("src/a.py"))
.expect("the custom matcher's file must group in PROBLEMS");
assert_eq!(g.items.len(), 1);
assert_eq!(g.items[0].source, "mylint");
assert_eq!(
g.items[0].severity,
crate::lsp::manager::DiagnosticSeverity::Error,
"severity_map turns E into an error"
);
assert_eq!((g.items[0].line, g.items[0].col), (11, 4));
assert!(app.apply_build_scan(0, Some(&cwd), "cargo build", out));
assert!(app.problems.groups().is_empty(), "non-matching command");
}
#[cfg(unix)]
#[test]
fn a_project_checker_that_failed_to_run_does_not_report_a_clean_project() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.finish_project_check_for_test(
tmp.path(),
"error TS5023: Unknown compiler option '--nosuchflag'.\n",
"",
false,
);
assert!(
app.status.contains("failed"),
"an invocation failure must say so, got {:?}",
app.status
);
assert!(
!app.status.contains("no problems"),
"and must NOT read as a clean project, got {:?}",
app.status
);
assert!(
app.status.contains("TS5023"),
"naming the reason, got {:?}",
app.status
);
app.finish_project_check_for_test(
tmp.path(),
"\n\x1b[41m\x1b[37m This is not the tsc command you are looking for \x1b[0m\n",
"",
false,
);
assert!(
app.status.contains("not the tsc command"),
"the reason is found past a blank line and escapes, got {:?}",
app.status
);
assert!(
!app.status.contains('\u{1b}'),
"and carries no escape sequences, got {:?}",
app.status
);
assert_ne!(
app.status, "The project checker failed: ",
"an empty reason is the bug this replaced"
);
app.finish_project_check_for_test(tmp.path(), "", "", true);
assert_eq!(
app.status, "Whole-project check: no problems",
"a real clean run still reports clean"
);
}
#[test]
fn each_producer_clears_only_its_own_rows_from_a_shared_file() {
let tmp = tempfile::tempdir().unwrap();
let shared = tmp.path().join("shared.ts");
std::fs::write(&shared, "export const a = 1;\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let line = |code: &str| format!("shared.ts(1,1): error {code}: boom.\n");
app.apply_build_scan(1, Some(tmp.path()), "tsc", &line("TS1001"));
app.ingest_project_check(Some(tmp.path()), &line("TS2002"));
app.rebuild_problems();
let rows = |app: &App| -> Vec<String> {
app.problems
.groups()
.iter()
.filter(|g| g.path == shared)
.flat_map(|g| g.items.iter().map(|i| i.message.clone()))
.collect()
};
assert_eq!(
rows(&app).len(),
2,
"both producers' rows are on the shared file, got {:?}",
rows(&app)
);
app.ingest_project_check(Some(tmp.path()), "");
app.rebuild_problems();
let after = rows(&app);
assert_eq!(
after.len(),
1,
"the sweep's row goes and the pane's remains, got {after:?}"
);
assert!(
after[0].contains("TS1001"),
"the surviving row is the PANE's, not the sweep's: {after:?}"
);
app.apply_build_scan(1, Some(tmp.path()), "tsc", "");
app.rebuild_problems();
assert!(
rows(&app).is_empty(),
"with both producers clean the file has no rows, got {:?}",
rows(&app)
);
}
#[cfg(unix)]
#[test]
fn a_file_both_producers_report_is_not_double_counted() {
let tmp = tempfile::tempdir().unwrap();
let shared = tmp.path().join("shared.ts");
let only = tmp.path().join("only.ts");
std::fs::write(&shared, "export const a = 1;\n").unwrap();
std::fs::write(&only, "export const b = 2;\n").unwrap();
let line = |f: &str| format!("{f}(1,1): error TS2322: Type error.\n");
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.finish_project_check_for_test(tmp.path(), &line("shared.ts"), "", false);
assert_eq!(app.status, "Whole-project check: 1 problem");
app.apply_build_scan(1, Some(tmp.path()), "tsc", &line("shared.ts"));
app.finish_project_check_for_test(tmp.path(), &line("shared.ts"), "", false);
assert_eq!(
app.status, "Whole-project check: 1 problem",
"the pane's row for the same file is not the sweep's to count"
);
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.apply_build_scan(1, Some(tmp.path()), "tsc", &line("shared.ts"));
app.finish_project_check_for_test(
tmp.path(),
&format!("{}{}", line("shared.ts"), line("only.ts")),
"",
false,
);
assert_eq!(
app.status, "Whole-project check: 2 problems",
"the sweep found two, even though a pane got to one of them first"
);
}
#[cfg(unix)]
#[test]
fn the_project_check_count_is_its_own_not_the_panels() {
use crate::lsp::manager::DiagnosticSeverity;
let tmp = tempfile::tempdir().unwrap();
let swept = tmp.path().join("swept.ts");
let other = tmp.path().join("other.rs");
std::fs::write(&swept, "export const x: string = 1;\n").unwrap();
std::fs::write(&other, "fn main() {}\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let mut by_server = std::collections::HashMap::new();
by_server.insert(
String::from("rust-analyzer"),
vec![diag(0, 4, DiagnosticSeverity::Error)],
);
app.lsp_diagnostics.insert(other.clone(), by_server);
app.finish_project_check_for_test(
tmp.path(),
"swept.ts(1,14): error TS2322: Type 'number' is not assignable.\n",
"",
false,
);
assert_eq!(
app.status, "Whole-project check: 1 problem",
"the sweep found one; the LSP's row is not its to count"
);
assert!(
app.problems.total_count() > 1,
"staging check: the panel really does hold more than the sweep's row"
);
app.problems.scope = crate::widgets::problems::ProblemScope::OpenFiles;
app.rebuild_problems();
app.finish_project_check_for_test(
tmp.path(),
"swept.ts(1,14): error TS2322: Type 'number' is not assignable.\n",
"",
false,
);
assert_eq!(
app.status, "Whole-project check: 1 problem",
"the scope filters the PANEL, not what the sweep found"
);
}
#[test]
fn a_project_check_reports_unopened_files_and_replaces_on_rerun() {
let tmp = tempfile::tempdir().unwrap();
let a = tmp.path().join("a.ts");
let b = tmp.path().join("b.ts");
std::fs::write(&a, "export const x: string = 1;\n").unwrap();
std::fs::write(&b, "export const y: string = 2;\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
assert!(app.editor.path.is_none(), "no file is open");
app.ingest_project_check(
None,
"a.ts(1,14): error TS2322: Type 'number' is not assignable to type 'string'.\n\
b.ts(1,14): error TS2322: Type 'number' is not assignable to type 'string'.\n",
);
app.rebuild_problems();
let paths: Vec<_> = app
.problems
.groups()
.iter()
.map(|g| g.path.clone())
.collect();
assert!(
paths.contains(&a) && paths.contains(&b),
"both unopened files must reach PROBLEMS, got {paths:?}"
);
app.ingest_project_check(
None,
"a.ts(1,14): error TS2322: Type 'number' is not assignable to type 'string'.\n",
);
app.rebuild_problems();
let paths: Vec<_> = app
.problems
.groups()
.iter()
.map(|g| g.path.clone())
.collect();
assert!(
paths.contains(&a),
"the still-broken file keeps its row, got {paths:?}"
);
assert!(
!paths.contains(&b),
"a re-run REPLACES the previous sweep: the fixed file's row must go, \
got {paths:?}"
);
let c = tmp.path().join("c.ts");
std::fs::write(&c, "export const z = 3;\n").unwrap();
app.apply_build_scan(
1,
Some(tmp.path()),
"tsc",
"c.ts(1,1): error TS1005: ';' expected.\n",
);
app.rebuild_problems();
let paths: Vec<_> = app
.problems
.groups()
.iter()
.map(|g| g.path.clone())
.collect();
assert!(
paths.contains(&a) && paths.contains(&c),
"a pane's build output and the project sweep coexist, got {paths:?}"
);
}
#[test]
fn problems_shows_diagnostics_for_a_file_that_was_never_opened() {
use crate::lsp::manager::DiagnosticSeverity;
let tmp = tempfile::tempdir().unwrap();
let opened = tmp.path().join("opened.rs");
let never = tmp.path().join("never_opened.rs");
std::fs::write(&opened, "fn main() {}\n").unwrap();
std::fs::write(&never, "fn helper() {}\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.open_pinned(&opened).unwrap();
let mut by_server = std::collections::HashMap::new();
by_server.insert(
String::from("rust-analyzer"),
vec![diag(0, 4, DiagnosticSeverity::Error)],
);
app.lsp_diagnostics.insert(never.clone(), by_server);
app.rebuild_problems();
let paths: Vec<_> = app.problems.groups().iter().map(|g| &g.path).collect();
assert!(
paths.contains(&&never),
"a diagnostic for an unopened file must still reach PROBLEMS"
);
}
#[test]
fn problems_scope_toggle_filters_unopened_files_and_the_badge_follows() {
use crate::lsp::manager::DiagnosticSeverity;
use crate::widgets::problems::ProblemScope;
let tmp = tempfile::tempdir().unwrap();
let opened = tmp.path().join("opened.rs");
let never = tmp.path().join("never_opened.rs");
std::fs::write(&opened, "fn main() {}\n").unwrap();
std::fs::write(&never, "fn helper() {}\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.open_pinned(&opened).unwrap();
for p in [&opened, &never] {
let mut by_server = std::collections::HashMap::new();
by_server.insert(
String::from("rust-analyzer"),
vec![diag(0, 4, DiagnosticSeverity::Error)],
);
app.lsp_diagnostics.insert(p.clone(), by_server);
}
app.problems.scope = ProblemScope::WholeProject;
app.rebuild_problems();
assert_eq!(
app.problems.groups().len(),
2,
"whole project lists the unopened file too"
);
let whole_count = app.problems.total_count();
app.problems.scope = ProblemScope::OpenFiles;
app.rebuild_problems();
let paths: Vec<_> = app.problems.groups().iter().map(|g| &g.path).collect();
assert_eq!(paths, vec![&opened], "open files drops the unopened one");
assert!(
app.problems.total_count() < whole_count,
"the badge counts the same filtered list"
);
}
#[test]
fn opening_a_file_refreshes_a_scoped_problems_panel() {
use crate::lsp::manager::DiagnosticSeverity;
use crate::widgets::problems::ProblemScope;
let tmp = tempfile::tempdir().unwrap();
let later = tmp.path().join("later.rs");
std::fs::write(&later, "fn helper() {}\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.problems.scope = ProblemScope::OpenFiles;
let mut by_server = std::collections::HashMap::new();
by_server.insert(
String::from("rust-analyzer"),
vec![diag(0, 4, DiagnosticSeverity::Error)],
);
app.lsp_diagnostics.insert(later.clone(), by_server);
app.rebuild_problems();
assert!(
app.problems.groups().is_empty(),
"not open yet, so Open Files scope hides it"
);
app.editor.open_pinned(&later).unwrap();
app.sync_lsp();
let paths: Vec<_> = app.problems.groups().iter().map(|g| &g.path).collect();
assert!(
paths.contains(&&later),
"opening the file refreshes the scoped panel"
);
}
#[test]
fn problem_scope_config_tokens_round_trip() {
use crate::widgets::problems::ProblemScope;
for scope in [ProblemScope::OpenFiles, ProblemScope::WholeProject] {
assert_eq!(
ProblemScope::from_config(scope.to_config()),
scope,
"{} must survive a save/load cycle",
scope.to_config()
);
}
assert_eq!(
ProblemScope::from_config("Open Files"),
ProblemScope::OpenFiles
);
assert_eq!(
ProblemScope::from_config("nonsense"),
ProblemScope::WholeProject
);
}
#[test]
fn a_zero_problem_count_clears_nothing_when_no_badge_was_drawn() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.overlays
.activity
.set_images(super::ActivityBarImages::default());
app.problems_badge_count = usize::MAX;
app.refresh_problems_badge();
assert!(!app.consume_problems_badge_image_clear());
}
#[cfg(unix)]
#[test]
fn the_project_check_checks_each_referenced_tsconfig() {
let tmp = fake_tsc_workspace(
r#"{
// Vite's layout
"files": [],
"references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }],
}"#,
);
let (status, calls) = run_project_check(&tmp);
assert_eq!(
calls,
"-p ./tsconfig.app.json --noEmit\n-p ./tsconfig.node.json --noEmit\n"
);
assert_eq!(status, "Whole-project check: 1 problem");
}
#[cfg(unix)]
#[test]
fn a_root_with_references_and_its_own_files_is_checked_too() {
let tmp = fake_tsc_workspace(
r#"{ "include": ["src"], "references": [{ "path": "./tsconfig.app.json" }] }"#,
);
let (status, calls) = run_project_check(&tmp);
assert_eq!(calls, "--noEmit\n-p ./tsconfig.app.json --noEmit\n");
assert_eq!(status, "Whole-project check: 1 problem");
}
#[cfg(unix)]
#[test]
fn a_nested_solution_reference_is_checked_through_its_leaves() {
let tmp = fake_tsc_workspace(r#"{ "files": [], "references": [{ "path": "./web" }] }"#);
std::fs::create_dir_all(tmp.path().join("web")).unwrap();
std::fs::write(
tmp.path().join("web/tsconfig.json"),
r#"{ "files": [], "references": [{ "path": "./tsconfig.app.json" }, { "path": ".." }] }"#,
)
.unwrap();
std::fs::write(tmp.path().join("web/tsconfig.app.json"), "{}").unwrap();
let (status, calls) = run_project_check(&tmp);
assert_eq!(calls, "-p ./web/./tsconfig.app.json --noEmit\n");
assert_eq!(status, "Whole-project check: 1 problem");
}
fn problem(
line: u32,
severity: crate::lsp::manager::DiagnosticSeverity,
message: &str,
) -> crate::widgets::problems::ProblemItem {
crate::widgets::problems::ProblemItem {
line,
col: 0,
col_utf16: true,
severity,
message: message.into(),
source: "ruff".into(),
code: None,
related: Vec::new(),
}
}
#[test]
fn the_problems_tab_is_announced_with_its_counts_and_top_entry() {
use crate::lsp::manager::DiagnosticSeverity::{Error, Warning};
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.focus = Pane::Terminal;
app.bottom_panel_tab = BottomPanelTab::Problems;
let snap = app.a11y_snapshot();
assert_eq!(snap.focus, "Problems, no problems");
assert_eq!(snap.item, None);
app.problems
.set_groups(vec![crate::widgets::problems::ProblemGroup {
path: tmp.path().join("app.py"),
name: "app.py".into(),
rel_dir: String::new(),
items: vec![
problem(3, Error, "Undefined name `totl`"),
problem(4, Error, "Type mismatch"),
problem(4, Warning, "Unused variable"),
],
}]);
let snap = app.a11y_snapshot();
assert_eq!(snap.focus, "Problems, 2 errors, 1 warning");
assert_eq!(
snap.item.as_deref(),
Some("app.py line 4: Undefined name `totl` (ruff)")
);
let mut coded = problem(0, Error, "`os` imported but unused");
coded.code = Some(crate::lsp::manager::DiagnosticCode {
value: String::from("F401"),
source: Some(String::from("Ruff")),
href: None,
});
app.problems
.set_groups(vec![crate::widgets::problems::ProblemGroup {
path: tmp.path().join("app.py"),
name: "app.py".into(),
rel_dir: String::new(),
items: vec![coded],
}]);
assert_eq!(
app.a11y_snapshot().item.as_deref(),
Some("app.py line 1: `os` imported but unused (Ruff(F401))")
);
}
#[test]
fn a_build_after_a_screen_clearing_watcher_reaches_problems() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let pane = app.run_project_task(long_task("tsc --watch")).unwrap();
let cwd = tmp.path().to_path_buf();
let stale = "main.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'.\n";
let fresh = "main.ts(2,7): error TS2322: Type 'number' is not assignable to type 'string'.\n";
assert!(app.apply_build_scan(pane, Some(&cwd), "tsc --watch", stale));
app.watch_published_panes.insert(pane);
finish_pane_command(&mut app, pane, Some(130), 5_000);
assert!(
app.apply_build_scan(pane, Some(&cwd), "tsc", fresh),
"the build after the watcher is scanned"
);
let groups = app.problems.groups().to_vec();
assert_eq!(groups.len(), 1, "{groups:?}");
let lines: Vec<u32> = groups[0].items.iter().map(|d| d.line).collect();
assert_eq!(
lines,
vec![1],
"the build's line 2 error (0-based 1), not the watcher's line 1"
);
}
#[test]
fn a_custom_matcher_named_go_keeps_rows_for_missing_files() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.matchers = std::sync::Arc::new(crate::problem_matchers::MatcherSet::from_json(
r##"[ { "name": "go",
"pattern": "^(?P<file>\\S+):(?P<line>\\d+):(?P<col>\\d+) (?P<severity>\\w+) (?P<message>.+)$",
"applies_to": "mygo*" } ]"##,
));
let out = "gen/missing.go:3:1 error generated file absent\n";
assert!(app.apply_build_scan(0, Some(tmp.path()), "mygo build", out));
let groups = app.problems.groups().to_vec();
let g = groups
.iter()
.find(|g| g.path == tmp.path().join("gen/missing.go"))
.expect("a user matcher's row must not need an existing file");
assert_eq!(g.items[0].source, "go");
}
#[test]
fn go_and_lint_rows_reach_problems_only_for_real_files() {
let tmp = tempfile::tempdir().unwrap();
std::fs::write(tmp.path().join("main.go"), "package main\n").unwrap();
std::fs::write(tmp.path().join("app.py"), "import os\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let out = "./main.go:4:6: declared and not used: unused\n\
app.py:1:1: F401 'os' imported but unused\n\
notes.go:9:9: just some text\n\
ghost.py:3:1: E999 not a real file\n\
app.py:2: error: Incompatible types in assignment\n";
assert!(app.apply_build_scan(3, Some(tmp.path()), "go build ./... ; flake8 app.py", out));
let mut rows: Vec<(String, u32, String)> = app
.problems
.groups()
.iter()
.flat_map(|g| {
let name = g.path.file_name().unwrap().to_string_lossy().into_owned();
g.items
.iter()
.map(move |i| (name.clone(), i.line, i.source.clone()))
})
.collect();
rows.sort();
assert_eq!(
rows,
[
(String::from("app.py"), 0, String::from("lint")),
(String::from("app.py"), 1, String::from("no-column")),
(String::from("main.go"), 3, String::from("go")),
]
);
}
fn seed_build_rows(app: &mut App, rows: &[(&std::path::Path, u32, u32, &str)]) {
use crate::lsp::manager::DiagnosticSeverity;
for (path, line, col, msg) in rows {
app.build_diagnostics
.entry(path.to_path_buf())
.or_default()
.push((
1,
crate::widgets::problems::ProblemItem {
line: *line,
col: *col,
col_utf16: false,
severity: DiagnosticSeverity::Warning,
message: (*msg).to_string(),
source: String::from("build"),
code: None,
related: Vec::new(),
},
));
}
app.rebuild_problems();
}
#[test]
fn go_to_next_and_previous_problem_walk_the_build_messages_across_files_and_wrap() {
use crate::widgets::command_palette::Command;
let tmp = tempfile::tempdir().unwrap();
let a = tmp.path().join("a.c");
let b = tmp.path().join("b.c");
std::fs::write(&a, "int a;\nint b;\nint c;\n").unwrap();
std::fs::write(&b, "int d;\nint e;\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
seed_build_rows(
&mut app,
&[(&a, 0, 4, "one"), (&a, 2, 1, "two"), (&b, 1, 2, "three")],
);
let next = Command::from_id("next_problem").expect("next_problem id");
let prev = Command::from_id("previous_problem").expect("previous_problem id");
app.run_command(next);
assert_eq!(app.editor.path.as_deref(), Some(a.as_path()));
assert_eq!((app.editor.cursor_row, app.editor.cursor_col), (0, 4));
assert!(app.status.contains("Problem 1/3"), "{}", app.status);
assert!(app.status.contains("one"), "{}", app.status);
app.run_command(next);
assert_eq!((app.editor.cursor_row, app.editor.cursor_col), (2, 1));
app.run_command(next);
assert_eq!(app.editor.path.as_deref(), Some(b.as_path()));
assert_eq!((app.editor.cursor_row, app.editor.cursor_col), (1, 2));
app.run_command(next);
assert_eq!(
app.editor.path.as_deref(),
Some(a.as_path()),
"wraps to the first"
);
assert_eq!((app.editor.cursor_row, app.editor.cursor_col), (0, 4));
app.run_command(prev);
assert_eq!(
app.editor.path.as_deref(),
Some(b.as_path()),
"wraps to the last"
);
app.run_command(prev);
assert_eq!(app.editor.path.as_deref(), Some(a.as_path()));
assert_eq!((app.editor.cursor_row, app.editor.cursor_col), (2, 1));
}
#[test]
fn go_to_next_problem_between_entries_and_with_none() {
use crate::widgets::command_palette::Command;
let tmp = tempfile::tempdir().unwrap();
let a = tmp.path().join("a.c");
std::fs::write(&a, "int a;\nint b;\nint c;\nint d;\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let next = Command::from_id("next_problem").unwrap();
app.run_command(next);
assert_eq!(app.status, "No problems");
seed_build_rows(&mut app, &[(&a, 1, 0, "x"), (&a, 3, 0, "y")]);
app.editor.open_pinned(&a).unwrap();
app.editor.cursor_row = 2;
app.editor.cursor_col = 0;
app.run_command(next);
assert_eq!(app.editor.cursor_row, 3, "the first entry after the caret");
app.editor.cursor_row = 0;
app.run_command(Command::from_id("previous_problem").unwrap());
assert_eq!(
app.editor.cursor_row, 3,
"before the first wraps to the last"
);
}
#[test]
fn go_to_next_problem_walks_past_an_entry_beyond_its_line_and_shared_positions() {
use crate::widgets::command_palette::Command;
let tmp = tempfile::tempdir().unwrap();
let a = tmp.path().join("a.c");
std::fs::write(&a, "int a;\nint b;\nint c;\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
seed_build_rows(
&mut app,
&[
(&a, 0, 50, "past the end"),
(&a, 2, 1, "first here"),
(&a, 2, 1, "second here"),
],
);
let next = Command::from_id("next_problem").unwrap();
app.run_command(next);
assert!(app.status.contains("past the end"), "{}", app.status);
assert_eq!(app.editor.cursor_row, 0);
app.run_command(next);
assert!(app.status.contains("first here"), "{}", app.status);
app.run_command(next);
assert!(app.status.contains("second here"), "{}", app.status);
app.run_command(next);
assert!(app.status.contains("past the end"), "wraps: {}", app.status);
}
#[test]
fn go_to_next_problem_visits_every_entry_once_around_mixed_columns() {
use crate::lsp::manager::DiagnosticSeverity;
use crate::widgets::command_palette::Command;
let tmp = tempfile::tempdir().unwrap();
let a = tmp.path().join("a.c");
let b = tmp.path().join("b.c");
std::fs::write(&a, "\u{1f600}\u{1f600}abc\n").unwrap();
std::fs::write(&b, "int b;\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let row = |col: u32, col_utf16: bool, msg: &str| {
(
1,
crate::widgets::problems::ProblemItem {
line: 0,
col,
col_utf16,
severity: DiagnosticSeverity::Warning,
message: msg.to_string(),
source: String::from("build"),
code: None,
related: Vec::new(),
},
)
};
app.build_diagnostics
.entry(a.clone())
.or_default()
.extend([row(3, false, "at b"), row(4, true, "at a")]);
app.build_diagnostics
.entry(b.clone())
.or_default()
.push(row(0, false, "in b.c"));
app.rebuild_problems();
let next = Command::from_id("next_problem").unwrap();
let mut seen = Vec::new();
for _ in 0..3 {
app.run_command(next);
seen.push(app.status.clone());
}
for msg in ["at a", "at b", "in b.c"] {
assert_eq!(
seen.iter().filter(|s| s.contains(msg)).count(),
1,
"{msg} once in a round: {seen:?}"
);
}
}
#[test]
fn go_to_next_problem_passes_over_an_entry_whose_file_is_gone() {
use crate::widgets::command_palette::Command;
let tmp = tempfile::tempdir().unwrap();
let gone = tmp.path().join("a_gone.c");
let b = tmp.path().join("b.c");
std::fs::write(&b, "int b;\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
seed_build_rows(&mut app, &[(&gone, 0, 1, "lost"), (&b, 0, 4, "found")]);
let next = Command::from_id("next_problem").unwrap();
app.run_command(next);
assert_eq!(
app.editor.path.as_deref(),
Some(b.as_path()),
"{}",
app.status
);
assert!(app.status.contains("found"), "{}", app.status);
std::fs::remove_file(&b).unwrap();
let mut alone = App::new(tmp.path().to_path_buf()).unwrap();
seed_build_rows(&mut alone, &[(&gone, 0, 1, "lost")]);
alone.run_command(next);
assert!(alone.status.starts_with("Open failed"), "{}", alone.status);
}
#[test]
fn a_watch_batch_gets_the_build_column_conversion() {
let tmp = tempfile::tempdir().unwrap();
std::fs::write(tmp.path().join("t.c"), "{\n\t\t\tint u;\n}\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let row = crate::build_matchers::BuildDiag {
file: String::from("t.c"),
line: 1,
col: 28,
severity: crate::lsp::manager::DiagnosticSeverity::Warning,
message: String::from("unused"),
source: String::from("build"),
needs_file: false,
};
app.install_build_diags(
7,
Some(tmp.path()),
vec![row],
crate::build_matchers::DEFAULT_TABSTOP,
);
let rows = &app.build_diagnostics[&tmp.path().join("t.c")];
assert_eq!(rows.len(), 1);
assert_eq!(rows[0].1.col, 7, "display column 28 is the `u`, char 7");
}