mirror of
https://github.com/utdemir/nix-tree.git
synced 2024-08-17 10:40:33 +03:00
Module restructure
This commit is contained in:
parent
e187d589f3
commit
ffa1656cae
@ -36,11 +36,11 @@ common common-options
|
|||||||
RankNTypes
|
RankNTypes
|
||||||
ScopedTypeVariables
|
ScopedTypeVariables
|
||||||
NumericUnderscores
|
NumericUnderscores
|
||||||
other-modules: PathStats
|
other-modules: NixTree.PathStats
|
||||||
StorePath
|
NixTree.StorePath
|
||||||
App
|
NixTree.App
|
||||||
InvertedIndex
|
Data.InvertedIndex
|
||||||
Clipboard
|
NixTree.Clipboard
|
||||||
Paths_nix_tree
|
Paths_nix_tree
|
||||||
autogen-modules: Paths_nix_tree
|
autogen-modules: Paths_nix_tree
|
||||||
mixins: base hiding (Prelude)
|
mixins: base hiding (Prelude)
|
||||||
@ -66,7 +66,7 @@ common common-options
|
|||||||
executable nix-tree
|
executable nix-tree
|
||||||
import: common-options
|
import: common-options
|
||||||
ghc-options: -Wunused-packages
|
ghc-options: -Wunused-packages
|
||||||
main-is: Main.hs
|
main-is: NixTree/Main.hs
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
build-depends: base >= 4.11 && < 5
|
build-depends: base >= 4.11 && < 5
|
||||||
@ -75,6 +75,7 @@ test-suite nix-tree-tests
|
|||||||
import: common-options
|
import: common-options
|
||||||
type: exitcode-stdio-1.0
|
type: exitcode-stdio-1.0
|
||||||
hs-source-dirs: test/ src/
|
hs-source-dirs: test/ src/
|
||||||
|
other-modules: Test.Data.InvertedIndex
|
||||||
main-is: Test.hs
|
main-is: Test.hs
|
||||||
build-depends: base >=4.11 && < 5
|
build-depends: base >=4.11 && < 5
|
||||||
, hedgehog
|
, hedgehog
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module InvertedIndex
|
module Data.InvertedIndex
|
||||||
( InvertedIndex,
|
( InvertedIndex,
|
||||||
iiFromList,
|
iiFromList,
|
||||||
iiInsert,
|
iiInsert,
|
@ -1,20 +1,20 @@
|
|||||||
module App (run, helpText) where
|
module NixTree.App (run, helpText) where
|
||||||
|
|
||||||
import qualified Brick as B
|
import qualified Brick as B
|
||||||
import qualified Brick.BChan as B
|
import qualified Brick.BChan as B
|
||||||
import qualified Brick.Widgets.Border as B
|
import qualified Brick.Widgets.Border as B
|
||||||
import qualified Brick.Widgets.Center as B
|
import qualified Brick.Widgets.Center as B
|
||||||
import qualified Brick.Widgets.List as B
|
import qualified Brick.Widgets.List as B
|
||||||
import qualified Clipboard
|
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
|
import Data.InvertedIndex
|
||||||
import qualified Data.List.NonEmpty as NE
|
import qualified Data.List.NonEmpty as NE
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import qualified Data.Sequence as S
|
import qualified Data.Sequence as S
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Graphics.Vty as V
|
import qualified Graphics.Vty as V
|
||||||
import InvertedIndex
|
import qualified NixTree.Clipboard as Clipboard
|
||||||
import PathStats
|
import NixTree.PathStats
|
||||||
import qualified System.Clock as Clock
|
import qualified System.Clock as Clock
|
||||||
import qualified System.HrfSize as HRF
|
import qualified System.HrfSize as HRF
|
||||||
|
|
||||||
@ -335,7 +335,7 @@ yankToClipboard p =
|
|||||||
( T.intercalate "\n" $
|
( T.intercalate "\n" $
|
||||||
"Cannot copy to clipboard: " :
|
"Cannot copy to clipboard: " :
|
||||||
map (" " <>) errs
|
map (" " <>) errs
|
||||||
++ ["Please report this as a bug."]
|
++ ["Please report this as a bug."]
|
||||||
)
|
)
|
||||||
|
|
||||||
renderMainScreen :: AppEnv s -> B.Widget Widgets
|
renderMainScreen :: AppEnv s -> B.Widget Widgets
|
@ -1,4 +1,4 @@
|
|||||||
module Clipboard
|
module NixTree.Clipboard
|
||||||
( copy,
|
( copy,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
@ -27,7 +27,7 @@ runCmd txt (cmd, args) =
|
|||||||
Right (Just (ExitSuccess, _, _)) -> Right ()
|
Right (Just (ExitSuccess, _, _)) -> Right ()
|
||||||
Right (Just (ExitFailure e, out, err)) ->
|
Right (Just (ExitFailure e, out, err)) ->
|
||||||
Left $
|
Left $
|
||||||
"failed with exit code "
|
"failed with exit code "
|
||||||
<> show e
|
<> show e
|
||||||
<> ", "
|
<> ", "
|
||||||
<> "stdout: "
|
<> "stdout: "
|
@ -1,10 +1,10 @@
|
|||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import App
|
import NixTree.App
|
||||||
import Control.Concurrent (forkIO)
|
import Control.Concurrent (forkIO)
|
||||||
import qualified Data.HashMap.Strict as HM
|
import qualified Data.HashMap.Strict as HM
|
||||||
import Data.Version (showVersion)
|
import Data.Version (showVersion)
|
||||||
import PathStats
|
import NixTree.PathStats
|
||||||
import Paths_nix_tree (version)
|
import Paths_nix_tree (version)
|
||||||
import System.Directory (canonicalizePath, doesDirectoryExist, getHomeDirectory)
|
import System.Directory (canonicalizePath, doesDirectoryExist, getHomeDirectory)
|
||||||
import System.Environment (getArgs)
|
import System.Environment (getArgs)
|
@ -1,9 +1,9 @@
|
|||||||
module PathStats
|
module NixTree.PathStats
|
||||||
( PathStats (..),
|
( PathStats (..),
|
||||||
calculatePathStats,
|
calculatePathStats,
|
||||||
whyDepends,
|
whyDepends,
|
||||||
shortestPathTo,
|
shortestPathTo,
|
||||||
module StorePath,
|
module NixTree.StorePath,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ import Data.List (minimumBy)
|
|||||||
import qualified Data.List.NonEmpty as NE
|
import qualified Data.List.NonEmpty as NE
|
||||||
import qualified Data.Map.Lazy as M
|
import qualified Data.Map.Lazy as M
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import StorePath
|
import NixTree.StorePath
|
||||||
|
|
||||||
data IntermediatePathStats s = IntermediatePathStats
|
data IntermediatePathStats s = IntermediatePathStats
|
||||||
{ ipsAllRefs :: M.Map (StoreName s) (StorePath s (StoreName s) ())
|
{ ipsAllRefs :: M.Map (StoreName s) (StorePath s (StoreName s) ())
|
@ -1,4 +1,4 @@
|
|||||||
module StorePath
|
module NixTree.StorePath
|
||||||
( StoreName (..),
|
( StoreName (..),
|
||||||
storeNameToPath,
|
storeNameToPath,
|
||||||
storeNameToText,
|
storeNameToText,
|
36
test/Test.hs
36
test/Test.hs
@ -2,39 +2,11 @@
|
|||||||
|
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import qualified Data.Map as Map
|
|
||||||
import qualified Data.Text as Text
|
|
||||||
import Hedgehog
|
import Hedgehog
|
||||||
import qualified Hedgehog.Gen as Gen
|
|
||||||
import Hedgehog.Main
|
import Hedgehog.Main
|
||||||
import qualified Hedgehog.Range as Range
|
import qualified Test.Data.InvertedIndex
|
||||||
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 :: IO ()
|
||||||
main = defaultMain [checkParallel $$(discover)]
|
main =
|
||||||
|
defaultMain . map checkParallel $
|
||||||
|
[Test.Data.InvertedIndex.tests]
|
||||||
|
39
test/Test/Data/InvertedIndex.hs
Normal file
39
test/Test/Data/InvertedIndex.hs
Normal 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
37
test/Test/Data/Test.hs
Normal 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
|
Loading…
Reference in New Issue
Block a user