test: exercise replacement properties
Rust CI JohnSlop passed all CI checks.
Gitea/john_slop/pipeline/head This commit looks good
Details
Rust CI JohnSlop passed all CI checks.
Gitea/john_slop/pipeline/head This commit looks good
Details
This commit is contained in:
parent
d98db5252d
commit
39c6eacdf3
|
|
@ -234,4 +234,56 @@ mod tests {
|
|||
Err(ReplacementError::OverlappingEdits { offset: 1 })
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generated_sequences_are_stable_non_overlapping_and_idempotent() {
|
||||
let config = Config::embedded();
|
||||
let alphabet = ["a", "é", "—", "−", "\r", "\n"];
|
||||
|
||||
for first in alphabet {
|
||||
for second in alphabet {
|
||||
for third in alphabet {
|
||||
for fourth in alphabet {
|
||||
let source = [first, second, third, fourth].concat();
|
||||
let edits = plan(&config, &source);
|
||||
assert_eq!(edits, plan(&config, &source));
|
||||
for edit in &edits {
|
||||
assert!(source.is_char_boundary(edit.byte_span.start));
|
||||
assert!(source.is_char_boundary(edit.byte_span.end));
|
||||
}
|
||||
assert!(
|
||||
edits
|
||||
.windows(2)
|
||||
.all(|pair| { pair[0].byte_span.end <= pair[1].byte_span.start })
|
||||
);
|
||||
|
||||
let formatted = apply(&source, &edits).unwrap();
|
||||
assert_eq!(
|
||||
source
|
||||
.chars()
|
||||
.filter(|character| *character == '\r')
|
||||
.count(),
|
||||
formatted
|
||||
.chars()
|
||||
.filter(|character| *character == '\r')
|
||||
.count()
|
||||
);
|
||||
assert_eq!(
|
||||
source
|
||||
.chars()
|
||||
.filter(|character| *character == '\n')
|
||||
.count(),
|
||||
formatted
|
||||
.chars()
|
||||
.filter(|character| *character == '\n')
|
||||
.count()
|
||||
);
|
||||
let second_edits = plan(&config, &formatted);
|
||||
assert!(second_edits.is_empty());
|
||||
assert_eq!(apply(&formatted, &second_edits).unwrap(), formatted);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue