Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add proptest to test diff input for crashes #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -27,3 +27,6 @@ diff = "0.1.12"
[target.'cfg(windows)'.dependencies]
output_vt100 = "0.1.2"
ctor = "0.1.9"

[dev-dependencies]
proptest = "1.0.0"
24 changes: 24 additions & 0 deletions src/printer.rs
Expand Up @@ -197,6 +197,30 @@ fn write_inline_diff<TWrite: fmt::Write>(f: &mut TWrite, left: &str, right: &str
#[cfg(test)]
mod test {
use super::*;
use proptest::prelude::*;
use proptest::proptest;

/// Generate a random number of random lines, joined together with newline.
fn lines_strategy() -> BoxedStrategy<String> {
proptest::collection::vec("\\PC*", 1..16)
.prop_map(|vec| vec.join("\n"))
.boxed()
}

// Check our writer functions don't crash with random arbitrary input.
proptest! {
#[test]
fn write_inline_diff_arbitary(ref left in "\\PC*", ref right in "\\PC*") {
let mut f = String::new();
write_inline_diff(&mut f, left, right).unwrap();
}

#[test]
fn write_diff_arbitary(ref left in lines_strategy(), ref right in lines_strategy()) {
let mut f = String::new();
write_inline_diff(&mut f, left, right).unwrap();
}
}

// ANSI terminal codes used in our outputs.
//
Expand Down