2016-06-27 22:28:11 +03:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2015-12-16 22:18:09 +03:00
|
|
|
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)
|
2017-01-09 22:20:11 +03:00
|
|
|
import Data.Functor.Listable
|
2016-06-17 20:33:50 +03:00
|
|
|
import Data.Record
|
2016-08-10 16:26:58 +03:00
|
|
|
import Diff
|
2016-06-27 20:08:12 +03:00
|
|
|
import Interpreter
|
2016-06-27 22:28:04 +03:00
|
|
|
import Syntax
|
2017-01-09 22:20:11 +03:00
|
|
|
import Term
|
2016-09-15 00:45:23 +03:00
|
|
|
import Test.Hspec (Spec, describe, it, parallel)
|
|
|
|
import Test.Hspec.Expectations.Pretty
|
2017-01-09 22:20:11 +03:00
|
|
|
import Test.Hspec.LeanCheck
|
2015-12-16 22:18:09 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
2016-06-27 20:08:12 +03:00
|
|
|
spec = parallel $ do
|
2016-06-27 20:03:58 +03:00
|
|
|
describe "interpret" $ do
|
2015-12-16 22:18:09 +03:00
|
|
|
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
|
2017-09-25 17:57:28 +03:00
|
|
|
diffSyntaxTerms termA termB `shouldBe` replacing termA termB
|
2016-06-27 22:28:11 +03:00
|
|
|
|
|
|
|
prop "produces correct diffs" $
|
2017-09-25 17:57:28 +03:00
|
|
|
\ 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)
|
2016-06-30 20:34:31 +03:00
|
|
|
|
|
|
|
prop "constructs zero-cost diffs of equal terms" $
|
2017-09-25 17:57:28 +03:00
|
|
|
\ a -> let diff = diffSyntaxTerms a a :: Diff Syntax (Record '[Category]) (Record '[Category]) in
|
2016-06-30 20:34:31 +03:00
|
|
|
diffCost diff `shouldBe` 0
|
2016-08-11 19:23:34 +03:00
|
|
|
|
2016-08-12 19:16:48 +03:00
|
|
|
it "produces unbiased insertions within branches" $
|
2017-09-14 02:14:01 +03:00
|
|
|
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
|
2017-09-25 17:57:28 +03:00
|
|
|
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") ])
|