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
|
2016-04-12 11:54:32 +03:00
|
|
|
import Diff
|
2016-06-17 20:33:50 +03:00
|
|
|
import Data.Record
|
2016-06-27 20:08:12 +03:00
|
|
|
import Interpreter
|
2015-12-16 22:18:09 +03:00
|
|
|
import Patch
|
2016-06-27 22:28:04 +03:00
|
|
|
import Prologue
|
|
|
|
import Syntax
|
2016-06-27 22:28:11 +03:00
|
|
|
import Term.Arbitrary
|
2015-12-16 22:18:09 +03:00
|
|
|
import Test.Hspec
|
2016-06-27 22:28:11 +03:00
|
|
|
import Test.Hspec.QuickCheck
|
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" $
|
2016-06-30 22:02:28 +03:00
|
|
|
let termA = cofree $ (StringLiteral .: RNil) :< Leaf ("t\776" :: Text)
|
2016-06-27 20:08:12 +03:00
|
|
|
termB = cofree $ (StringLiteral .: RNil) :< Leaf "\7831" in
|
|
|
|
diffTerms (free . Free) ((==) `on` extract) diffCost termA termB `shouldBe` free (Pure (Replace termA termB))
|
2016-06-27 22:28:11 +03:00
|
|
|
|
|
|
|
prop "produces correct diffs" $
|
|
|
|
\ a b -> let diff = diffTerms (free . Free) ((==) `on` extract) diffCost (toTerm a) (toTerm b) :: Diff Text (Record '[Category]) in
|
|
|
|
(beforeTerm diff, afterTerm diff) `shouldBe` (Just (toTerm a), Just (toTerm b))
|
2016-06-30 20:34:31 +03:00
|
|
|
|
|
|
|
prop "constructs zero-cost diffs of equal terms" $
|
|
|
|
\ a -> let term = toTerm a
|
|
|
|
diff = diffTerms (free . Free) ((==) `on` extract) diffCost term term :: Diff Text (Record '[Category]) in
|
|
|
|
diffCost diff `shouldBe` 0
|