mirror of
https://github.com/github/semantic.git
synced 2024-12-01 00:33:59 +03:00
Add (failing) tests that forward/backward permutations are correctly diffed as changes.
This commit is contained in:
parent
34da19750b
commit
6608ab48e3
@ -3,6 +3,7 @@ module DiffSpec where
|
||||
|
||||
import Category
|
||||
import Data.Functor.Both
|
||||
import Data.Functor.Foldable (cata)
|
||||
import Data.Functor.Listable ()
|
||||
import Data.Record
|
||||
import RWS
|
||||
@ -33,3 +34,16 @@ spec = parallel $ do
|
||||
prop "recovers the after term" $
|
||||
\ a b -> let diff = diffTerms a b :: Diff Syntax (Record '[Category]) (Record '[Category]) in
|
||||
afterTerm diff `shouldBe` Just b
|
||||
|
||||
prop "forward permutations are changes" $
|
||||
\ a b -> let wrap = termIn (Program :. Nil) . Indexed
|
||||
c = wrap [a] in
|
||||
diffTerms (wrap [a, b, c]) (wrap [c, a, b :: Term Syntax (Record '[Category])]) `shouldBe` merge (Program :. Nil, Program :. Nil) (Indexed [ inserting c, mergeTerm a, mergeTerm b, deleting c ])
|
||||
|
||||
prop "backward permutations are changes" $
|
||||
\ a b -> let wrap = termIn (Program :. Nil) . Indexed
|
||||
c = wrap [a] in
|
||||
diffTerms (wrap [a, b, c]) (wrap [b, c, a :: Term Syntax (Record '[Category])]) `shouldBe` merge (Program :. Nil, Program :. Nil) (Indexed [ 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)
|
||||
|
Loading…
Reference in New Issue
Block a user