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
|
|
|
|
import Data.String
|
2016-05-16 21:43:53 +03:00
|
|
|
import Test.Hspec
|
2016-05-17 22:59:07 +03:00
|
|
|
import Diff
|
|
|
|
import Info
|
|
|
|
import Syntax
|
2016-05-17 20:09:14 +03:00
|
|
|
import Patch
|
2016-05-17 22:59:07 +03:00
|
|
|
import Range
|
|
|
|
import Category
|
|
|
|
import Data.Set
|
2016-05-16 21:43:53 +03:00
|
|
|
import DiffSummary
|
2016-05-17 20:09:14 +03:00
|
|
|
|
2016-05-17 22:59:07 +03:00
|
|
|
arrayInfo :: Info
|
|
|
|
arrayInfo = Info (rangeAt 0) (singleton ArrayLiteral) 2
|
|
|
|
|
|
|
|
literalInfo :: Info
|
|
|
|
literalInfo = Info (rangeAt 1) (singleton StringLiteral) 1
|
|
|
|
|
|
|
|
testDiff :: Diff String Info
|
|
|
|
testDiff = free $ Free (pure arrayInfo :< Indexed [ free $ Pure (Insert (cofree $ literalInfo :< Leaf "a")) ])
|
|
|
|
|
|
|
|
testSummary :: DiffSummary Char
|
2016-05-23 20:57:04 +03:00
|
|
|
testSummary = DiffSummary { patch = Insert (DiffInfo "string" (Just "a")), parentAnnotations = [] }
|
2016-05-17 20:09:14 +03:00
|
|
|
|
2016-05-18 17:24:08 +03:00
|
|
|
replacementSummary :: DiffSummary Char
|
2016-05-23 20:57:04 +03:00
|
|
|
replacementSummary = DiffSummary { patch = Replace (DiffInfo "string" (Just "a")) (DiffInfo "symbol" (Just "b")), parentAnnotations = [ (DiffInfo "array" (Just "switch {}")) ] }
|
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-05-23 20:57:04 +03:00
|
|
|
diffSummary testDiff `shouldBe` [ DiffSummary { patch = Insert (DiffInfo "string" (Just "a")), parentAnnotations = [ DiffInfo "array" Nothing ] } ]
|
2016-05-17 20:09:14 +03:00
|
|
|
describe "show" $ do
|
|
|
|
it "should print adds" $
|
2016-05-26 20:40:54 +03:00
|
|
|
show testSummary `shouldBe` ("Added the 'a' string" :: String)
|
2016-05-18 17:24:08 +03:00
|
|
|
it "prints a replacement" $ do
|
2016-05-26 20:40:54 +03:00
|
|
|
show replacementSummary `shouldBe` ("Replaced the 'a' string with the 'b' symbol in the array context" :: String)
|