Fix text encoding to utf8

This commit is contained in:
Guillaume Maudoux 2020-11-11 00:38:04 +01:00
parent 474725b3de
commit ffc0cc4519
5 changed files with 28 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF tasty-discover -optF --generated-module=Spec #-}

View 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