Module restructure

This commit is contained in:
Utku Demir 2021-09-04 22:09:30 +12:00
parent e187d589f3
commit ffa1656cae
No known key found for this signature in database
GPG Key ID: F3F8629C3E0BF60B
10 changed files with 101 additions and 52 deletions

View File

@ -36,11 +36,11 @@ common common-options
RankNTypes
ScopedTypeVariables
NumericUnderscores
other-modules: PathStats
StorePath
App
InvertedIndex
Clipboard
other-modules: NixTree.PathStats
NixTree.StorePath
NixTree.App
Data.InvertedIndex
NixTree.Clipboard
Paths_nix_tree
autogen-modules: Paths_nix_tree
mixins: base hiding (Prelude)
@ -66,7 +66,7 @@ common common-options
executable nix-tree
import: common-options
ghc-options: -Wunused-packages
main-is: Main.hs
main-is: NixTree/Main.hs
hs-source-dirs: src
default-language: Haskell2010
build-depends: base >= 4.11 && < 5
@ -75,6 +75,7 @@ test-suite nix-tree-tests
import: common-options
type: exitcode-stdio-1.0
hs-source-dirs: test/ src/
other-modules: Test.Data.InvertedIndex
main-is: Test.hs
build-depends: base >=4.11 && < 5
, hedgehog

View File

@ -1,4 +1,4 @@
module InvertedIndex
module Data.InvertedIndex
( InvertedIndex,
iiFromList,
iiInsert,

View File

@ -1,20 +1,20 @@
module App (run, helpText) where
module NixTree.App (run, helpText) where
import qualified Brick as B
import qualified Brick.BChan as B
import qualified Brick.Widgets.Border as B
import qualified Brick.Widgets.Center as B
import qualified Brick.Widgets.List as B
import qualified Clipboard
import Control.Concurrent
import Data.InvertedIndex
import qualified Data.List.NonEmpty as NE
import qualified Data.Map as Map
import qualified Data.Sequence as S
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Graphics.Vty as V
import InvertedIndex
import PathStats
import qualified NixTree.Clipboard as Clipboard
import NixTree.PathStats
import qualified System.Clock as Clock
import qualified System.HrfSize as HRF
@ -335,7 +335,7 @@ yankToClipboard p =
( T.intercalate "\n" $
"Cannot copy to clipboard: " :
map (" " <>) errs
++ ["Please report this as a bug."]
++ ["Please report this as a bug."]
)
renderMainScreen :: AppEnv s -> B.Widget Widgets

View File

@ -1,4 +1,4 @@
module Clipboard
module NixTree.Clipboard
( copy,
)
where
@ -27,7 +27,7 @@ runCmd txt (cmd, args) =
Right (Just (ExitSuccess, _, _)) -> Right ()
Right (Just (ExitFailure e, out, err)) ->
Left $
"failed with exit code "
"failed with exit code "
<> show e
<> ", "
<> "stdout: "

View File

@ -1,10 +1,10 @@
module Main where
import App
import NixTree.App
import Control.Concurrent (forkIO)
import qualified Data.HashMap.Strict as HM
import Data.Version (showVersion)
import PathStats
import NixTree.PathStats
import Paths_nix_tree (version)
import System.Directory (canonicalizePath, doesDirectoryExist, getHomeDirectory)
import System.Environment (getArgs)

View File

@ -1,9 +1,9 @@
module PathStats
module NixTree.PathStats
( PathStats (..),
calculatePathStats,
whyDepends,
shortestPathTo,
module StorePath,
module NixTree.StorePath,
)
where
@ -11,7 +11,7 @@ import Data.List (minimumBy)
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Lazy as M
import qualified Data.Set as S
import StorePath
import NixTree.StorePath
data IntermediatePathStats s = IntermediatePathStats
{ ipsAllRefs :: M.Map (StoreName s) (StorePath s (StoreName s) ())

View File

@ -1,4 +1,4 @@
module StorePath
module NixTree.StorePath
( StoreName (..),
storeNameToPath,
storeNameToText,

View File

@ -2,39 +2,11 @@
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
import qualified Test.Data.InvertedIndex
main :: IO ()
main = defaultMain [checkParallel $$(discover)]
main =
defaultMain . map checkParallel $
[Test.Data.InvertedIndex.tests]

View File

@ -0,0 +1,39 @@
{-# LANGUAGE TemplateHaskell #-}
module Test.Data.InvertedIndex (tests) where
import Data.InvertedIndex
import qualified Data.Map as Map
import qualified Data.Text as Text
import Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
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
tests :: Group
tests = $$(discover)

37
test/Test/Data/Test.hs Normal file
View File

@ -0,0 +1,37 @@
{-# LANGUAGE TemplateHaskell #-}
module Test.Data.InvertedIndex where
import Data.InvertedIndex
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
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