mirror of
https://github.com/github/semantic.git
synced 2024-12-19 04:41:47 +03:00
47 lines
1.6 KiB
Haskell
47 lines
1.6 KiB
Haskell
{-# LANGUAGE DataKinds #-}
|
|
module DiffSummarySpec where
|
|
|
|
import Prologue
|
|
import Data.Record
|
|
import Test.Hspec
|
|
import Test.Hspec.QuickCheck
|
|
import Diff
|
|
import Syntax
|
|
import Patch
|
|
import Category
|
|
import DiffSummary
|
|
import Text.PrettyPrint.Leijen.Text
|
|
import Term.Arbitrary
|
|
import Interpreter
|
|
|
|
arrayInfo :: Record '[Category]
|
|
arrayInfo = ArrayLiteral .: RNil
|
|
|
|
literalInfo :: Record '[Category]
|
|
literalInfo = StringLiteral .: RNil
|
|
|
|
testDiff :: Diff Text (Record '[Category])
|
|
testDiff = free $ Free (pure arrayInfo :< Indexed [ free $ Pure (Insert (cofree $ literalInfo :< Leaf "a")) ])
|
|
|
|
testSummary :: DiffSummary DiffInfo
|
|
testSummary = DiffSummary { patch = Insert (DiffInfo "string" "a"), parentAnnotations = [] }
|
|
|
|
replacementSummary :: DiffSummary DiffInfo
|
|
replacementSummary = DiffSummary { patch = Replace (DiffInfo "string" "a") (DiffInfo "symbol" "b"), parentAnnotations = [ ArrayLiteral ] }
|
|
|
|
spec :: Spec
|
|
spec = parallel $ do
|
|
describe "diffSummary" $ do
|
|
it "outputs a diff summary" $ do
|
|
diffSummary testDiff `shouldBe` [ DiffSummary { patch = Insert (DiffInfo "string" "a"), parentAnnotations = [ ArrayLiteral ] } ]
|
|
|
|
prop "equal terms produce identity diffs" $
|
|
\ a -> let term = toTerm (a :: ArbitraryTerm Text (Record '[Category])) in
|
|
diffSummary (diffTerms wrap (==) diffCost term term) `shouldBe` []
|
|
|
|
describe "show" $ do
|
|
it "should print adds" $
|
|
show (pretty testSummary) `shouldBe` ("Added the 'a' string" :: Text)
|
|
it "prints a replacement" $ do
|
|
show (pretty replacementSummary) `shouldBe` ("Replaced the 'a' string with the 'b' symbol in the array context" :: Text)
|