From 0a3ae16ed27fd140b3e7c2a21b3fbdb5d404cbb5 Mon Sep 17 00:00:00 2001 From: Sean D Gillespie Date: Sat, 16 Mar 2024 21:31:24 -0400 Subject: [PATCH] refactor(lib): Restructure modules --- app/Main.hs | 7 +-- app/gen-trigraph.hs | 2 +- gibberish.cabal | 16 ++++--- src/Data/Gibberish.hs | 46 +++++++++++++++++++ .../Gibberish/{Format.hs => Formatting.hs} | 2 +- src/Data/Gibberish/Gen.hs | 7 +++ .../Gibberish/{GenPass.hs => Gen/Pass.hs} | 4 +- src/Data/Gibberish/{ => Gen}/Trigraph.hs | 3 +- .../Gibberish/{MonadPass.hs => Monad/Pass.hs} | 2 +- src/Data/Gibberish/Types.hs | 3 -- .../{FormatSpec.hs => FormattingSpec.hs} | 4 +- .../{GenPassSpec.hs => Gen/PassSpec.hs} | 8 ++-- test/Data/Gibberish/{ => Gen}/TrigraphSpec.hs | 5 +- test/Data/Gibberish/UtilsSpec.hs | 2 +- test/Golden.hs | 2 +- 15 files changed, 82 insertions(+), 31 deletions(-) create mode 100644 src/Data/Gibberish.hs rename src/Data/Gibberish/{Format.hs => Formatting.hs} (99%) create mode 100644 src/Data/Gibberish/Gen.hs rename src/Data/Gibberish/{GenPass.hs => Gen/Pass.hs} (98%) rename src/Data/Gibberish/{ => Gen}/Trigraph.hs (97%) rename src/Data/Gibberish/{MonadPass.hs => Monad/Pass.hs} (98%) rename test/Data/Gibberish/{FormatSpec.hs => FormattingSpec.hs} (98%) rename test/Data/Gibberish/{GenPassSpec.hs => Gen/PassSpec.hs} (96%) rename test/Data/Gibberish/{ => Gen}/TrigraphSpec.hs (96%) diff --git a/app/Main.hs b/app/Main.hs index 0723290..6785219 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,10 +1,7 @@ module Main (main) where -import Data.Gibberish.Format qualified as Fmt -import Data.Gibberish.GenPass (genPassphrase, genPassword) -import Data.Gibberish.MonadPass (Pass (), usingPass) -import Data.Gibberish.Trigraph (Language (..), TrigraphConfig (..), loadTrigraph) -import Data.Gibberish.Types (GenPassphraseOpts (..), GenPasswordOpts (..)) +import Data.Gibberish +import Data.Gibberish.Formatting qualified as Fmt import Control.Monad.IO.Class (MonadIO (..)) import Data.Text (Text ()) diff --git a/app/gen-trigraph.hs b/app/gen-trigraph.hs index 3367695..8611348 100644 --- a/app/gen-trigraph.hs +++ b/app/gen-trigraph.hs @@ -1,6 +1,6 @@ module Main (main) where -import Data.Gibberish.Trigraph (genTrigraph) +import Data.Gibberish (genTrigraph) import Data.Aeson.Encode.Pretty (encodePretty) import Data.ByteString.Lazy (ByteString ()) diff --git a/gibberish.cabal b/gibberish.cabal index 957eb6a..8eb4368 100644 --- a/gibberish.cabal +++ b/gibberish.cabal @@ -95,11 +95,13 @@ common common-test library import: common-options exposed-modules: + Data.Gibberish, Data.Gibberish.Errors, - Data.Gibberish.Format, - Data.Gibberish.GenPass, - Data.Gibberish.MonadPass, - Data.Gibberish.Trigraph, + Data.Gibberish.Formatting, + Data.Gibberish.Gen, + Data.Gibberish.Gen.Pass, + Data.Gibberish.Gen.Trigraph, + Data.Gibberish.Monad.Pass, Data.Gibberish.Types, Data.Gibberish.Utils other-modules: @@ -145,9 +147,9 @@ test-suite spec build-tool-depends: hspec-discover:hspec-discover other-modules: - Data.Gibberish.FormatSpec - Data.Gibberish.GenPassSpec - Data.Gibberish.TrigraphSpec + Data.Gibberish.FormattingSpec + Data.Gibberish.Gen.PassSpec + Data.Gibberish.Gen.TrigraphSpec Data.Gibberish.TypesSpec Data.Gibberish.UtilsSpec Paths_gibberish diff --git a/src/Data/Gibberish.hs b/src/Data/Gibberish.hs new file mode 100644 index 0000000..2d4d614 --- /dev/null +++ b/src/Data/Gibberish.hs @@ -0,0 +1,46 @@ +module Data.Gibberish + ( -- * Core types + GenPasswordOpts (..), + GenPassphraseOpts (..), + Unigram (..), + Digram (..), + Trigram (..), + Frequency (..), + Frequencies (..), + Trigraph (..), + Word (..), + + -- * Password/phrase generation + genPassword, + genPassphrase, + genPassphrase', + + -- * Trigraph generation + Language (..), + TrigraphConfig (..), + genTrigraph, + loadTrigraph, + + -- * Password/phrase generation monad + Pass (), + PassT (..), + MonadRandom (..), + runPass, + evalPass, + usingPass, + runPassT, + evalPassT, + usingPassT, + + -- * Error handling + GibberishErr (..), + isTrigraphNotFound, + isImpossibleError, + ) where + +import Data.Gibberish.Errors +import Data.Gibberish.Gen +import Data.Gibberish.Monad.Pass +import Data.Gibberish.Types + +import Prelude hiding (Word ()) diff --git a/src/Data/Gibberish/Format.hs b/src/Data/Gibberish/Formatting.hs similarity index 99% rename from src/Data/Gibberish/Format.hs rename to src/Data/Gibberish/Formatting.hs index 3229f20..055e0ed 100644 --- a/src/Data/Gibberish/Format.hs +++ b/src/Data/Gibberish/Formatting.hs @@ -1,4 +1,4 @@ -module Data.Gibberish.Format +module Data.Gibberish.Formatting ( FormatOpts (..), MaxLen (..), MaxHeight (..), diff --git a/src/Data/Gibberish/Gen.hs b/src/Data/Gibberish/Gen.hs new file mode 100644 index 0000000..b2295e5 --- /dev/null +++ b/src/Data/Gibberish/Gen.hs @@ -0,0 +1,7 @@ +module Data.Gibberish.Gen + ( module Data.Gibberish.Gen.Pass, + module Data.Gibberish.Gen.Trigraph, + ) where + +import Data.Gibberish.Gen.Pass +import Data.Gibberish.Gen.Trigraph diff --git a/src/Data/Gibberish/GenPass.hs b/src/Data/Gibberish/Gen/Pass.hs similarity index 98% rename from src/Data/Gibberish/GenPass.hs rename to src/Data/Gibberish/Gen/Pass.hs index 2a832c5..228d593 100644 --- a/src/Data/Gibberish/GenPass.hs +++ b/src/Data/Gibberish/Gen/Pass.hs @@ -1,13 +1,13 @@ {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE ScopedTypeVariables #-} -module Data.Gibberish.GenPass +module Data.Gibberish.Gen.Pass ( genPassword, genPassphrase, genPassphrase', ) where -import Data.Gibberish.MonadPass (MonadRandom ()) +import Data.Gibberish.Monad.Pass (MonadRandom ()) import Data.Gibberish.Types import Data.Gibberish.Utils diff --git a/src/Data/Gibberish/Trigraph.hs b/src/Data/Gibberish/Gen/Trigraph.hs similarity index 97% rename from src/Data/Gibberish/Trigraph.hs rename to src/Data/Gibberish/Gen/Trigraph.hs index 3589e55..927b32b 100644 --- a/src/Data/Gibberish/Trigraph.hs +++ b/src/Data/Gibberish/Gen/Trigraph.hs @@ -1,12 +1,13 @@ {-# LANGUAGE OverloadedLists #-} -module Data.Gibberish.Trigraph +module Data.Gibberish.Gen.Trigraph ( Language (..), TrigraphConfig (..), genTrigraph, loadTrigraph, ) where +import Data.Gibberish.Errors (GibberishErr (..)) import Data.Gibberish.Utils (toQwertyKey) import Paths_gibberish (getDataFileName) diff --git a/src/Data/Gibberish/MonadPass.hs b/src/Data/Gibberish/Monad/Pass.hs similarity index 98% rename from src/Data/Gibberish/MonadPass.hs rename to src/Data/Gibberish/Monad/Pass.hs index 9d68e10..7911a7e 100644 --- a/src/Data/Gibberish/MonadPass.hs +++ b/src/Data/Gibberish/Monad/Pass.hs @@ -1,4 +1,4 @@ -module Data.Gibberish.MonadPass +module Data.Gibberish.Monad.Pass ( Pass (), PassT (..), MonadRandom (..), diff --git a/src/Data/Gibberish/Types.hs b/src/Data/Gibberish/Types.hs index 46d4648..0da3e50 100644 --- a/src/Data/Gibberish/Types.hs +++ b/src/Data/Gibberish/Types.hs @@ -10,11 +10,8 @@ module Data.Gibberish.Types Frequencies (..), Trigraph (..), Word (..), - module Data.Gibberish.Errors, ) where -import Data.Gibberish.Errors - import Control.DeepSeq (NFData) import Data.Aeson (FromJSON (..), FromJSONKey (..), ToJSON (..), ToJSONKey (..)) import Data.Aeson qualified as Aeson diff --git a/test/Data/Gibberish/FormatSpec.hs b/test/Data/Gibberish/FormattingSpec.hs similarity index 98% rename from test/Data/Gibberish/FormatSpec.hs rename to test/Data/Gibberish/FormattingSpec.hs index ce7ee48..3b34321 100644 --- a/test/Data/Gibberish/FormatSpec.hs +++ b/test/Data/Gibberish/FormattingSpec.hs @@ -1,6 +1,6 @@ -module Data.Gibberish.FormatSpec (spec) where +module Data.Gibberish.FormattingSpec (spec) where -import Data.Gibberish.Format +import Data.Gibberish.Formatting import Data.Gibberish.Types import Control.Monad (forM_) diff --git a/test/Data/Gibberish/GenPassSpec.hs b/test/Data/Gibberish/Gen/PassSpec.hs similarity index 96% rename from test/Data/Gibberish/GenPassSpec.hs rename to test/Data/Gibberish/Gen/PassSpec.hs index c8e4b45..532bf81 100644 --- a/test/Data/Gibberish/GenPassSpec.hs +++ b/test/Data/Gibberish/Gen/PassSpec.hs @@ -1,8 +1,8 @@ -module Data.Gibberish.GenPassSpec (spec) where +module Data.Gibberish.Gen.PassSpec (spec) where -import Data.Gibberish.GenPass (genPassphrase, genPassphrase', genPassword) -import Data.Gibberish.MonadPass (usingPass, usingPassT) -import Data.Gibberish.Trigraph (Language (..), loadTrigraph) +import Data.Gibberish.Gen.Pass (genPassphrase, genPassphrase', genPassword) +import Data.Gibberish.Gen.Trigraph (Language (..), loadTrigraph) +import Data.Gibberish.Monad.Pass (usingPass, usingPassT) import Data.Gibberish.Types import Data.Gibberish.Utils (numeralConversions, symbolConversions) import Test.Gibberish.Gen qualified as Gen diff --git a/test/Data/Gibberish/TrigraphSpec.hs b/test/Data/Gibberish/Gen/TrigraphSpec.hs similarity index 96% rename from test/Data/Gibberish/TrigraphSpec.hs rename to test/Data/Gibberish/Gen/TrigraphSpec.hs index 0ffff55..baa7e2b 100644 --- a/test/Data/Gibberish/TrigraphSpec.hs +++ b/test/Data/Gibberish/Gen/TrigraphSpec.hs @@ -1,8 +1,9 @@ {-# LANGUAGE OverloadedLists #-} -module Data.Gibberish.TrigraphSpec (spec) where +module Data.Gibberish.Gen.TrigraphSpec (spec) where -import Data.Gibberish.Trigraph +import Data.Gibberish.Errors (isTrigraphNotFound) +import Data.Gibberish.Gen.Trigraph import Data.Gibberish.Types import Data.Gibberish.Utils (qwertyKeys) import Paths_gibberish (getDataFileName) diff --git a/test/Data/Gibberish/UtilsSpec.hs b/test/Data/Gibberish/UtilsSpec.hs index 3093096..bfc3e73 100644 --- a/test/Data/Gibberish/UtilsSpec.hs +++ b/test/Data/Gibberish/UtilsSpec.hs @@ -1,6 +1,6 @@ module Data.Gibberish.UtilsSpec (spec) where -import Data.Gibberish.MonadPass (usingPass) +import Data.Gibberish.Monad.Pass (usingPass) import Data.Gibberish.Utils import Test.Gibberish.Gen qualified as Gen diff --git a/test/Golden.hs b/test/Golden.hs index e8d11c7..70a8e0d 100644 --- a/test/Golden.hs +++ b/test/Golden.hs @@ -1,6 +1,6 @@ module Main (main) where -import Data.Gibberish.Trigraph (genTrigraph) +import Data.Gibberish (genTrigraph) import Data.Aeson.Encode.Pretty (encodePretty) import Data.ByteString.Lazy (ByteString ())