2016-07-14 22:21:14 +03:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2016-05-17 20:09:14 +03:00
|
|
|
module DiffSummarySpec where
|
2016-05-16 21:43:53 +03:00
|
|
|
|
2016-05-26 20:40:54 +03:00
|
|
|
import Prologue
|
2016-06-17 20:33:50 +03:00
|
|
|
import Data.Record
|
2016-05-16 21:43:53 +03:00
|
|
|
import Test.Hspec
|
2016-07-14 22:21:14 +03:00
|
|
|
import Test.Hspec.QuickCheck
|
2016-05-17 22:59:07 +03:00
|
|
|
import Diff
|
|
|
|
import Syntax
|
2016-05-17 20:09:14 +03:00
|
|
|
import Patch
|
2016-05-17 22:59:07 +03:00
|
|
|
import Category
|
2016-05-16 21:43:53 +03:00
|
|
|
import DiffSummary
|
2016-07-13 18:58:43 +03:00
|
|
|
import Text.PrettyPrint.Leijen.Text
|
2016-07-22 19:36:03 +03:00
|
|
|
import Term.Arbitrary
|
|
|
|
import Interpreter
|
2016-05-17 20:09:14 +03:00
|
|
|
|
2016-07-15 16:41:12 +03:00
|
|
|
arrayInfo :: Record '[Category]
|
|
|
|
arrayInfo = ArrayLiteral .: RNil
|
2016-05-17 22:59:07 +03:00
|
|
|
|
2016-07-15 16:41:12 +03:00
|
|
|
literalInfo :: Record '[Category]
|
|
|
|
literalInfo = StringLiteral .: RNil
|
2016-05-17 22:59:07 +03:00
|
|
|
|
2016-07-22 19:36:03 +03:00
|
|
|
testDiff :: Diff Text (Record '[Category])
|
2016-05-17 22:59:07 +03:00
|
|
|
testDiff = free $ Free (pure arrayInfo :< Indexed [ free $ Pure (Insert (cofree $ literalInfo :< Leaf "a")) ])
|
|
|
|
|
2016-05-31 23:15:40 +03:00
|
|
|
testSummary :: DiffSummary DiffInfo
|
2016-06-10 23:42:11 +03:00
|
|
|
testSummary = DiffSummary { patch = Insert (DiffInfo "string" "a"), parentAnnotations = [] }
|
2016-05-17 20:09:14 +03:00
|
|
|
|
2016-05-31 23:15:40 +03:00
|
|
|
replacementSummary :: DiffSummary DiffInfo
|
2016-06-10 23:42:11 +03:00
|
|
|
replacementSummary = DiffSummary { patch = Replace (DiffInfo "string" "a") (DiffInfo "symbol" "b"), parentAnnotations = [ ArrayLiteral ] }
|
2016-05-18 17:24:08 +03:00
|
|
|
|
2016-05-17 20:09:14 +03:00
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
2016-05-17 22:59:07 +03:00
|
|
|
describe "diffSummary" $ do
|
|
|
|
it "outputs a diff summary" $ do
|
2016-06-10 23:42:11 +03:00
|
|
|
diffSummary testDiff `shouldBe` [ DiffSummary { patch = Insert (DiffInfo "string" "a"), parentAnnotations = [ ArrayLiteral ] } ]
|
2016-07-14 22:21:14 +03:00
|
|
|
|
|
|
|
prop "equal terms produce identity diffs" $
|
|
|
|
\ a -> let term = toTerm (a :: ArbitraryTerm Text (Record '[Category])) in
|
|
|
|
diffSummary (diffTerms wrap (==) diffCost term term) `shouldBe` []
|
|
|
|
|
2016-05-17 20:09:14 +03:00
|
|
|
describe "show" $ do
|
|
|
|
it "should print adds" $
|
2016-07-13 18:58:43 +03:00
|
|
|
show (pretty testSummary) `shouldBe` ("Added the 'a' string" :: Text)
|
2016-05-18 17:24:08 +03:00
|
|
|
it "prints a replacement" $ do
|
2016-07-13 18:58:43 +03:00
|
|
|
show (pretty replacementSummary) `shouldBe` ("Replaced the 'a' string with the 'b' symbol in the array context" :: Text)
|