From 462d44c174202053415b65d7c5a691b0a3ab93dc Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 16 Feb 2017 14:20:22 -0800 Subject: [PATCH] Fill out prop test for the different patch types --- test/TOCSpec.hs | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/test/TOCSpec.hs b/test/TOCSpec.hs index ed09e94f0..3eee8a431 100644 --- a/test/TOCSpec.hs +++ b/test/TOCSpec.hs @@ -51,36 +51,44 @@ spec = parallel $ do diff <- testDiff sourceBlobs diffTOC sourceBlobs diff `shouldBe` [ JSONSummary $ Summarizable C.Method "foo" (sourceSpanBetween (6, 1) (7, 4)) "added" ] - prop "inserts in methods and functions are summarized" $ + prop "inserts of methods and functions are summarized" $ \name body -> - let - diff = programOf name (unListableF body :: SyntaxTerm') - tocSummaries = filter (not . isErrorSummary) (diffTOC blobs diff) - in - (isJust (beforeTerm diff) && isJust (afterTerm diff) ==> Prologue.length tocSummaries == 1) `shouldBe` True + let diff = programWithInsert name (unListableF body) + in numTocSummaries diff `shouldBe` 1 - prop "deletes in methods and functions are summarized" $ + prop "deletes of methods and functions are summarized" $ \name body -> - let - diff = programOf' name (unListableF body :: SyntaxTerm') - tocSummaries = filter (not . isErrorSummary) (diffTOC blobs diff) - in - (isJust (beforeTerm diff) && isJust (afterTerm diff) ==> Prologue.length tocSummaries == 1) `shouldBe` True + let diff = programWithDelete name (unListableF body) + in numTocSummaries diff `shouldBe` 1 + + prop "replacements of methods and functions are summarized" $ + \name body -> + let diff = programWithReplace name (unListableF body) + in numTocSummaries diff `shouldBe` 1 prop "equal terms produce identity diffs" $ - \a -> let term = defaultFeatureVectorDecorator (Info.category . headF) (unListableF a :: SyntaxTerm String '[Category, Range, SourceSpan]) in + \a -> let term = defaultFeatureVectorDecorator (Info.category . headF) (unListableF a :: Term') in diffTOC blobs (diffTerms wrap (==) diffCost term term) `shouldBe` [] -type SyntaxDiff' = SyntaxDiff String '[Range, Category, SourceSpan] -type SyntaxTerm' = SyntaxTerm String '[Range, Category, SourceSpan] +type Diff' = SyntaxDiff String '[Range, Category, SourceSpan] +type Term' = SyntaxTerm String '[Range, Category, SourceSpan] -programOf :: String -> SyntaxTerm' -> SyntaxDiff' -programOf name body = free $ Free (pure programInfo :< Indexed [ free $ Pure (Insert (functionOf name body)) ]) +numTocSummaries :: Diff' -> Int +numTocSummaries diff = Prologue.length $ filter (not . isErrorSummary) (diffTOC blobs diff) -programOf' :: String -> SyntaxTerm' -> SyntaxDiff' -programOf' name body = free $ Free (pure programInfo :< Indexed [ free $ Pure (Delete (functionOf name body)) ]) +programWithInsert :: String -> Term' -> Diff' +programWithInsert name body = programOf $ Insert (functionOf name body) -functionOf :: String -> SyntaxTerm' -> SyntaxTerm' +programWithDelete :: String -> Term' -> Diff' +programWithDelete name body = programOf $ Delete (functionOf name body) + +programWithReplace :: String -> Term' -> Diff' +programWithReplace name body = programOf $ Replace (functionOf name body) (functionOf (name <> "2") body) + +programOf :: Patch Term' -> Diff' +programOf patch = free $ Free (pure programInfo :< Indexed [ free $ Pure patch ]) + +functionOf :: String -> Term' -> Term' functionOf name body = cofree $ functionInfo :< Syntax.Function (fName name) [] Nothing [body] programInfo :: Record '[Range, Category, SourceSpan]