From aade9415aa5684262dbe4d7511b20571c88fc88c Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 18 May 2016 10:24:08 -0400 Subject: [PATCH] Add replacement summaries --- src/DiffSummary.hs | 4 +++- test/DiffSummarySpec.hs | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 260968770..47c6b9061 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -63,7 +63,9 @@ instance Show a => Show (DiffSummary a) where ++ if null parentAnnotations then "" else " to the " ++ intercalate "#" (termName <$> parentAnnotations) ++ " context" (Delete termInfo) -> "Deleted the " ++ "'" ++ fromJust (term termInfo) ++ "' " ++ termName termInfo ++ if null parentAnnotations then "" else " in the " ++ intercalate "#" (termName <$> parentAnnotations) ++ " context" - (Replace t1 t2) -> "Replaced " + (Replace t1 t2) -> "Replaced the " ++ "'" ++ fromJust (term t1) ++ "' " ++ termName t1 + ++ " with the " ++ "'" ++ fromJust (term t2) ++ "' " ++ termName t2 + ++ if null parentAnnotations then "" else " in the " ++ intercalate "#" (termName <$> parentAnnotations) ++ " context" diffSummary :: IsTerm leaf => Diff leaf Info -> [DiffSummary DiffInfo] diffSummary = cata diffSummary' where diff --git a/test/DiffSummarySpec.hs b/test/DiffSummarySpec.hs index bb59e343f..92ce568aa 100644 --- a/test/DiffSummarySpec.hs +++ b/test/DiffSummarySpec.hs @@ -24,6 +24,9 @@ testDiff = free $ Free (pure arrayInfo :< Indexed [ free $ Pure (Insert (cofree testSummary :: DiffSummary Char testSummary = DiffSummary { patch = Insert (DiffInfo "string literal" (Just "a")), parentAnnotations = [] } +replacementSummary :: DiffSummary Char +replacementSummary = DiffSummary { patch = Replace (DiffInfo "string literal" (Just "a")) (DiffInfo "symbol literal" (Just "b")), parentAnnotations = [ (DiffInfo "array literal" Nothing)] } + spec :: Spec spec = parallel $ do describe "diffSummary" $ do @@ -32,3 +35,5 @@ spec = parallel $ do describe "show" $ do it "should print adds" $ show testSummary `shouldBe` "Added the 'a' string literal" + it "prints a replacement" $ do + show replacementSummary `shouldBe` "Replaced the 'a' string literal with the 'b' symbol literal in the array literal context"