diff --git a/src/bin/john-slop-fmt.rs b/src/bin/john-slop-fmt.rs index 4f57040..b5496a8 100644 --- a/src/bin/john-slop-fmt.rs +++ b/src/bin/john-slop-fmt.rs @@ -349,4 +349,44 @@ mod tests { assert!(has_archive_extension(Path::new("bundle.zip"))); assert!(!has_archive_extension(Path::new("article.txt"))); } + + #[test] + fn validates_write_and_recursive_mode_boundaries() { + let stdin_write = Cli::try_parse_from(["john-slop-fmt", "--write"]).unwrap(); + assert!(validate_invocation(&stdin_write, mode(&stdin_write)).is_err()); + + let recursive_stdout = + Cli::try_parse_from(["john-slop-fmt", "--recursive", "docs"]).unwrap(); + assert!(validate_invocation(&recursive_stdout, mode(&recursive_stdout)).is_err()); + + let recursive_diff = + Cli::try_parse_from(["john-slop-fmt", "--recursive", "--diff", "docs"]).unwrap(); + assert!(validate_invocation(&recursive_diff, mode(&recursive_diff)).is_err()); + + let recursive_check = + Cli::try_parse_from(["john-slop-fmt", "--recursive", "--check", "docs"]).unwrap(); + assert!(validate_invocation(&recursive_check, mode(&recursive_check)).is_ok()); + } + + #[test] + fn formats_loaded_documents_and_tracks_changed_state() { + let documents = vec![ + ( + Some(PathBuf::from("changed.txt")), + "changed.txt".into(), + "a—b".into(), + ), + ( + Some(PathBuf::from("clean.txt")), + "clean.txt".into(), + "plain".into(), + ), + ]; + let formatted = format_documents(documents, &Config::embedded()).unwrap(); + + assert_eq!(formatted[0].formatted, "a-b"); + assert!(formatted[0].changed()); + assert_eq!(formatted[1].formatted, "plain"); + assert!(!formatted[1].changed()); + } } diff --git a/src/bin/john-slop.rs b/src/bin/john-slop.rs index 00d480b..90fcf43 100644 --- a/src/bin/john-slop.rs +++ b/src/bin/john-slop.rs @@ -433,4 +433,41 @@ mod tests { assert_eq!(error.exit_code(), 2); } + + #[test] + fn threshold_source_paths_and_ignore_globs_cover_every_variant() { + let config = Config::embedded(); + for (level, expected) in [ + ("low", config.thresholds.low), + ("medium", config.thresholds.medium), + ("high", config.thresholds.high), + ] { + let cli = + Cli::try_parse_from(["john-slop", "--fail-level", level, "article.md"]).unwrap(); + assert_eq!(fail_threshold(&cli, &config), expected); + } + let cli = + Cli::try_parse_from(["john-slop", "--fail-confidence", "17", "article.md"]).unwrap(); + assert_eq!(fail_threshold(&cli, &config), 17); + + assert_eq!(source_path(&SourceId::Stdin), None); + assert_eq!( + source_path(&SourceId::File("article.md".into())), + Some(Path::new("article.md")) + ); + assert_eq!( + source_path(&SourceId::ArchiveMember { + archive: "bundle.zip".into(), + member: "docs/article.md".into(), + }), + Some(Path::new("docs/article.md")) + ); + + let globs = compile_ignore_globs(&["generated/**".into(), "*.min.js".into()]).unwrap(); + assert!(is_ignored(&globs, Some(Path::new("generated/out.rs")))); + assert!(is_ignored(&globs, Some(Path::new("bundle.min.js")))); + assert!(!is_ignored(&globs, Some(Path::new("src/lib.rs")))); + assert!(!is_ignored(&globs, None)); + assert!(compile_ignore_globs(&["[".into()]).is_err()); + } } diff --git a/src/bin/john-slop/output.rs b/src/bin/john-slop/output.rs index 039e5bb..e65ba3e 100644 --- a/src/bin/john-slop/output.rs +++ b/src/bin/john-slop/output.rs @@ -331,4 +331,44 @@ mod tests { assert_eq!(value["source"], "broken.txt"); assert!(!output.contains('\u{1b}')); } + + #[test] + fn concise_output_has_stable_findings_summary_and_input_errors() { + let (source, analysis) = analysis(); + let source_id = SourceId::File("article.md".into()); + let output = + render_analysis(OutputFormat::Concise, &source_id, &source, &analysis).unwrap(); + + assert!(output.contains("article.md:8:11: advice[typography-non-ascii-hyphen]")); + assert!(output.contains("article.md: summary: confidence=")); + assert!(output.contains("advice=1")); + assert_eq!( + render_input_error(OutputFormat::Concise, "bad.txt", "binary").unwrap(), + "bad.txt: input-error: binary\n" + ); + assert_eq!( + render_input_error(OutputFormat::Human, "bad.txt", "binary").unwrap(), + "bad.txt: input error: binary\n" + ); + assert_eq!( + render_input_error(OutputFormat::Miette, "bad.txt", "binary").unwrap(), + "bad.txt: input error: binary\n" + ); + } + + #[test] + fn clean_analysis_still_emits_an_explicit_no_evidence_summary() { + let output = render_analysis( + OutputFormat::Concise, + &SourceId::Stdin, + "clean", + &Analysis::default(), + ) + .unwrap(); + + assert_eq!( + output, + ": summary: confidence=0 band=none advice=0 warnings=0 errors=0 total=0\n" + ); + } } diff --git a/src/lsp.rs b/src/lsp.rs index 33c6a55..61d1a84 100644 --- a/src/lsp.rs +++ b/src/lsp.rs @@ -447,8 +447,8 @@ mod tests { }; use super::{ - DocumentStore, LineIndex, OpenDocument, PositionError, replacement_code_actions, - replacement_diagnostics, requested_version_is_current, + DocumentStore, LineIndex, OpenDocument, PositionError, ranges_overlap, + replacement_code_actions, replacement_diagnostics, requested_version_is_current, }; fn uri() -> Uri { @@ -628,4 +628,46 @@ mod tests { assert!(requested_version_is_current(&diagnostics, 9)); assert!(!requested_version_is_current(&diagnostics, 10)); } + + #[test] + fn action_filtering_and_document_order_are_deterministic() { + let config = crate::Config::embedded(); + let document = OpenDocument { + version: 1, + language_id: "plaintext".into(), + text: "left—right".into(), + }; + let unrelated = + tower_lsp_server::ls_types::Range::new(Position::new(5, 0), Position::new(5, 1)); + assert!( + replacement_code_actions(&config, &uri(), &document, &unrelated, &[]) + .unwrap() + .is_empty() + ); + assert!(!ranges_overlap( + &tower_lsp_server::ls_types::Range::new(Position::new(0, 0), Position::new(0, 1)), + &tower_lsp_server::ls_types::Range::new(Position::new(0, 2), Position::new(0, 3)), + )); + assert!( + replacement_diagnostics(&config, "plain ASCII", 1) + .unwrap() + .is_empty() + ); + assert!(requested_version_is_current(&[], 99)); + + let mut store = DocumentStore::default(); + for text_uri in ["file:///tmp/z.txt", "file:///tmp/a.txt"] { + store.open(DidOpenTextDocumentParams { + text_document: TextDocumentItem::new( + Uri::from_str(text_uri).unwrap(), + "plaintext".into(), + 1, + "text".into(), + ), + }); + } + let uris = store.uris(); + assert_eq!(uris[0].as_str(), "file:///tmp/a.txt"); + assert_eq!(uris[1].as_str(), "file:///tmp/z.txt"); + } } diff --git a/tasks.md b/tasks.md index 23be290..4eec696 100644 --- a/tasks.md +++ b/tasks.md @@ -246,7 +246,7 @@ line-coverage run. diagnostic accessors with behavior-focused unit tests. - [x] Cover archive and input resource-policy branches with generated fixtures, including unsafe, binary, malformed, and oversized members. -- [ ] Cover remaining practical CLI, formatter, and LSP adapter branches without +- [x] Cover remaining practical CLI, formatter, and LSP adapter branches without coupling tests to unreachable platform failures or coverage-tool artifacts. - [ ] Raise measured Tarpaulin line coverage toward 90%, refresh badges and development documentation, and record any intentionally uncovered remainder.