1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 01:47:01 +03:00
semantic/test/InterpreterSpec.hs

37 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-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
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" $
2017-09-11 22:48:58 +03:00
let termA = Term $ (StringLiteral :. Nil) `In` Leaf "t\776"
termB = Term $ (StringLiteral :. Nil) `In` Leaf "\7831" in
diffSyntaxTerms termA termB `shouldBe` replacing termA termB
prop "produces correct diffs" $
\ a b -> let diff = diffSyntaxTerms a b :: Diff Syntax (Record '[Category]) (Record '[Category]) in
2017-09-14 02:34:27 +03:00
(beforeTerm diff, afterTerm diff) `shouldBe` (Just a, Just b)
prop "constructs zero-cost diffs of equal terms" $
\ a -> let diff = diffSyntaxTerms a a :: Diff Syntax (Record '[Category]) (Record '[Category]) in
diffCost diff `shouldBe` 0
it "produces unbiased insertions within branches" $
let term s = Term ((StringLiteral :. Nil) `In` Indexed [ Term ((StringLiteral :. Nil) `In` Leaf s) ]) :: Term Syntax (Record '[Category])
2017-09-11 22:48:58 +03:00
root = termIn (Program :. Nil) . Indexed in
diffSyntaxTerms (root [ term "b" ]) (root [ term "a", term "b" ]) `shouldBe` merge ((Program :. Nil, Program :. Nil)) (Indexed [ inserting (term "a"), cata (\ (In a r) -> merge (a, a) r) (term "b") ])