Closed colin-kiegel closed 7 years ago
The results look like this: https://travis-ci.org/johannhof/difference.rs/jobs/220621495#L289
I've baked a const DEBUG: bool
into the test. Setting it to true will print all assertions to stdout.
Let me know if I should change anything. :-)
PS: The CI tests only fail, because this unveils some edge case bugs.
Oh, and please rebase on master and run the latest rustfmt :)
Thanks again!
done :-)
Great, thanks. I'll open an issue for fixing the fuzzing results.
This adds fuzzy testing via quickcheck :-)
The basic idea is that each sequence set of differences can be asserted
This internally calls
Changeset::new("a b : g", "b a : b b : g g", " ")
, which leads to the differences[Same("") Rem("a") Same("b") Add("a") Same(":") Rem("g") Add("b b") Same(": g") Add("g")]
.We can assert them one by one, while stripping our slices accordingly.
assert `Same("")` (old: "a b : g", new: "b a : b b : g g")
assert `Rem("a")` (old: "a b : g", new: "b a : b b : g g")
assert `Same("b")` (old: "b : g", new: "b a : b b : g g")
assert `Add("a")` (old: ": g", new: "a : b b : g g")
assert `Same(":")` (old: ": g", new: ": b b : g g")
assert `Rem("g")` (old: "g", new: "b b : g g")
assert `Add("b b")` (old: "", new: "b b : g g")
assert `Same(": g")` (old: "", new: ": g g")
Ok, now the last assertion fails with
Error: `Same(": g")` does not match `old` at "" for Changeset::new("a b : g", "b a : b b : g g", " ") -> [Same("") Rem("a") Same("b") Add("a") Same(":") Rem("g") Add("b b") Same(": g") Add("g")]
Fuzzy Testing
Now the interesting part is that we can use quickcheck to generate random inputs. These tests pass most of the time, but occasionally quickcheck indeed finds a bogus combination like:
Error: `Same("\u{1} ")` does not match `old` at "\u{1}" for Changeset::new("\u{0} \u{0} \u{1}", "\u{1} \u{0}", " ") -> [Same("") Add("\u{1}") Same("\u{0}") Rem("\u{0}") Same("\u{1} ")]
Here the output does not look so nice, because quickcheck tries all that unicode has to offer. Theoretically it would be possible to restrict the tests to latin characters, but that would contradict the general idea of fuzzy testing a little.