nix-tree/test/Test.hs
Utku Demir 1ffb426cc5
Don't hardcode '/nix/store', instead query at startup
This _should_ enable nix-tree to work on non-standard store paths.
Not tested yet, since I do not have a setup like that.

Main changes:

* Fetch store path at the beginning (`getNixStore` function)
* Make `StoreName`'s also contain a NixStore
* Make `InvertedIndex` similar to a `Map` rather than a `Set`
2021-03-10 22:30:56 +13:00

41 lines
959 B
Haskell

{-# LANGUAGE TemplateHaskell #-}
module Main where
import qualified Data.Map as Map
import qualified Data.Text as Text
import Hedgehog
import qualified Hedgehog.Gen as Gen
import Hedgehog.Main
import qualified Hedgehog.Range as Range
import InvertedIndex
prop_inverted_index :: Property
prop_inverted_index = withDiscards 10000 . withTests 10000 . property $ do
haystack <-
forAll $
Gen.map
(Range.linear 0 100)
( (,)
<$> Gen.text (Range.linear 0 10) Gen.alphaNum
<*> Gen.int (Range.linear 0 100)
)
needle <-
forAll $
(Gen.text (Range.linear 0 5) Gen.alphaNum)
let ii = iiFromList (Map.toList haystack)
annotateShow ii
let expected =
haystack
& Map.filterWithKey
(\t _ -> Text.toLower needle `Text.isInfixOf` Text.toLower t)
actual = iiSearch needle ii
expected === actual
main :: IO ()
main = defaultMain [checkParallel $$(discover)]