2016-06-27 20:15:03 +03:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2017-03-01 02:35:43 +03:00
|
|
|
module DiffSpec where
|
2016-06-27 20:12:06 +03:00
|
|
|
|
2017-09-27 19:41:41 +03:00
|
|
|
import Data.Diff
|
2017-06-01 18:10:47 +03:00
|
|
|
import Data.Functor.Both
|
2017-09-26 16:12:06 +03:00
|
|
|
import Data.Functor.Foldable (cata)
|
2017-09-26 16:48:59 +03:00
|
|
|
import Data.Functor.Listable (ListableSyntax)
|
2017-09-14 02:14:01 +03:00
|
|
|
import Data.Record
|
2017-09-27 19:37:37 +03:00
|
|
|
import Data.Term
|
2017-09-26 02:52:08 +03:00
|
|
|
import Data.Union
|
2016-06-27 20:15:03 +03:00
|
|
|
import Interpreter
|
2017-09-26 02:52:08 +03:00
|
|
|
import RWS
|
2016-06-27 20:12:06 +03:00
|
|
|
import Test.Hspec
|
2017-01-08 07:17:05 +03:00
|
|
|
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" $
|
2017-09-26 16:48:59 +03:00
|
|
|
\ diff -> diff `shouldBe` (diff :: Diff ListableSyntax (Record '[]) (Record '[]))
|
2016-06-27 20:18:20 +03:00
|
|
|
|
2016-07-13 00:29:47 +03:00
|
|
|
prop "equal terms produce identity diffs" $
|
2017-09-26 16:48:59 +03:00
|
|
|
\ term -> diffCost (diffTerms term (term :: Term ListableSyntax (Record '[]))) `shouldBe` 0
|
2016-06-27 20:18:20 +03:00
|
|
|
|
2016-06-27 20:23:43 +03:00
|
|
|
describe "beforeTerm" $ do
|
|
|
|
prop "recovers the before term" $
|
2017-09-26 16:48:59 +03:00
|
|
|
\ 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
|
2016-06-27 20:15:03 +03:00
|
|
|
|
2016-06-27 20:24:50 +03:00
|
|
|
describe "afterTerm" $ do
|
|
|
|
prop "recovers the after term" $
|
2017-09-26 16:48:59 +03:00
|
|
|
\ 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
|
2017-09-26 16:12:06 +03:00
|
|
|
|
2017-09-26 17:11:00 +03:00
|
|
|
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
|
2017-09-26 17:11:00 +03:00
|
|
|
-- b = wrap [a]
|
|
|
|
-- c = wrap [a, b] in
|
2017-09-28 17:40:23 +03:00
|
|
|
-- diffTerms (wrap [a, b, c]) (wrap [c, a, b :: Term ListableSyntax (Record '[])]) `shouldBe` merge (Nil, Nil) (inj [ inserting c, merging a, merging b, deleting c ])
|
2017-09-26 16:12:06 +03:00
|
|
|
|
|
|
|
prop "backward permutations are changes" $
|
2017-09-26 19:10:32 +03:00
|
|
|
\ a -> let wrap = termIn Nil . inj
|
2017-09-26 17:09:54 +03:00
|
|
|
b = wrap [a]
|
|
|
|
c = wrap [a, b] in
|
2017-09-28 17:40:23 +03:00
|
|
|
diffTerms (wrap [a, b, c]) (wrap [b, c, a :: Term ListableSyntax (Record '[])]) `shouldBe` merge (Nil, Nil) (inj [ deleting a, merging b, merging c, inserting a ])
|