diff --git a/Cargo.lock b/Cargo.lock index 4221895..d7d5818 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -156,7 +156,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 3.0.6", + "syn", ] [[package]] @@ -258,7 +258,7 @@ checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn", ] [[package]] @@ -477,6 +477,17 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "insta" +version = "1.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0f8fee8c926415c58d6ae43a08523a26faccb2323f5e6b644fe7dd4ef6b82" +dependencies = [ + "once_cell", + "similar", + "tempfile", +] + [[package]] name = "is_ci" version = "1.2.0" @@ -498,6 +509,7 @@ name = "john_slop" version = "0.1.0" dependencies = [ "clap", + "insta", "miette", "regex", "tempfile", @@ -571,7 +583,6 @@ dependencies = [ "backtrace", "backtrace-ext", "cfg-if", - "miette-derive", "owo-colors", "supports-color", "supports-hyperlinks", @@ -581,17 +592,6 @@ dependencies = [ "unicode-width 0.1.14", ] -[[package]] -name = "miette-derive" -version = "7.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - [[package]] name = "miniz_oxide" version = "0.8.9" @@ -787,7 +787,7 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn", ] [[package]] @@ -824,6 +824,12 @@ version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" +[[package]] +name = "similar" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" + [[package]] name = "slab" version = "0.4.12" @@ -869,17 +875,6 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7401a30af6cb5818bb64852270bb722533397edcfc7344954a38f420819ece2" -[[package]] -name = "syn" -version = "2.0.119" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "3.0.6" @@ -899,7 +894,7 @@ checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn", ] [[package]] @@ -952,7 +947,7 @@ checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn", ] [[package]] @@ -1064,7 +1059,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn 3.0.6", + "syn", "wasm-bindgen-shared", ] @@ -1126,7 +1121,7 @@ checksum = "33811428bee40dbceb6d545e95754741d17a6aef9a4849f0fd62e2ba4f412a78" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn", "synstructure", ] @@ -1147,7 +1142,7 @@ checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn", "synstructure", ] @@ -1187,7 +1182,7 @@ checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 746461d..6c44ed4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,13 +19,18 @@ path = "src/bin/john-slop-fmt.rs" name = "john-slop-lsp" path = "src/bin/john-slop-lsp.rs" +[features] +default = ["fancy-diagnostics"] +fancy-diagnostics = ["miette/fancy"] + [dependencies] clap = { version = "4.6.7", default-features = false, features = ["derive", "error-context", "help", "std", "suggestions", "usage"] } -miette = { version = "7.6.0", features = ["fancy"] } +miette = { version = "7.6.0", default-features = false } regex = "1.13.1" thiserror = "2.0.21" walkdir = "2.5.0" zip = "8.6.0" [dev-dependencies] +insta = { version = "1.48.0", default-features = false } tempfile = "3.27.0" diff --git a/Jenkinsfile b/Jenkinsfile index af74b5a..3f0f16f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -113,6 +113,21 @@ pipeline { } } + stage('Test Minimal Features') { + steps { + sh ''' + set -eu + + echo "Running tests without default features..." + + cargo test \ + --locked \ + --all-targets \ + --no-default-features + ''' + } + } + stage('Clippy') { steps { sh ''' diff --git a/src/config.rs b/src/config.rs index 659bac1..f95b795 100644 --- a/src/config.rs +++ b/src/config.rs @@ -87,3 +87,47 @@ impl Default for Config { Self::embedded() } } + +#[cfg(test)] +mod tests { + use std::collections::BTreeSet; + + use super::*; + + #[test] + fn embedded_replacements_are_unique_and_ascii() { + let config = Config::embedded(); + let ids = config + .replacements + .iter() + .map(|rule| rule.id) + .collect::>(); + let sources = config + .replacements + .iter() + .map(|rule| rule.source) + .collect::>(); + + assert_eq!(config.replacements.len(), 10); + assert_eq!(ids.len(), config.replacements.len()); + assert_eq!(sources.len(), config.replacements.len()); + assert!( + config + .replacements + .iter() + .all(|rule| !rule.source.is_ascii() && rule.replacement.is_ascii()) + ); + } + + #[test] + fn default_input_limits_match_the_accepted_policy() { + let limits = InputLimits::default(); + + assert_eq!(limits.max_document_bytes, 8 * 1024 * 1024); + assert_eq!(limits.max_archive_bytes, 64 * 1024 * 1024); + assert_eq!(limits.max_expanded_bytes, 256 * 1024 * 1024); + assert_eq!(limits.max_archive_entries, 10_000); + assert_eq!(limits.max_compression_ratio, 100); + assert_eq!(limits.max_walk_depth, 64); + } +} diff --git a/src/model.rs b/src/model.rs index cc84ac7..3d38a60 100644 --- a/src/model.rs +++ b/src/model.rs @@ -132,4 +132,31 @@ mod tests { assert_eq!(Confidence::from_score(73).score(), 73); assert_eq!(Confidence::from_score(255).score(), 100); } + + #[test] + fn source_id_display_distinguishes_all_source_kinds() { + assert_eq!(SourceId::Stdin.to_string(), ""); + assert_eq!( + SourceId::File(PathBuf::from("article.md")).to_string(), + "article.md" + ); + assert_eq!( + SourceId::ArchiveMember { + archive: PathBuf::from("bundle.zip"), + member: PathBuf::from("docs/article.md"), + } + .to_string(), + "bundle.zip::docs/article.md" + ); + } + + #[test] + fn rule_id_has_stable_text_and_ordering() { + let first = RuleId::from_static("alpha-rule"); + let second = RuleId::from_static("beta-rule"); + + assert_eq!(first.as_str(), "alpha-rule"); + assert_eq!(first.to_string(), "alpha-rule"); + assert!(first < second); + } } diff --git a/src/replacement.rs b/src/replacement.rs index da06686..d9f679d 100644 --- a/src/replacement.rs +++ b/src/replacement.rs @@ -31,4 +31,31 @@ mod tests { assert_eq!(edits[0].byte_span, 10..13); assert_eq!(edits[0].replacement, "-"); } + + #[test] + fn plans_multiple_edits_in_source_order_with_utf8_ranges() { + let edits = plan(&Config::embedded(), "a—b−c"); + + assert_eq!( + edits, + vec![ + TextEdit { + byte_span: 1..4, + replacement: "-".to_owned(), + }, + TextEdit { + byte_span: 5..8, + replacement: "-".to_owned(), + }, + ] + ); + } + + #[test] + fn empty_or_ascii_sources_need_no_edits() { + let config = Config::embedded(); + + assert!(plan(&config, "").is_empty()); + assert!(plan(&config, "ordinary-ascii").is_empty()); + } } diff --git a/tasks.md b/tasks.md index 79610f9..44ca037 100644 --- a/tasks.md +++ b/tasks.md @@ -70,7 +70,7 @@ entry do not discard successful documents. - [x] Update the declared Rust toolchain and direct dependencies to their latest stable releases; verify the locked graph with the declared toolchain. -- [ ] Add focused behavioral and snapshot tests, including feature-matrix +- [x] Add focused behavioral and snapshot tests, including feature-matrix coverage, without snapshotting structured domain values unnecessarily. - [ ] Configure Tarpaulin with an enforceable coverage floor around 30%, run `rust_autobadges`, and publish local version/test/coverage badges. diff --git a/tests/cli.rs b/tests/cli.rs index d010735..798b4bd 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -11,11 +11,7 @@ fn help_is_successful_and_names_the_command() { let output = detector().arg("--help").output().expect("run detector"); assert!(output.status.success()); - assert!( - String::from_utf8(output.stdout) - .expect("UTF-8 stdout") - .contains("Usage: john-slop") - ); + insta::assert_snapshot!(String::from_utf8(output.stdout).expect("UTF-8 stdout")); } #[test] @@ -26,6 +22,7 @@ fn invalid_confidence_is_a_usage_error() { .expect("run detector"); assert_eq!(output.status.code(), Some(2)); + insta::assert_snapshot!(String::from_utf8(output.stderr).expect("UTF-8 stderr")); } #[test] diff --git a/tests/snapshots/cli__help_is_successful_and_names_the_command.snap b/tests/snapshots/cli__help_is_successful_and_names_the_command.snap new file mode 100644 index 0000000..b9adf01 --- /dev/null +++ b/tests/snapshots/cli__help_is_successful_and_names_the_command.snap @@ -0,0 +1,18 @@ +--- +source: tests/cli.rs +expression: "String::from_utf8(output.stdout).expect(\"UTF-8 stdout\")" +--- +Inspect files, directories, or ZIP-based documents for low-care signals + +Usage: john-slop [OPTIONS] ... + +Arguments: + ... Files, directories, or supported ZIP-based containers to inspect + +Options: + --fail-confidence + Return exit code 1 when a document reaches this evidence-confidence score [default: 100] + -h, --help + Print help + -V, --version + Print version diff --git a/tests/snapshots/cli__invalid_confidence_is_a_usage_error.snap b/tests/snapshots/cli__invalid_confidence_is_a_usage_error.snap new file mode 100644 index 0000000..535b6cc --- /dev/null +++ b/tests/snapshots/cli__invalid_confidence_is_a_usage_error.snap @@ -0,0 +1,7 @@ +--- +source: tests/cli.rs +expression: "String::from_utf8(output.stderr).expect(\"UTF-8 stderr\")" +--- +error: invalid value '101' for '--fail-confidence ': confidence must be an integer from 0 through 100 + +For more information, try '--help'.