1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Empty diffs have empty hunks

This commit is contained in:
joshvera 2016-03-01 17:13:53 -05:00
parent 9ee2e1c285
commit b124b461c0
2 changed files with 6 additions and 4 deletions

View File

@ -1,6 +1,7 @@
module Renderer.Patch (
patch,
hunks
hunks,
Hunk(..)
) where
import Alignment
@ -88,13 +89,14 @@ header blobs hunk = filepathHeader ++ blobOidHeader ++ maybeOffsetHeader
-- | Render a diff as a series of hunks.
hunks :: Renderer a [Hunk (SplitDiff a Info)]
hunks diff blobs | (Both (True, True) ==) $ Source.null . source <$> blobs = [Hunk { offset = Both (0, 0), changes = [], trailingContext = [] }]
hunks diff blobs = hunksInRows (Both (1, 1)) . Prelude.fst $ splitDiffByLines diff (pure 0) (source <$> blobs)
-- | Given beginning line numbers, turn rows in a split diff into hunks in a
-- | patch.
hunksInRows :: Both (Sum Int) -> [Row (SplitDiff a Info)] -> [Hunk (SplitDiff a Info)]
hunksInRows start rows = case nextHunk start rows of
Nothing -> [Hunk { offset = Both (0, 0), changes = [], trailingContext = [] }]
Nothing -> []
Just (hunk, rest) -> hunk : hunksInRows (offset hunk <> hunkLength hunk) rest
-- | Given beginning line numbers, return the next hunk and the remaining rows

View File

@ -12,5 +12,5 @@ import Test.Hspec
spec :: Spec
spec = parallel $
describe "hunks" $
it "empty diffs have no hunks" $
hunks (Free . Annotated (pure (Info (Range 0 0) mempty)) $ Leaf "") (Both (SourceBlob (fromList "") "abcde" "path2.txt", SourceBlob (fromList "") "xyz" "path2.txt")) `shouldBe` []
it "empty diffs have empty hunks" $
hunks (Free . Annotated (pure (Info (Range 0 0) mempty)) $ Leaf "") (Both (SourceBlob (fromList "") "abcde" "path2.txt", SourceBlob (fromList "") "xyz" "path2.txt")) `shouldBe` [Hunk {offset = Both (0, 0), changes = [], trailingContext = []}]