mirror of
https://github.com/github/semantic.git
synced 2024-11-28 10:15:55 +03:00
37 lines
1.3 KiB
Haskell
37 lines
1.3 KiB
Haskell
module TermSpec where
|
|
|
|
import ArbitraryTerm
|
|
import Data.String
|
|
import Data.Text.Arbitrary ()
|
|
import Diff
|
|
import Diff.Arbitrary
|
|
import Interpreter
|
|
import Prologue
|
|
import Term.Arbitrary
|
|
import Test.Hspec
|
|
import Test.Hspec.QuickCheck
|
|
import Test.QuickCheck
|
|
|
|
spec :: Spec
|
|
spec = parallel $ do
|
|
describe "Term" $ do
|
|
prop "equality is reflexive" $
|
|
\ a -> toTerm a == toTerm (a :: ArbitraryTerm String ())
|
|
|
|
describe "ArbitraryTerm" $
|
|
prop "generates terms of a specific size" $ forAll ((arbitrary >>= \ n -> (,) n <$> termOfSize n) `suchThat` ((> 0) . fst)) $
|
|
\ (n, term) -> arbitraryTermSize (term :: ArbitraryTerm String ()) `shouldBe` n
|
|
|
|
describe "ArbitraryDiff" $
|
|
prop "generates diffs of a specific size" $ forAll ((arbitrary >>= \ n -> (,) n <$> diffOfSize n) `suchThat` ((> 0) . fst)) $
|
|
\ (n, diff) -> arbitraryDiffSize (diff :: ArbitraryDiff String ()) `shouldBe` n
|
|
|
|
describe "Diff" $ do
|
|
prop "equality is reflexive" $
|
|
\ a b -> let diff = diffTerms (free . Free) (==) diffCost (toTerm a) (toTerm (b :: ArbitraryTerm String CategorySet)) in
|
|
diff == diff
|
|
|
|
prop "equal terms produce identity diffs" $
|
|
\ a -> let term = toTerm (a :: ArbitraryTerm String CategorySet) in
|
|
diffCost (diffTerms (free . Free) (==) diffCost term term) == 0
|