mirror of
https://github.com/crate-ci/typos.git
synced 2024-12-23 08:02:15 -05:00
test(cli): Ensure we apply corrections
This commit is contained in:
parent
cb02353b5a
commit
d7978658d4
2 changed files with 64 additions and 1 deletions
|
@ -64,7 +64,6 @@ fn process_word<'w, 's: 'w>(
|
||||||
|
|
||||||
/// An invalid term found in the buffer.
|
/// An invalid term found in the buffer.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
#[non_exhaustive]
|
|
||||||
pub struct Typo<'m> {
|
pub struct Typo<'m> {
|
||||||
pub byte_offset: usize,
|
pub byte_offset: usize,
|
||||||
pub typo: Cow<'m, str>,
|
pub typo: Cow<'m, str>,
|
||||||
|
|
64
src/file.rs
64
src/file.rs
|
@ -609,3 +609,67 @@ fn walk_entry(
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn fix_simple(line: &str, corrections: Vec<(usize, &'static str, &'static str)>) -> String {
|
||||||
|
let line = line.as_bytes().to_vec();
|
||||||
|
let corrections: Vec<_> = corrections
|
||||||
|
.into_iter()
|
||||||
|
.map(|(byte_offset, typo, correction)| typos::Typo {
|
||||||
|
byte_offset,
|
||||||
|
typo: typo.into(),
|
||||||
|
corrections: typos::Status::Corrections(vec![correction.into()]),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let actual = fix_buffer(line, corrections.into_iter());
|
||||||
|
String::from_utf8(actual).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fix_buffer_single() {
|
||||||
|
let actual = fix_simple("foo foo foo", vec![(4, "foo", "bar")]);
|
||||||
|
assert_eq!(actual, "foo bar foo");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fix_buffer_single_grow() {
|
||||||
|
let actual = fix_simple("foo foo foo", vec![(4, "foo", "happy")]);
|
||||||
|
assert_eq!(actual, "foo happy foo");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fix_buffer_single_shrink() {
|
||||||
|
let actual = fix_simple("foo foo foo", vec![(4, "foo", "if")]);
|
||||||
|
assert_eq!(actual, "foo if foo");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fix_buffer_start() {
|
||||||
|
let actual = fix_simple("foo foo foo", vec![(0, "foo", "bar")]);
|
||||||
|
assert_eq!(actual, "bar foo foo");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fix_buffer_end() {
|
||||||
|
let actual = fix_simple("foo foo foo", vec![(8, "foo", "bar")]);
|
||||||
|
assert_eq!(actual, "foo foo bar");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fix_buffer_end_grow() {
|
||||||
|
let actual = fix_simple("foo foo foo", vec![(8, "foo", "happy")]);
|
||||||
|
assert_eq!(actual, "foo foo happy");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fix_buffer_multiple() {
|
||||||
|
let actual = fix_simple(
|
||||||
|
"foo foo foo",
|
||||||
|
vec![(4, "foo", "happy"), (8, "foo", "world")],
|
||||||
|
);
|
||||||
|
assert_eq!(actual, "foo happy world");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue