mirror of
https://github.com/github/semantic.git
synced 2024-11-28 10:15:55 +03:00
Use the curried both
constructor.
This commit is contained in:
parent
9476b1226d
commit
60d6cfeb90
@ -43,7 +43,7 @@ constructAndRun comparable (annotation1 :< a) (annotation2 :< b) =
|
||||
algorithm (Keyed a') (Keyed b') = Free $ ByKey a' b' (annotate . Keyed)
|
||||
algorithm (Leaf a') (Leaf b') | a' == b' = annotate $ Leaf b'
|
||||
algorithm a' b' = Free $ Recursive (annotation1 :< a') (annotation2 :< b') Pure
|
||||
annotate = Pure . Free . Annotated (Both (annotation1, annotation2))
|
||||
annotate = Pure . Free . Annotated (both annotation1 annotation2)
|
||||
|
||||
-- | Runs the diff algorithm
|
||||
run :: (Eq a, Eq annotation) => Comparable a annotation -> Algorithm a annotation (Diff a annotation) -> Maybe (Diff a annotation)
|
||||
@ -59,7 +59,7 @@ run comparable (Free (Recursive (annotation1 :< a) (annotation2 :< b) f)) = run
|
||||
interpretInBoth key x y = interpret comparable (x ! key) (y ! key)
|
||||
recur _ _ = Pure $ Replace (annotation1 :< a) (annotation2 :< b)
|
||||
|
||||
annotate = Free . Annotated (Both (annotation1, annotation2))
|
||||
annotate = Free . Annotated (both annotation1 annotation2)
|
||||
|
||||
run comparable (Free (ByKey a b f)) = run comparable $ f byKey where
|
||||
byKey = Map.fromList $ toKeyValue <$> List.union aKeys bKeys
|
||||
|
@ -64,7 +64,7 @@ showHunk blobs hunk = maybeOffsetHeader ++
|
||||
-- | Given the before and after sources, render a change to a string.
|
||||
showChange :: Both (Source Char) -> Change (SplitDiff a Info) -> String
|
||||
showChange sources change = showLines (snd sources) ' ' (snd <$> context change) ++ deleted ++ inserted
|
||||
where (deleted, inserted) = runBoth $ pure showLines <*> sources <*> Both ('-', '+') <*> Both.unzip (contents change)
|
||||
where (deleted, inserted) = runBoth $ pure showLines <*> sources <*> both '-' '+' <*> Both.unzip (contents change)
|
||||
|
||||
-- | Given a source, render a set of lines to a string with a prefix.
|
||||
showLines :: Source Char -> Char -> [Line (SplitDiff leaf Info)] -> String
|
||||
|
@ -15,7 +15,7 @@ type Term a annotation = Cofree (Syntax a) annotation
|
||||
zipTerms :: Term a annotation -> Term a annotation -> Maybe (Term a (Both annotation))
|
||||
zipTerms (annotation1 :< a) (annotation2 :< b) = annotate $ zipUnwrap a b
|
||||
where
|
||||
annotate = fmap (Both (annotation1, annotation2) :<)
|
||||
annotate = fmap (both annotation1 annotation2 :<)
|
||||
zipUnwrap (Leaf _) (Leaf b') = Just $ Leaf b'
|
||||
zipUnwrap (Indexed a') (Indexed b') = Just . Indexed . catMaybes $ zipWith zipTerms a' b'
|
||||
zipUnwrap (Fixed a') (Fixed b') = Just . Fixed . catMaybes $ zipWith zipTerms a' b'
|
||||
|
@ -56,7 +56,7 @@ instance Arbitrary CategorySet where
|
||||
arbitrary = elements [ A, B, C, D ]
|
||||
|
||||
instance Arbitrary a => Arbitrary (Both a) where
|
||||
arbitrary = pure (curry Both) <*> arbitrary <*> arbitrary
|
||||
arbitrary = both <$> arbitrary <*> arbitrary
|
||||
shrink b = both <$> (shrink (fst b)) <*> (shrink (snd b))
|
||||
|
||||
instance Arbitrary a => Arbitrary (Line a) where
|
||||
|
@ -62,7 +62,7 @@ examples directory = do
|
||||
patches <- toDict <$> globFor "*.patch.*"
|
||||
splits <- toDict <$> globFor "*.split.*"
|
||||
let keys = Set.unions $ keysSet <$> [as, bs]
|
||||
return $ (\name -> (Both (as ! name, bs ! name), Map.lookup name jsons, Map.lookup name patches, Map.lookup name splits)) <$> sort (Set.toList keys)
|
||||
return $ (\name -> (both (as ! name) (bs ! name), Map.lookup name jsons, Map.lookup name patches, Map.lookup name splits)) <$> sort (Set.toList keys)
|
||||
where
|
||||
globFor :: String -> IO [FilePath]
|
||||
globFor p = globDir1 (compile p) directory
|
||||
@ -79,7 +79,7 @@ testDiff :: Renderer T.Text String -> Both FilePath -> Maybe FilePath -> (String
|
||||
testDiff renderer paths diff matcher = do
|
||||
let parser = parserForFilepath (fst paths)
|
||||
sources <- sequence $ readAndTranscodeFile <$> paths
|
||||
let sourceBlobs = Both (S.SourceBlob, S.SourceBlob) <*> sources <*> pure mempty <*> paths <*> pure (Just S.defaultPlainBlob)
|
||||
let sourceBlobs = both S.SourceBlob S.SourceBlob <*> sources <*> pure mempty <*> paths <*> pure (Just S.defaultPlainBlob)
|
||||
actual <- diffFiles parser renderer sourceBlobs
|
||||
case diff of
|
||||
Nothing -> matcher actual actual
|
||||
|
@ -14,4 +14,4 @@ spec :: Spec
|
||||
spec = parallel $
|
||||
describe "hunks" $
|
||||
it "empty diffs have empty hunks" $
|
||||
hunks (Free . Annotated (pure (Info (Range 0 0) mempty)) $ Leaf "" :: Diff String Info) (Both (SourceBlob (fromList "") "abcde" "path2.txt" (Just defaultPlainBlob), SourceBlob (fromList "") "xyz" "path2.txt" (Just defaultPlainBlob))) `shouldBe` [Hunk {offset = Both (0, 0), changes = [], trailingContext = []}]
|
||||
hunks (Free . Annotated (pure (Info (Range 0 0) mempty)) $ Leaf "" :: Diff String Info) (both (SourceBlob (fromList "") "abcde" "path2.txt" (Just defaultPlainBlob)) (SourceBlob (fromList "") "xyz" "path2.txt" (Just defaultPlainBlob))) `shouldBe` [Hunk {offset = both 0 0, changes = [], trailingContext = []}]
|
||||
|
Loading…
Reference in New Issue
Block a user