Diff 1.0.1.1 → 1.0.2
raw patch · 4 files changed
+35/−20 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- Diff.cabal +1/−1
- src/Data/Algorithm/DiffContext.hs +2/−1
- test/Test.hs +28/−18
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 1.0.2++ - Output correct format when an input file is empty, e.g. `@@ --0,0 +1,3 @@`.+ # 1.0.1.1 - Require `base >= 4.11` (GHC 8.4).
Diff.cabal view
@@ -1,6 +1,6 @@ Cabal-Version: 1.18 name: Diff-version: 1.0.1.1+version: 1.0.2 synopsis: Diff algorithm in pure Haskell description: Implementation of the standard diff algorithm in Haskell. .
src/Data/Algorithm/DiffContext.hs view
@@ -150,7 +150,7 @@ formatHunk hunk = "-" <> formatRun (firsts hunk) <> " +" <> formatRun (seconds hunk) formatRun :: [Int] -> String- formatRun [] = error "empty hunk!"+ formatRun [] = "-0,0" formatRun [n] = show n formatRun ns@(n : _) = show n <> "," <> show (length ns) @@ -164,6 +164,7 @@ seconds (Second ns : more) = fmap (\(Numbered n _) -> n) ns <> seconds more seconds [] = [] +-- | Pretty print without line numbers. prettyContextDiffOld :: Doc -- ^ Document 1 name -> Doc -- ^ Document 2 name
test/Test.hs view
@@ -50,11 +50,29 @@ { diLeft = ["1","2","3","4","","5","6","7"] , diRight = ["1","2","3","q","b","u","l","","XXX6",""] }),- testProperty "test parse" prop_parse,- testProperty "test context" prop_context_diff+ testProperty "test parse" prop_parse+ ],+ testGroup "context props" [+ testProperty "test context" $ prop_ppContextDiffUnitTest+ (DiffInput+ { diLeft = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]+ , diRight = ["a", "b", "d", "e", "f", "g", "h", "i", "j"]+ })+ "--- a\n+++ b\n@@ -1,5 +1,4 @@\n a\n b\n-c\n d\n e\n@@ -9,3 +8,2 @@\n i\n j\n-k\n",+ testProperty "compare with empty" $ prop_ppContextDiffUnitTest+ (DiffInput+ { diLeft = []+ , diRight = ["1","2","3"]+ })+ "--- a\n+++ b\n@@ --0,0 +1,3 @@\n+1\n+2\n+3\n",+ testProperty "compare with empty" $ prop_ppContextDiffUnitTest+ (DiffInput+ { diLeft = ["1","2","3"]+ , diRight = []+ })+ "--- a\n+++ b\n@@ -1,3 +-0,0 @@\n-1\n-2\n-3\n" ] ]- slTest s t = testProperty s $ forAll shortLists (t :: [Bool] -> Bool) slTest2 s t = testProperty s $ forAll2 shortLists (t :: [Bool] -> [Bool] -> Bool) @@ -173,6 +191,13 @@ hClose h return fp +prop_ppContextDiffUnitTest :: DiffInput -> String -> Property+prop_ppContextDiffUnitTest (DiffInput le ri) expected =+ show diff === expected+ where+ hunks = getContextDiff (Just 2) le ri+ diff = prettyContextDiff (text "a") (text "b") (text . unnumber) hunks+ -- | Check pretty printed DiffOperations can be parsed again prop_parse :: DiffInput -> Bool prop_parse (DiffInput le ri) =@@ -204,21 +229,6 @@ , (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- -- Note that the line numbers don't affect equality- expected = [[Both [Numbered 1 "a",Numbered 2 "b"] [Numbered 1 "a",Numbered 2 "b"],- First [Numbered 3 "c"],- Both [Numbered 4 "d",Numbered 5 "e"] [Numbered 3 "d",Numbered 4 "e"]],- [Both [Numbered 9 "i",Numbered 10 "j"] [Numbered 8 "i",Numbered 9 "j"],- First [Numbered 11 "k"]]]- actual = getContextDiff (Just 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" -- | Reference implementation, very slow. naiveGetDiffBy :: forall a b. (a -> b -> Bool) -> [a] -> [b] -> [PolyDiff a b]