mirror of
https://github.com/github/semantic.git
synced 2024-12-20 05:11:44 +03:00
31 lines
1.1 KiB
Haskell
31 lines
1.1 KiB
Haskell
{-# LANGUAGE DataKinds #-}
|
|
module InterpreterSpec where
|
|
|
|
import Category
|
|
import Diff
|
|
import Data.Record
|
|
import Interpreter
|
|
import Patch
|
|
import Prologue
|
|
import Syntax
|
|
import Term.Arbitrary
|
|
import Test.Hspec
|
|
import Test.Hspec.QuickCheck
|
|
|
|
spec :: Spec
|
|
spec = parallel $ do
|
|
describe "interpret" $ do
|
|
it "returns a replacement when comparing two unicode equivalent terms" $
|
|
let termA = cofree $ (StringLiteral .: RNil) :< Leaf ("t\776" :: Text)
|
|
termB = cofree $ (StringLiteral .: RNil) :< Leaf "\7831" in
|
|
diffTerms (free . Free) ((==) `on` extract) diffCost termA termB `shouldBe` free (Pure (Replace termA termB))
|
|
|
|
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))
|
|
|
|
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
|