1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 13:51:44 +03:00
semantic/test/DiffSpec.hs

38 lines
1.1 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
import Category
2017-06-01 18:10:47 +03:00
import Data.Functor.Both
import Data.Functor.Listable
2017-04-24 22:53:11 +03:00
import RWS
import Data.String
2016-06-27 20:12:06 +03:00
import Diff
2017-02-08 19:15:37 +03:00
import Info
import Interpreter
2016-06-27 20:12:06 +03:00
import Prologue
import SpecHelpers
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
2017-02-08 19:15:37 +03:00
let decorate = defaultFeatureVectorDecorator (category . headF)
2016-06-27 20:18:20 +03:00
prop "equality is reflexive" $
\ a -> let diff = unListableDiff a :: SyntaxDiff String '[Category] in
2016-06-27 20:21:32 +03:00
diff `shouldBe` diff
2016-06-27 20:18:20 +03:00
prop "equal terms produce identity diffs" $
2017-02-08 19:15:37 +03:00
\ a -> let term = decorate (unListableF a :: SyntaxTerm String '[Category]) in
2017-06-01 18:10:47 +03:00
diffCost (diffTerms (pure term)) `shouldBe` 0
2016-06-27 20:18:20 +03:00
describe "beforeTerm" $ do
prop "recovers the before term" $
2017-06-01 18:10:47 +03:00
\ a b -> let diff = diffTerms (unListableF <$> both a b :: Both (SyntaxTerm String '[Category])) in
beforeTerm diff `shouldBe` Just (unListableF a)
describe "afterTerm" $ do
prop "recovers the after term" $
2017-06-01 18:10:47 +03:00
\ a b -> let diff = diffTerms (unListableF <$> both a b :: Both (SyntaxTerm String '[Category])) in
afterTerm diff `shouldBe` Just (unListableF b)