example: showcase all printable ASCII replacements
This commit is contained in:
parent
8d927f1699
commit
3281bd5a44
|
|
@ -5,7 +5,7 @@ coverage = 92.23
|
|||
|
||||
[last_run_clean.run_duration]
|
||||
secs = 31
|
||||
nanos = 493686186
|
||||
nanos = 461842752
|
||||
|
||||
[last_run_incremental]
|
||||
run_status = "Success"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ All notable changes to John Slop are recorded here. The format follows
|
|||
- Restructured the README and documentation index as a progressive path from
|
||||
quickstart to usage guides, with engineering detail in a dedicated advanced
|
||||
guide.
|
||||
- Added an opt-in Rust example that maps fullwidth Unicode forms to all 95
|
||||
printable ASCII targets while leaving production defaults unchanged.
|
||||
- Adopted the measured three-package Cargo workspace. Shared package metadata,
|
||||
dependency requirements, and lint policy now use workspace inheritance while
|
||||
the reusable core remains isolated from CLI, async, and LSP dependencies.
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ John Slop binaries:
|
|||
cargo run --example analyze_text
|
||||
cargo run --example analyze_path -- examples/fixtures
|
||||
cargo run --example plan_replacements
|
||||
cargo run --example ascii_replacements
|
||||
```
|
||||
|
||||
- `analyze_text` analyzes an in-memory prose snapshot and prints its explainable
|
||||
|
|
@ -15,6 +16,8 @@ cargo run --example plan_replacements
|
|||
optional path defaults to `examples/fixtures`.
|
||||
- `plan_replacements` prints the exact UTF-8 byte edits shared by the formatter
|
||||
and LSP quick fixes.
|
||||
- `ascii_replacements` builds an opt-in catalog through the public API and maps
|
||||
fullwidth characters to all 95 printable ASCII targets.
|
||||
|
||||
These examples use embedded defaults so their behavior does not depend on a
|
||||
developer's user configuration. Applications that want normal configuration
|
||||
|
|
@ -44,6 +47,24 @@ expected ASCII file. The manifest also names `lsp` as a consumer, and the
|
|||
in-process protocol suite proves that applying LSP edits produces the same bytes
|
||||
as the formatter.
|
||||
|
||||
## Printable ASCII replacement showcase
|
||||
|
||||
[`ascii_replacements.rs`](ascii_replacements.rs) extends the embedded defaults
|
||||
in memory with fullwidth mappings for ASCII `!` through `~` and maps ideographic
|
||||
space to ASCII space. Its [Unicode input](ascii-replacement-showcase/fullwidth.txt)
|
||||
and [expected output](ascii-replacement-showcase/ascii.txt) display all 95
|
||||
printable ASCII targets in one place:
|
||||
|
||||
```sh
|
||||
cargo run --example ascii_replacements
|
||||
```
|
||||
|
||||
The example reports 95 planned edits on stderr and writes only the transformed
|
||||
fixture to stdout. These broad letter, digit, punctuation, and space mappings
|
||||
are an API/configuration demonstration, not additions to the production
|
||||
defaults or a recommendation to rewrite arbitrary multilingual text. The
|
||||
embedded catalog remains limited to individually reviewed conservative rules.
|
||||
|
||||
## Expected-failure diagnostic showcase
|
||||
|
||||
[`diagnostic-showcase.txt`](diagnostic-showcase.txt) contains every currently
|
||||
|
|
@ -72,5 +93,5 @@ with capture disabled to print the complete report:
|
|||
|
||||
```sh
|
||||
cargo test --test example_fixtures \
|
||||
diagnostic_showcase_is_an_expected_threshold_failure -- --nocapture
|
||||
diagnostic_showcase_spans_prose_source_and_severities -- --nocapture
|
||||
```
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Fullwidth ASCII showcase:
|
||||
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Fullwidth ASCII showcase:
|
||||
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
//! Showcase opt-in replacements for every printable ASCII target.
|
||||
|
||||
use std::{collections::BTreeSet, io::Write};
|
||||
|
||||
use john_slop::{
|
||||
Config, ConfigValidationError, ReplacementRule, apply_replacements, plan_replacements,
|
||||
};
|
||||
|
||||
const SOURCE: &str = include_str!("ascii-replacement-showcase/fullwidth.txt");
|
||||
|
||||
fn showcase_config() -> Result<Config, ConfigValidationError> {
|
||||
let mut config = Config::embedded();
|
||||
let embedded_sources = config
|
||||
.replacements
|
||||
.iter()
|
||||
.map(|rule| rule.source.clone())
|
||||
.collect::<BTreeSet<_>>();
|
||||
let mappings = std::iter::once(('\u{3000}', ' ')).chain((b'!'..=b'~').map(|ascii| {
|
||||
// U+FF01..=U+FF5E is a contiguous block of valid Unicode scalar values.
|
||||
let fullwidth = char::from_u32(u32::from(ascii) + 0xfee0)
|
||||
.expect("the fullwidth ASCII range contains valid scalar values");
|
||||
(fullwidth, char::from(ascii))
|
||||
}));
|
||||
|
||||
for (source, target) in mappings {
|
||||
if embedded_sources.contains(&source.to_string()) {
|
||||
continue;
|
||||
}
|
||||
config.replacements.push(ReplacementRule {
|
||||
id: format!("showcase-fullwidth-{:04x}", u32::from(source)),
|
||||
source: source.to_string(),
|
||||
replacement: target.to_string(),
|
||||
rationale: format!(
|
||||
"Demonstrate an opt-in mapping from U+{:04X} to printable ASCII.",
|
||||
u32::from(source)
|
||||
),
|
||||
enabled: true,
|
||||
});
|
||||
}
|
||||
|
||||
config.validate()?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = showcase_config()?;
|
||||
let edits = plan_replacements(&config, SOURCE);
|
||||
let formatted = apply_replacements(SOURCE, &edits)?;
|
||||
|
||||
eprintln!(
|
||||
"planned {} opt-in replacements covering ASCII space through tilde",
|
||||
edits.len()
|
||||
);
|
||||
std::io::stdout().write_all(formatted.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const EXPECTED: &str = include_str!("ascii-replacement-showcase/ascii.txt");
|
||||
|
||||
#[test]
|
||||
fn showcase_maps_each_printable_ascii_target_once() {
|
||||
let config = showcase_config().expect("build valid showcase configuration");
|
||||
let edits = plan_replacements(&config, SOURCE);
|
||||
let targets = edits
|
||||
.iter()
|
||||
.map(|edit| edit.replacement.as_bytes()[0])
|
||||
.collect::<BTreeSet<_>>();
|
||||
|
||||
assert_eq!(edits.len(), 95);
|
||||
assert_eq!(targets, (b' '..=b'~').collect());
|
||||
assert_eq!(
|
||||
apply_replacements(SOURCE, &edits).expect("apply non-overlapping showcase edits"),
|
||||
EXPECTED
|
||||
);
|
||||
}
|
||||
}
|
||||
8
tasks.md
8
tasks.md
|
|
@ -446,7 +446,7 @@ formatting, line-length, and all-feature rustdoc checks pass.
|
|||
|
||||
## Milestone 18 — Full printable-ASCII replacement showcase
|
||||
|
||||
- [ ] Add an opt-in Rust example and checked-in input/expected-output fixtures
|
||||
- [x] Add an opt-in Rust example and checked-in input/expected-output fixtures
|
||||
that map the fullwidth Unicode forms of every printable non-space ASCII
|
||||
character, plus ideographic space, to all 95 printable ASCII targets. Reuse
|
||||
the embedded fullwidth-hyphen rule, construct the remaining showcase-only
|
||||
|
|
@ -459,6 +459,12 @@ through tilde is represented once as a target; documentation clearly labels the
|
|||
mapping as an API/configuration showcase rather than a recommended universal
|
||||
rewrite policy; both feature matrices and the coverage floor pass.
|
||||
|
||||
Accepted on 2026-09-29 after the example produced exactly 95 edits whose unique
|
||||
targets span ASCII space (`0x20`) through tilde (`0x7e`) and matched the
|
||||
checked-in output byte for byte. Formatting, Clippy, rustdoc, both feature
|
||||
matrices, and Tarpaulin passed; production coverage remains 92.23%
|
||||
(1,342/1,455 lines).
|
||||
|
||||
## Deferred by design
|
||||
|
||||
- Statistical or model-based authorship classification.
|
||||
|
|
|
|||
Loading…
Reference in New Issue