Rename StringUtil.hs to Util.hs

This commit is contained in:
CrystalSplitter 2023-10-14 21:41:43 -07:00
parent d1a62d351e
commit 33db7c4f32
5 changed files with 31 additions and 9 deletions

View File

@ -80,7 +80,7 @@ library ghcitui-lib
exposed-modules: Ghcid.Daemon
, Ghcid.ParseContext
, Loc
, StringUtil
, Util
, NameBinding
ghc-options: -Wall
-Wcompat
@ -102,4 +102,5 @@ test-suite spec
, hspec ^>= 2.11.5
, ghcitui-lib
other-modules: LocSpec
, UtilSpec
default-language: Haskell2010

View File

@ -58,9 +58,10 @@ import System.IO (stderr)
import qualified Ghcid.ParseContext as ParseContext
import qualified Loc
import qualified NameBinding
import qualified StringUtil
import Util (showT)
import qualified Util
newtype LogLevel = LogLevel Int
newtype LogLevel = LogLevel Int deriving (Eq, Ord, Show)
-- | Determines where the daemon logs are written.
data LogOutput = LogOutputStdOut | LogOutputStdErr | LogOutputFile FilePath

View File

@ -27,16 +27,13 @@ import Text.Regex.TDFA (MatchResult (..), (=~~))
import qualified Loc
import NameBinding
import StringUtil
import Util
ghcidPrompt :: T.Text
ghcidPrompt = "#~GHCID-START~#"
newtype ParseError = ParseError T.Text deriving (Show, Eq)
showT :: (Show a) => a -> T.Text
showT = T.pack . show
-- | Output record datatype for 'parseContext'.
data ParseContextOut = ParseContextOut
{ func :: !T.Text

View File

@ -1,6 +1,6 @@
module StringUtil (linesToText, splitBy) where
module Util (showT, splitBy, linesToText) where
import Data.Text (pack, Text, breakOn, drop, length)
import Data.Text (Text, breakOn, drop, length, pack)
import Prelude hiding (drop, length)
-- | Split text based on a delimiter.
@ -10,6 +10,7 @@ splitBy
-> Text
-- ^ Text to split on.
-> [Text]
splitBy "" source = [source]
splitBy delim source =
case breakOn delim source of
(l, "") -> [l]
@ -18,3 +19,7 @@ splitBy delim source =
-- | Convert Strings to Text.
linesToText :: [String] -> Text
linesToText = pack . Prelude.unlines
-- | 'show' but to Text.
showT :: (Show a) => a -> Text
showT = pack . show

18
test/UtilSpec.hs Normal file
View File

@ -0,0 +1,18 @@
{-# LANGUAGE OverloadedStrings #-}
module StringUtilSpec where
import Test.Hspec
import Util
spec :: Spec
spec = do
describe "splitBy" $ do
it "should not edit an empty text" $ do
splitBy "a" "" `shouldBe` [""]
it "should not split with an empty delimiter" $ do
splitBy "" "a" `shouldBe` ["a"]
it "should split by a delim" $ do
splitBy "a" "a" `shouldBe` ["", ""]
splitBy "b" "aba" `shouldBe` ["a", "a"]