packages feed

Diff 0.4.0 → 0.4.1

raw patch · 5 files changed

+95/−10 lines, 5 filessetup-changednew-uploaderPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Algorithm.DiffContext: getContextDiffOld :: Eq a => Int -> [a] -> [a] -> ContextDiff a

Files

Diff.cabal view
@@ -1,5 +1,5 @@ name:                Diff-version:             0.4.0+version:             0.4.1 synopsis:            O(ND) diff algorithm in haskell. description:         Implementation of the standard diff algorithm, and utilities for pretty printing. category:            Algorithms@@ -9,9 +9,10 @@ maintainer:          s.clover@gmail.com Tested-With:         GHC == 7.8.4 Build-Type:          Simple-Cabal-Version:       >= 1.8+Cabal-Version:       >= 1.10  library+  default-language: Haskell2010   build-depends:   base >= 3 && <= 6, array, pretty >= 1.1   hs-source-dirs:  src   exposed-modules:@@ -21,10 +22,11 @@   ghc-options:     -O2 -Wall -funbox-strict-fields  source-repository head-  type:      darcs-  location:  http://hub.darcs.net/sterlingclover/Diff+  type:      git+  location:  http://github.com/seereason/Diff  test-suite diff-tests+  default-language: Haskell2010   type: exitcode-stdio-1.0   hs-source-dirs: test, src   main-is: Test.hs
− Setup.hs
@@ -1,3 +0,0 @@-#!/usr/bin/env runhaskell-import Distribution.Simple-main = defaultMain
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
src/Data/Algorithm/DiffContext.hs view
@@ -12,6 +12,7 @@ ----------------------------------------------------------------------------- module Data.Algorithm.DiffContext     ( getContextDiff+    , getContextDiffOld     , prettyContextDiff     ) where @@ -22,12 +23,79 @@  type ContextDiff c = [[Diff [c]]] +-- | See https://github.com/haskell/containers/issues/424+groupBy' :: (a -> a -> Bool) -> [a] -> [[a]]+groupBy' _ [] = []+groupBy' eq (x : xs) = go [x] xs+    where+      go (x : xs) (y : zs) | eq x y = go (y : x : xs) zs+      go g (y : zs) = reverse g : go [y] zs+      go g [] = [reverse g]++-- | See https://github.com/seereason/Diff/commit/35596ca45fdd6ee2559cf610bef7a86b4617988a.+-- The original 'getContextDiff' omitted trailing context in diff hunks.+-- This new one corrects the issue.  Here is the example from the test+-- suite:+--+--     > prettyContextDiff (text "file1") (text "file2") text (getContextDiffOld 2 (lines textA) (lines textB))+--     --- file1+--     +++ file2+--     @@+--      a+--      b+--     -c+--     @@+--      d+--      e+--     @@+--      i+--      j+--     -k+--+--     > prettyContextDiff (text "file1") (text "file2") text (getContextDiff 2 (lines textA) (lines textB))+--     --- file1+--     +++ file2+--     @@+--      a+--      b+--     -c+--      d+--      e+--     @@+--      i+--      j+--     -k+getContextDiff :: Eq a => Int -> [a] -> [a] -> ContextDiff a+getContextDiff context a b =+    groupBy' (\a b -> not (isBoth a && isBoth b)) $ doPrefix $ getGroupedDiff a b+    where+      isBoth (Both {}) = True+      isBoth _ = False+      -- Handle the common text leading up to a diff.+      doPrefix [] = []+      doPrefix [Both _ _] = []+      doPrefix (Both xs ys : more) =+          Both (drop (max 0 (length xs - context)) xs)+               (drop (max 0 (length ys - context)) ys) : doSuffix more+      -- Prefix finished, do the diff then the following suffix+      doPrefix (d : ds) = doSuffix (d : ds)+      -- Handle the common text following a diff.+      doSuffix [] = []+      doSuffix [Both xs ys] = [Both (take context xs) (take context ys)]+      doSuffix (Both xs ys : more)+          | length xs <= context * 2 =+              Both xs ys : doPrefix more+      doSuffix (Both xs ys : more) =+          Both (take context xs) (take context ys)+                   : doPrefix (Both (drop context xs) (drop context ys) : more)+      doSuffix (d : ds) = d : doSuffix ds+ -- | Do a grouped diff and then split up the chunks into runs that -- contain differences surrounded by N lines of unchanged text.  If -- there is less then 2N+1 lines of unchanged text between two -- changes, the runs are left merged.-getContextDiff :: Eq a => Int -> [a] -> [a] -> ContextDiff a-getContextDiff context a b =+getContextDiffOld :: Eq a => Int -> [a] -> [a] -> ContextDiff a+getContextDiffOld context a b =     group $ swap $ trimTail $ trimHead $ concatMap split $ getGroupedDiff a b     where       -- Drop the middle elements of a run of Both if there are more
test/Test.hs view
@@ -4,6 +4,7 @@ import Test.Framework.Providers.QuickCheck2 (testProperty) import Test.QuickCheck import Data.Algorithm.Diff+import Data.Algorithm.DiffContext import Data.Algorithm.DiffOutput import Text.PrettyPrint @@ -37,7 +38,8 @@                         testProperty "self generates empty" $ forAll shortLists  prop_ppDiffEqual,                         --testProperty "compare our lists with diff" $ forAll2 shortLists  prop_ppDiffShort,                         testProperty "compare random with diff" prop_ppDiffR,-                        testProperty "test parse" prop_parse+                        testProperty "test parse" prop_parse,+                        testProperty "test context" prop_context_diff                      ]                    ] @@ -190,3 +192,16 @@                          , (3, return (prefix ++ ["XXX" ++ str]))                          , (2, return prefix)                          , (2, return [str])]++-- | FIXME - make a real quickcheck property+prop_context_diff :: Bool+prop_context_diff =+    expected == actual+    where+      expected = [[Both ["a","b"] ["a","b"],+                   First ["c"],+                   Both ["d","e"] ["d","e"]],+                  [Both ["i","j"] ["i","j"],First ["k"]]]+      actual = getContextDiff 2 (lines textA) (lines textB)+      textA = "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\n"+      textB = "a\nb\nd\ne\nf\ng\nh\ni\nj\n"