render_example_test.gno
2.00 Kb · 36 lines
1package myersdiffdemo
2
3// ExampleRender pins the realm Render output as a testable example.
4//
5// The block below is copied verbatim from what gno printed, never hand typed:
6// every diff line and every count in it is computed by the library under test,
7// so a change in the algorithm shows up here as a diff.
8func ExampleRender() {
9 print(Render(""))
10 // Output:
11 // # Myers diff
12 //
13 // Demo of the [`p/moul/x/daily/myersdiff`](/p/moul/x/daily/myersdiff/v0) library: the shortest edit script between two documents, the algorithm behind `git diff`.
14 //
15 // It walks a grid whose diagonals are matching lines, taking the furthest-reaching path at each round, and stops the first time a path reaches the far corner. That round number is the number of edits, and it is minimal because no shorter path was available at any earlier round.
16 //
17 // ## The scenarios
18 //
19 // | scenario | edits | minimal | what it shows |
20 // | --- | --- | --- | --- |
21 // | [patch](/r/moul/x/daily/myersdiffdemo/v0:patch) | 5 | yes | A small patch in a large file |
22 // | [insert](/r/moul/x/daily/myersdiffdemo/v0:insert) | 3 | yes | Appending to an empty document |
23 // | [move](/r/moul/x/daily/myersdiffdemo/v0:move) | 2 | yes | A moved line is a delete and an insert |
24 // | [starved](/r/moul/x/daily/myersdiffdemo/v0:starved) | 10 | no | A budget too small for the answer |
25 //
26 // ## Context width
27 //
28 // Append a number to widen or narrow the unchanged lines printed around each change: [`patch/0`](/r/moul/x/daily/myersdiffdemo/v0:patch/0) shows the changes alone, [`patch/6`](/r/moul/x/daily/myersdiffdemo/v0:patch/6) shows the whole file as one hunk. Anything out of range is clamped to 0..6.
29 //
30 // ## API
31 //
32 // - `Lines(a, b string) Script` is the whole surface for text.
33 // - `Script.Apply(a []string) ([]string, bool)` replays the script and says whether it describes that document.
34 // - `Hunks(s Script, context int) []Hunk` groups the script the way a review tool prints it.
35 // - `Unified(a, b string, context int) string` is the two above, as text.
36}