1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 16:33:03 +03:00
semantic/test/DiffSpec.hs

48 lines
1.8 KiB
Haskell
Raw Normal View History

{-# LANGUAGE DataKinds #-}
2017-03-01 02:35:43 +03:00
module DiffSpec where
2016-06-27 20:12:06 +03:00
2017-06-01 18:10:47 +03:00
import Data.Functor.Both
import Data.Functor.Foldable (cata)
import Data.Functor.Listable (ListableSyntax)
import Data.Record
import Data.Union
2016-06-27 20:12:06 +03:00
import Diff
import Interpreter
import RWS
import Term
2016-06-27 20:12:06 +03:00
import Test.Hspec
import Test.Hspec.LeanCheck
2016-06-27 20:12:06 +03:00
spec :: Spec
spec = parallel $ do
2016-06-27 20:18:20 +03:00
prop "equality is reflexive" $
\ diff -> diff `shouldBe` (diff :: Diff ListableSyntax (Record '[]) (Record '[]))
2016-06-27 20:18:20 +03:00
prop "equal terms produce identity diffs" $
\ term -> diffCost (diffTerms term (term :: Term ListableSyntax (Record '[]))) `shouldBe` 0
2016-06-27 20:18:20 +03:00
describe "beforeTerm" $ do
prop "recovers the before term" $
\ a b -> let diff = diffTerms a b :: Diff ListableSyntax (Record '[]) (Record '[]) in
2017-09-09 16:18:08 +03:00
beforeTerm diff `shouldBe` Just a
describe "afterTerm" $ do
prop "recovers the after term" $
\ a b -> let diff = diffTerms a b :: Diff ListableSyntax (Record '[]) (Record '[]) in
2017-09-09 16:18:08 +03:00
afterTerm diff `shouldBe` Just b
prop "forward permutations are changes" $ pendingWith "https://github.com/github/semantic-diff/issues/1359"
2017-09-26 19:14:36 +03:00
-- \ a -> let wrap = termIn Nil . inj
-- b = wrap [a]
-- c = wrap [a, b] in
-- diffTerms (wrap [a, b, c]) (wrap [c, a, b :: Term ListableSyntax (Record '[])]) `shouldBe` merge (Nil, Nil) (inj [ inserting c, mergeTerm a, mergeTerm b, deleting c ])
prop "backward permutations are changes" $
\ a -> let wrap = termIn Nil . inj
2017-09-26 17:09:54 +03:00
b = wrap [a]
c = wrap [a, b] in
diffTerms (wrap [a, b, c]) (wrap [b, c, a :: Term ListableSyntax (Record '[])]) `shouldBe` merge (Nil, Nil) (inj [ deleting a, mergeTerm b, mergeTerm c, inserting a ])
mergeTerm :: Functor syntax => Term syntax ann -> Diff syntax ann ann
mergeTerm = cata (\ (In ann syntax) -> merge (ann, ann) syntax)