string-transform 0.0.1 → 0.1.0
raw patch · 4 files changed
+39/−33 lines, 4 files
Files
- README.md +2/−11
- src/Data/String/Transform.hs +17/−0
- string-transform.cabal +2/−2
- test/Main.hs +18/−20
README.md view
@@ -1,18 +1,9 @@ # string-transform [](https://travis-ci.org/ncaq/string-transform)--It is--* `Prelude.String`-* `Data.ByteString.ByteString`-* `Data.ByteString.Lazy.ByteString`-* `Data.Text.Text`-* `Data.Text.Lazy.Text`--transform wrapper.+ -It is **simple** and **easy**.+simple and easy haskell string transform wrapper. # provide function
src/Data/String/Transform.hs view
@@ -1,6 +1,8 @@ {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE IncoherentInstances #-} {-# LANGUAGE Safe #-} {-# LANGUAGE TypeSynonymInstances #-}+{-# LANGUAGE UndecidableInstances #-} module Data.String.Transform where import qualified Data.ByteString as B@@ -30,6 +32,9 @@ instance ToString TL.Text where toString = TL.unpack +instance Show a => ToString a where+ toString = show+ class ToByteStringStrict a where toByteStringStrict :: a -> B.ByteString @@ -48,6 +53,9 @@ instance ToByteStringStrict TL.Text where toByteStringStrict = T.encodeUtf8 . TL.toStrict +instance Show a => ToByteStringStrict a where+ toByteStringStrict = toByteStringStrict . show+ class ToByteStringLazy a where toByteStringLazy :: a -> BL.ByteString @@ -66,6 +74,9 @@ instance ToByteStringLazy TL.Text where toByteStringLazy = TL.encodeUtf8 +instance Show a => ToByteStringLazy a where+ toByteStringLazy = toByteStringLazy . show+ class ToTextStrict a where toTextStrict :: a -> T.Text @@ -84,6 +95,9 @@ instance ToTextStrict TL.Text where toTextStrict = TL.toStrict +instance Show a => ToTextStrict a where+ toTextStrict = toTextStrict . show+ class ToTextLazy a where toTextLazy :: a -> TL.Text @@ -101,3 +115,6 @@ instance ToTextLazy TL.Text where toTextLazy = id++instance Show a => ToTextLazy a where+ toTextLazy = toTextLazy . show
string-transform.cabal view
@@ -3,8 +3,8 @@ -- see: https://github.com/sol/hpack name: string-transform-version: 0.0.1-synopsis: simple and easy haskell string transform+version: 0.1.0+synopsis: simple and easy haskell string transform wrapper category: Text homepage: https://github.com/ncaq/string-transform#readme bug-reports: https://github.com/ncaq/string-transform/issues
test/Main.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE ScopedTypeVariables #-} module Main (main) where import Data.String.Transform@@ -16,28 +17,25 @@ smallCheckTest :: [TestTree] smallCheckTest =- [ testProperty "toByteStringStrict" prop_toByteStringStrict_toString- , testProperty "toByteStringLazy" prop_toByteStringLazy_toString- , testProperty "toTextStrict" prop_toTextStrict_toString- , testProperty "toTextLazy" prop_toTextLazy_toString+ [ testProperty "s == toString (toByteStringStrict s)"+ (\(s :: String) -> s == toString (toByteStringStrict s))+ , testProperty "s == toString (toByteStringLazy s)"+ (\(s :: String) -> s == toString (toByteStringLazy s))+ , testProperty "s == toString (toTextStrict s)"+ (\(s :: String) -> s == toString (toTextStrict s))+ , testProperty "s == toString (toTextLazy s)"+ (\(s :: String) -> s == toString (toTextLazy s))+ , testProperty "a == b ⇔ toByteStringStrict a == toByteStringStrict b"+ (\(a :: String) (b :: String) ->+ let p = a == b+ q = toByteStringStrict a == toByteStringStrict b+ in p == q) ] hunitTest :: [TestTree] hunitTest =- [ testCase "toByteStringStrict 日本語" case_japanese_toByteStrictStrict_toString+ [ testCase "toString 1" (toString 1 @?= "1")+ , testCase "toByteStringStrict 1" (toByteStringStrict 1 @?= toByteStringStrict "1")+ , testCase "toTextStrict 1" (toTextStrict 1 @?= toTextStrict "1")+ , testCase "toByteStringStrict 日本語" (toString (toByteStringStrict "日本語") @?= "日本語") ]--prop_toByteStringStrict_toString :: String -> Bool-prop_toByteStringStrict_toString string = string == toString (toByteStringStrict string)--prop_toByteStringLazy_toString :: String -> Bool-prop_toByteStringLazy_toString string = string == toString (toByteStringLazy string)--prop_toTextStrict_toString :: String -> Bool-prop_toTextStrict_toString string = string == toString (toTextStrict string)--prop_toTextLazy_toString :: String -> Bool-prop_toTextLazy_toString string = string == toString (toTextLazy string)--case_japanese_toByteStrictStrict_toString :: Assertion-case_japanese_toByteStrictStrict_toString = toString (toByteStringStrict "日本語") @?= "日本語"