0 | module Evince.Diff
 1 |
 2 | import public Text.Show.Diff
 3 | import Text.Show.Pretty
 4 | import Evince.Core
 5 |
 6 | ||| Render a single LineDiff as plain text with a two-character prefix.
 7 | export
 8 | renderLineDiffPlain : LineDiff -> String
 9 | renderLineDiffPlain (LineSame x)    = "  " ++ x
10 | renderLineDiffPlain (LineRemoved x) = "- " ++ x
11 | renderLineDiffPlain (LineAdded x)   = "+ " ++ x
12 |
13 | ||| Compute a structural diff between two Show-output strings. Returns Nothing
14 | ||| if either value can't be parsed or if they are structurally identical.
15 | export
16 | structuralDiff : (expected : String) -> (actual : String) -> Maybe (List LineDiff)
17 | structuralDiff expected actual = do
18 |   ve <- parseValue expected
19 |   va <- parseValue actual
20 |   guard (ve /= va)
21 |   Just $ toLineDiff (valueDiff ve va)
22 |
23 | ||| Try to extract a structural diff from a FailureInfo. Returns the reason and
24 | ||| diff lines for ExpectedButGot failures that can be structurally parsed,
25 | ||| Nothing otherwise.
26 | export
27 | failureDiff : FailureInfo -> Maybe (String, List LineDiff)
28 | failureDiff (ExpectedButGot reason expected actual) = do
29 |   diffs <- structuralDiff expected actual
30 |   Just (reason, diffs)
31 | failureDiff _ = Nothing
32 |