pretty-diff 0.3.0.0 → 0.4.0.0
raw patch · 4 files changed
+65/−41 lines, 4 files
Files
- CHANGELOG.md +6/−2
- pretty-diff.cabal +2/−2
- src/Pretty/Diff.hs +17/−19
- test/Main.hs +40/−18
CHANGELOG.md view
@@ -1,7 +1,11 @@+# 0.4.0.0+- `pretty/above/below` take `Text` instead of `Show a` allowing the user to decide how to turn stuff into a string.+- `pretty` render multiline input nicely+ - config takes a multilineContext to param to specify how much around the diff to+ # 0.3.0.0 -- `pretty/above/below` take `Text` instead of `Show a` allowing the user to decide how to turn stuff into a string.-- Add `prettyMultilines` to render multiline input.+- I messed this release up :-( 0.4.0.0 is correct. # 0.2.0.3
pretty-diff.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: b037055a0de30dc728cde0c1b44091182200bbc9adf3ae7ef583d2d6495921c4+-- hash: eed5c39a0385cbbf94a482ecf959f7f8b11c2359cb954cc2b8b87fb90d9b34e3 name: pretty-diff-version: 0.3.0.0+version: 0.4.0.0 synopsis: Pretty printing a diff of two values. description: Please see the README at <https://github.com/stoeffel/pretty-diff>. category: Diffing
src/Pretty/Diff.hs view
@@ -24,13 +24,12 @@ -- @ module Pretty.Diff ( -- * Configuration- Config (Config, separatorText, wrapping),+ Config (Config, separatorText, wrapping, multilineContext), Wrapping (Wrap, NoWrap),- Context (FullContext, Surrounding),+ MultilineContext (FullContext, Surrounding), -- * pretty printing pretty,- prettyMultilines, above, below, )@@ -86,11 +85,13 @@ -- 00000" -- ▲ -- @- wrapping :: Wrapping+ wrapping :: Wrapping,+ -- | Only used if text passed in is multiline. Options are full or a some surrounding number of lines+ multilineContext :: MultilineContext } instance Default Config where- def = Config {separatorText = Nothing, wrapping = NoWrap}+ def = Config {separatorText = Nothing, wrapping = NoWrap, multilineContext = Surrounding 2 "..."} -- | Define whether or not to wrap the diffing lines. data Wrapping@@ -98,23 +99,20 @@ | NoWrap -- | Define how much context surrounding diffs you'd like to show.-data Context+data MultilineContext = FullContext | Surrounding Int Text -- | Printing a full diff of both values separated by some pipes. pretty :: Config -> Text -> Text -> Text-pretty config x y =- prettyMultilines config FullContext [x] [y]---- | Printing a full diff of both values separated by some pipes.-prettyMultilines :: Config -> Context -> [Text] -> [Text] -> Text-prettyMultilines Config {separatorText, wrapping} context xs ys =- [ zipWith (\x y -> above' wrapping x y) xs ys & extractContext context (False, [], []) & mconcat,- separator separatorText,- zipWith (\x y -> below' wrapping x y) xs ys & extractContext context (False, [], []) & mconcat- ]- & mconcat+pretty Config {separatorText, wrapping, multilineContext} x y =+ let xs = Text.lines x+ ys = Text.lines y+ in [ zipWith (above' wrapping) xs ys & extractContext multilineContext (False, [], []) & mconcat,+ separator separatorText,+ zipWith (below' wrapping) xs ys & extractContext multilineContext (False, [], []) & mconcat+ ]+ & mconcat -- | Printing The first value and the diff indicator above. --@@ -210,8 +208,8 @@ Second -> Just (x, c) Diff.Both x _ -> Just (x, ' ') -extractContext :: Context -> (Bool, [Text], [Text]) -> [(Bool, Text)] -> [Text]-extractContext FullContext _ xs = map (\(_, a) -> a) xs+extractContext :: MultilineContext -> (Bool, [Text], [Text]) -> [(Bool, Text)] -> [Text]+extractContext FullContext _ xs = map snd xs extractContext context@(Surrounding c sep) (hadDiff, acc, before) xs = case xs of [] ->
test/Main.hs view
@@ -134,7 +134,7 @@ testCase "With separator text" $ expectDiffToEqual ( Diff.pretty- Diff.Config+ def { Diff.separatorText = Just "equals", Diff.wrapping = Diff.Wrap 5 }@@ -153,14 +153,13 @@ ] ], testGroup- "prettyMultilines"- [ testCase "Multiline content with full context" $+ "pretty (multiline)"+ [ testCase "Multiline content with full multiline context" $ expectDiffToEqual- ( Diff.prettyMultilines- def- Diff.FullContext- ["a", "b", "c", "d", "e", "f"]- ["a", "b", "c", "D", "e", "f"]+ ( Diff.pretty+ def {Diff.multilineContext = Diff.FullContext}+ "a\nb\nc\nd\ne\nf"+ "a\nb\nc\nD\ne\nf" ) [ "a", "b",@@ -181,20 +180,44 @@ "f" ] ],- testCase "Multiline content with narrow context" $+ testCase "Multiline content with default multiline config" $ expectDiffToEqual- ( Diff.prettyMultilines+ ( Diff.pretty def- (Diff.Surrounding 1 "...")- ["a", "b", "c", "d", "e", "f"]- ["a", "b", "c", "D", "e", "f"]+ "a\nb\nc\nd\ne\nf"+ "a\nb\nc\nD\ne\nf" ) [ "...",+ "b", "c", "▼", "d", "e",+ "f",+ "╷",+ "│",+ "╵", "...",+ "b",+ "c",+ "D",+ "▲",+ "e",+ "f"+ ],+ testCase "Multiline content with narrow multiline context" $+ expectDiffToEqual+ ( Diff.pretty+ def {Diff.multilineContext = Diff.Surrounding 1 "..."}+ "a\nb\nc\nd\ne\nf"+ "a\nb\nc\nD\ne\nf"+ )+ [ "...",+ "c",+ "▼",+ "d",+ "e",+ "...", "╷", "│", "╵",@@ -207,11 +230,10 @@ ], testCase "Multiline content with narrow context and multiple diffs" $ expectDiffToEqual- ( Diff.prettyMultilines- def {Diff.wrapping = Diff.Wrap 3}- (Diff.Surrounding 1 "...")- ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]- ["A", "b", "c", "D", "e", "f", "g", "h", "i", "JJJJJJ"]+ ( Diff.pretty+ def {Diff.wrapping = Diff.Wrap 3, Diff.multilineContext = Diff.Surrounding 1 "..."}+ "a\nb\nc\nd\ne\nf\ng\nh\ni\nj"+ "A\nb\nc\nD\ne\nf\ng\nh\ni\nJJJJJJ" ) [ "▼", "a",