1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 00:44:57 +03:00

Define (failing) tests that permutations are changes.

This commit is contained in:
Rob Rix 2017-09-26 09:12:06 -04:00
parent 86ede39a58
commit cfc6d13ad0

View File

@ -3,6 +3,7 @@ module DiffSpec where
import Category
import Data.Functor.Both
import Data.Functor.Foldable (cata)
import Data.Functor.Listable ()
import qualified Data.Syntax as Syntax
import qualified Data.Syntax.Comment as Comment
@ -45,3 +46,16 @@ spec = parallel $ do
prop "recovers the after term" $
\ a b -> let diff = diffTerms a b :: Diff Syntax (Record '[]) (Record '[]) in
afterTerm diff `shouldBe` Just b
prop "forward permutations are changes" $
\ a b -> let wrap = termIn Nil . inj
c = wrap [a] in
diffTerms (wrap [a, b, c]) (wrap [c, a, b :: Term Syntax (Record '[])]) `shouldBe` merge (Nil, Nil) (inj [ inserting c, mergeTerm a, mergeTerm b, deleting c ])
prop "backward permutations are changes" $
\ a b -> let wrap = termIn Nil . inj
c = wrap [a] in
diffTerms (wrap [a, b, c]) (wrap [b, c, a :: Term Syntax (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)