mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
40 lines
1.3 KiB
Haskell
40 lines
1.3 KiB
Haskell
module DiffSummarySpec where
|
|
|
|
import Prologue
|
|
import Data.String
|
|
import Test.Hspec
|
|
import Diff
|
|
import Info
|
|
import Syntax
|
|
import Patch
|
|
import Range
|
|
import Category
|
|
import Data.Set
|
|
import DiffSummary
|
|
|
|
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
|
|
testSummary = DiffSummary { patch = Insert (DiffInfo "string" (Just "a")), parentAnnotations = [] }
|
|
|
|
replacementSummary :: DiffSummary Char
|
|
replacementSummary = DiffSummary { patch = Replace (DiffInfo "string" (Just "a")) (DiffInfo "symbol" (Just "b")), parentAnnotations = [ (DiffInfo "array" (Just "switch {}")) ] }
|
|
|
|
spec :: Spec
|
|
spec = parallel $ do
|
|
describe "diffSummary" $ do
|
|
it "outputs a diff summary" $ do
|
|
diffSummary testDiff `shouldBe` [ DiffSummary { patch = Insert (DiffInfo "string" (Just "a")), parentAnnotations = [ DiffInfo "array" Nothing ] } ]
|
|
describe "show" $ do
|
|
it "should print adds" $
|
|
show testSummary `shouldBe` ("Added the 'a' string" :: String)
|
|
it "prints a replacement" $ do
|
|
show replacementSummary `shouldBe` ("Replaced the 'a' string with the 'b' symbol in the array context" :: String)
|