1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 22:31:36 +03:00
semantic/test/InterpreterSpec.hs

40 lines
1.6 KiB
Haskell
Raw Normal View History

{-# LANGUAGE DataKinds #-}
module InterpreterSpec where
2016-06-27 22:28:04 +03:00
import Category
2017-07-28 21:37:02 +03:00
import Control.Monad.Free (wrap)
2017-06-01 18:10:47 +03:00
import Data.Functor.Both
2017-01-19 23:53:16 +03:00
import Data.Functor.Foldable hiding (Nil)
import Data.Functor.Listable
import Data.Record
import Diff
import Interpreter
import Patch
2016-06-27 22:28:04 +03:00
import Syntax
import Term
import Test.Hspec (Spec, describe, it, parallel)
import Test.Hspec.Expectations.Pretty
import Test.Hspec.LeanCheck
spec :: Spec
spec = parallel $ do
describe "interpret" $ do
it "returns a replacement when comparing two unicode equivalent terms" $
let termA = cofree $ (StringLiteral :. Nil) :< Leaf "t\776"
2017-01-19 23:46:28 +03:00
termB = cofree $ (StringLiteral :. Nil) :< Leaf "\7831" in
2017-06-01 18:10:47 +03:00
diffTerms (both termA termB) `shouldBe` replacing termA termB
prop "produces correct diffs" $
\ a b -> let diff = diffTerms (unListableF <$> both a b :: Both (SyntaxTerm '[Category])) in
(beforeTerm diff, afterTerm diff) `shouldBe` (Just (unListableF a), Just (unListableF b))
prop "constructs zero-cost diffs of equal terms" $
\ a -> let term = (unListableF a :: SyntaxTerm '[Category])
2017-06-01 18:10:47 +03:00
diff = diffTerms (pure term) in
diffCost diff `shouldBe` 0
it "produces unbiased insertions within branches" $
let term s = cofree ((StringLiteral :. Nil) :< Indexed [ cofree ((StringLiteral :. Nil) :< Leaf s) ]) :: SyntaxTerm '[Category]
root = cofree . ((Program :. Nil) :<) . Indexed in
2017-06-01 18:10:47 +03:00
diffTerms (both (root [ term "b" ]) (root [ term "a", term "b" ])) `shouldBe` wrap (pure (Program :. Nil) :< Indexed [ inserting (term "a"), cata wrap (fmap pure (term "b")) ])