mirror of
https://github.com/haskell-nix/hnix-store.git
synced 2025-01-05 19:00:24 +03:00
Fix text encoding to utf8
This commit is contained in:
parent
474725b3de
commit
ffc0cc4519
@ -62,6 +62,8 @@ test-suite hnix-store-remote-tests
|
||||
main-is: Driver.hs
|
||||
other-modules: Derivation
|
||||
, NixDaemon
|
||||
, Spec
|
||||
, Util
|
||||
hs-source-dirs: tests
|
||||
build-depends:
|
||||
attoparsec
|
||||
@ -76,6 +78,7 @@ test-suite hnix-store-remote-tests
|
||||
, process
|
||||
, filepath
|
||||
, hspec-expectations-lifted
|
||||
, quickcheck-text
|
||||
, tasty
|
||||
, tasty-discover
|
||||
, tasty-hspec
|
||||
|
@ -11,6 +11,9 @@ import Data.Binary.Get
|
||||
import Data.Binary.Put
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.Encoding as T
|
||||
import qualified Data.Text.Lazy as TL
|
||||
import qualified Data.Text.Lazy.Encoding as TL
|
||||
import Data.Time
|
||||
import Data.Time.Clock.POSIX
|
||||
import Data.ByteString (ByteString)
|
||||
@ -91,13 +94,16 @@ sockGetPaths = do
|
||||
getSocketIncremental (getPaths sd)
|
||||
|
||||
bsToText :: ByteString -> Text
|
||||
bsToText = T.pack . BSC.unpack
|
||||
bsToText = T.decodeUtf8
|
||||
|
||||
textToBS :: Text -> ByteString
|
||||
textToBS = T.encodeUtf8
|
||||
|
||||
bslToText :: BSL.ByteString -> Text
|
||||
bslToText = T.pack . BSC.unpack . BSL.toStrict
|
||||
bslToText = TL.toStrict . TL.decodeUtf8
|
||||
|
||||
textToBSL :: Text -> BSL.ByteString
|
||||
textToBSL = BSL.fromStrict . BSC.pack . T.unpack
|
||||
textToBSL = TL.encodeUtf8 . TL.fromStrict
|
||||
|
||||
putText :: Text -> Put
|
||||
putText = putByteStringLen . textToBSL
|
||||
|
@ -1,8 +1,9 @@
|
||||
import Test.Tasty.Hspec
|
||||
import NixDaemon
|
||||
import qualified Spec
|
||||
|
||||
-- we run remote tests in
|
||||
-- Linux namespaces to avoid interacting with systems store
|
||||
main = do
|
||||
enterNamespaces
|
||||
hspec spec_protocol
|
||||
Spec.main
|
||||
|
1
hnix-store-remote/tests/Spec.hs
Normal file
1
hnix-store-remote/tests/Spec.hs
Normal file
@ -0,0 +1 @@
|
||||
{-# OPTIONS_GHC -F -pgmF tasty-discover -optF --generated-module=Spec #-}
|
13
hnix-store-remote/tests/Util.hs
Normal file
13
hnix-store-remote/tests/Util.hs
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
module Util where
|
||||
|
||||
import Test.Tasty.QuickCheck
|
||||
import Data.Text.Arbitrary
|
||||
|
||||
import System.Nix.Store.Remote.Util
|
||||
|
||||
prop_TextToBSLRoundtrip x =
|
||||
bslToText (textToBSL x) === x
|
||||
|
||||
prop_TextToBSRoundtrip x =
|
||||
bsToText (textToBS x) === x
|
Loading…
Reference in New Issue
Block a user