Documentation ¶
Overview ¶
Package difftest implement test based on diffing serialized string output
User provides a function that get a input path and input string and returns a output path and output string. Content of output path and output string is compared and if there is a difference the test fails with a diff.
Test inputs are read from files matching Pattern from Path.
Note that output path can be the same as input which useful if the function implements some kind of transcript that includes both input and output.
Index ¶
- func Diff(oldName string, old []byte, newName string, new_ []byte) []byte
- func Error(t tf, expected string, actual string)
- func ErrorEx(t tf, color bool, expected string, actual string)
- func Fatal(t tf, expected string, actual string)
- func FatalEx(t tf, color bool, expected string, actual string)
- func Test(t *testing.T, pattern string, fn Fn)
- func TestWithOptions(t *testing.T, opts Options)
- type Fn
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Diff ¶ added in v0.11.0
Diff returns an anchored diff of the two texts old and new in the “unified diff” format. If old and new are identical, Diff returns a nil slice (no output).
Unix diff implementations typically look for a diff with the smallest number of lines inserted and removed, which can in the worst case take time quadratic in the number of lines in the texts. As a result, many implementations either can be made to run for a long time or cut off the search after a predetermined amount of work.
In contrast, this implementation looks for a diff with the smallest number of “unique” lines inserted and removed, where unique means a line that appears just once in both old and new. We call this an “anchored diff” because the unique lines anchor the chosen matching regions. An anchored diff is usually clearer than a standard diff, because the algorithm does not try to reuse unrelated blank lines or closing braces. The algorithm also guarantees to run in O(n log n) time instead of the standard O(n²) time.
Some systems call this approach a “patience diff,” named for the “patience sorting” algorithm, itself named for a solitaire card game. We avoid that name for two reasons. First, the name has been used for a few different variants of the algorithm, so it is imprecise. Second, the name is frequently interpreted as meaning that you have to wait longer (to be patient) for the diff, meaning that it is a slower algorithm, when in fact the algorithm is faster than the standard one.