Skip to content

Commit

Permalink
drop speculate, switch to plain #[test]
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshkukreti committed Feb 1, 2024
1 parent 020d411 commit 18dc57d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 121 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ homepage = "https://github.com/utkarshkukreti/diff.rs"
repository = "https://github.com/utkarshkukreti/diff.rs"

[dev-dependencies]
speculate = "0.1.2"
quickcheck = "1.0.3"
criterion = "0.5.1"

Expand Down
208 changes: 88 additions & 120 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
extern crate diff;
extern crate quickcheck;
extern crate speculate;

use diff::Result::*;
use speculate::speculate;

pub fn undiff<T: Clone>(diff: &[::diff::Result<&T>]) -> (Vec<T>, Vec<T>) {
let (mut left, mut right) = (vec![], vec![]);
Expand Down Expand Up @@ -58,143 +56,115 @@ pub fn undiff_chars(diff: &[::diff::Result<char>]) -> (String, String) {
)
}

speculate! {
describe "slice" {
fn go<T>(left: &[T], right: &[T], len: usize) where
T: Clone + ::std::fmt::Debug + PartialEq
{
let diff = ::diff::slice(left, right);
assert_eq!(diff.len(), len);
let (left_, right_) = undiff(&diff);
assert_eq!(left, &left_[..]);
assert_eq!(right, &right_[..]);
}
#[test]
fn test_slice() {
fn go<T>(left: &[T], right: &[T], len: usize)
where
T: Clone + ::std::fmt::Debug + PartialEq,
{
let diff = ::diff::slice(left, right);
assert_eq!(diff.len(), len);
let (left_, right_) = undiff(&diff);
assert_eq!(left, &left_[..]);
assert_eq!(right, &right_[..]);
}

test "empty slices" {
let slice: &[()] = &[];
go(slice, slice, 0);
}
let slice: &[()] = &[];
go(slice, slice, 0);

test "equal + non-empty slices" {
let slice = [1, 2, 3];
go(&slice, &slice, 3);
}
let slice = [1, 2, 3];
go(&slice, &slice, 3);

test "left empty, right non-empty" {
let slice = [1, 2, 3];
go(&slice, &[], 3);
}
let slice = [1, 2, 3];
go(&slice, &[], 3);

test "left non-empty, right empty" {
let slice = [1, 2, 3];
go(&[], &slice, 3);
}
let slice = [1, 2, 3];
go(&[], &slice, 3);

test "misc 1" {
let left = [1, 2, 3, 4, 1, 3];
let right = [1, 4, 1, 1];
go(&left, &right, 7);
}
let left = [1, 2, 3, 4, 1, 3];
let right = [1, 4, 1, 1];
go(&left, &right, 7);

test "misc 2" {
let left = [1, 2, 1, 2, 3, 2, 2, 3, 1, 3];
let right = [3, 3, 1, 2, 3, 1, 2, 3, 4, 1];
go(&left, &right, 14);
}
let left = [1, 2, 1, 2, 3, 2, 2, 3, 1, 3];
let right = [3, 3, 1, 2, 3, 1, 2, 3, 4, 1];
go(&left, &right, 14);

test "misc 3" {
let left = [1, 3, 4];
let right = [2, 3, 4];
go(&left, &right, 4);
}
let left = [1, 3, 4];
let right = [2, 3, 4];
go(&left, &right, 4);
}

test "quickcheck" {
fn prop(left: Vec<i32>, right: Vec<i32>) -> bool {
let diff = ::diff::slice(&left, &right);
let (left_, right_) = undiff(&diff);
left == left_[..] && right == right_[..]
}
#[test]
fn test_slice_quickcheck() {
fn prop(left: Vec<i32>, right: Vec<i32>) -> bool {
let diff = ::diff::slice(&left, &right);
let (left_, right_) = undiff(&diff);
left == left_[..] && right == right_[..]
}

::quickcheck::quickcheck(prop as fn(Vec<i32>, Vec<i32>) -> bool);
}
::quickcheck::quickcheck(prop as fn(Vec<i32>, Vec<i32>) -> bool);
}

#[test]
fn test_lines() {
fn go(left: &str, right: &str, len: usize) {
let diff = ::diff::lines(left, right);
assert_eq!(diff.len(), len);
let (left_, right_) = undiff_str(&diff);
assert_eq!(left, left_.join("\n"));
assert_eq!(right, right_.join("\n"));
}

describe "lines" {
fn go(left: &str, right: &str, len: usize) {
let diff = ::diff::lines(left, right);
assert_eq!(diff.len(), len);
let (left_, right_) = undiff_str(&diff);
assert_eq!(left, left_.join("\n"));
assert_eq!(right, right_.join("\n"));
}
go("", "", 0);

test "both empty" {
go("", "", 0);
}
go("foo", "", 1);
go("", "foo", 1);

test "one empty" {
go("foo", "", 1);
go("", "foo", 1);
}
go("foo\nbar", "foo\nbar", 2);

test "both equal and non-empty" {
go("foo\nbar", "foo\nbar", 2);
}
go("foo\nbar\nbaz", "foo\nbaz\nquux", 4);

test "misc 1" {
go("foo\nbar\nbaz", "foo\nbaz\nquux", 4);
}
// #10
go("a\nb\nc", "a\nb\nc\n", 4);
go("a\nb\nc\n", "a\nb\nc", 4);
let left = "a\nb\n\nc\n\n\n";
let right = "a\n\n\nc\n\n";
go(left, right, 8);
go(right, left, 8);
}

test "#10" {
go("a\nb\nc", "a\nb\nc\n", 4);
go("a\nb\nc\n", "a\nb\nc", 4);
let left = "a\nb\n\nc\n\n\n";
let right = "a\n\n\nc\n\n";
go(left, right, 8);
go(right, left, 8);
}
#[test]
fn test_chars() {
fn go(left: &str, right: &str, len: usize) {
let diff = ::diff::chars(left, right);
assert_eq!(diff.len(), len);
let (left_, right_) = undiff_chars(&diff);
assert_eq!(left, left_);
assert_eq!(right, right_);
}

describe "chars" {
fn go(left: &str, right: &str, len: usize) {
let diff = ::diff::chars(left, right);
assert_eq!(diff.len(), len);
let (left_, right_) = undiff_chars(&diff);
assert_eq!(left, left_);
assert_eq!(right, right_);
}
go("", "", 0);

test "both empty" {
go("", "", 0);
}

test "one empty" {
go("foo", "", 3);
go("", "foo", 3);
}
go("foo", "", 3);
go("", "foo", 3);

test "both equal and non-empty" {
go("foo bar", "foo bar", 7);
}
go("foo bar", "foo bar", 7);

test "misc 1" {
go("foo bar baz", "foo baz quux", 16);
}
}
go("foo bar baz", "foo baz quux", 16);
}

describe "issues" {
test "#4" {
assert_eq!(::diff::slice(&[1], &[2]), vec![Left(&1),
Right(&2)]);
assert_eq!(::diff::lines("a", "b"), vec![Left("a"),
Right("b")]);
}
#[test]
fn test_issue_4() {
assert_eq!(::diff::slice(&[1], &[2]), vec![Left(&1), Right(&2)]);
assert_eq!(::diff::lines("a", "b"), vec![Left("a"), Right("b")]);
}

test "#6" {
// This produced an overflow in the lines computation because it
// was not accounting for the fact that the "right" length was
// less than the "left" length.
let expected = r#"
#[test]
fn test_issue_6() {
// This produced an overflow in the lines computation because it
// was not accounting for the fact that the "right" length was
// less than the "left" length.
let expected = r#"
BacktraceNode {
parents: [
BacktraceNode {
Expand All @@ -209,7 +179,7 @@ BacktraceNode {
}
]
}"#;
let actual = r#"
let actual = r#"
BacktraceNode {
parents: [
BacktraceNode {
Expand All @@ -227,9 +197,7 @@ BacktraceNode {
}
]
}"#;
::diff::lines(actual, expected);
}
}
::diff::lines(actual, expected);
}

#[test]
Expand Down

0 comments on commit 18dc57d

Please sign in to comment.