mirror of
https://github.com/tfausak/witch.git
synced 2024-11-22 14:58:13 +03:00
Put string instances together
This commit is contained in:
parent
e5cabcd77d
commit
e89047f07a
@ -1049,15 +1049,6 @@ instance From.From ShortByteString.ShortByteString ByteString.ByteString where
|
||||
|
||||
-- Text
|
||||
|
||||
-- | Uses 'Text.pack'. Some 'Char' values cannot be represented in 'Text.Text'
|
||||
-- and will be replaced with @'\\xFFFD'@.
|
||||
instance From.From String Text.Text where
|
||||
from = Text.pack
|
||||
|
||||
-- | Uses 'Text.unpack'.
|
||||
instance From.From Text.Text String where
|
||||
from = Text.unpack
|
||||
|
||||
-- | Uses 'LazyText.fromStrict'.
|
||||
instance From.From Text.Text LazyText.Text where
|
||||
from = LazyText.fromStrict
|
||||
@ -1068,6 +1059,25 @@ instance From.From Text.Text ByteString.ByteString where
|
||||
|
||||
-- LazyText
|
||||
|
||||
-- | Uses 'LazyText.toStrict'.
|
||||
instance From.From LazyText.Text Text.Text where
|
||||
from = LazyText.toStrict
|
||||
|
||||
-- | Uses 'LazyText.encodeUtf8'.
|
||||
instance From.From LazyText.Text LazyByteString.ByteString where
|
||||
from = LazyText.encodeUtf8
|
||||
|
||||
-- String
|
||||
|
||||
-- | Uses 'Text.pack'. Some 'Char' values cannot be represented in 'Text.Text'
|
||||
-- and will be replaced with @'\\xFFFD'@.
|
||||
instance From.From String Text.Text where
|
||||
from = Text.pack
|
||||
|
||||
-- | Uses 'Text.unpack'.
|
||||
instance From.From Text.Text String where
|
||||
from = Text.unpack
|
||||
|
||||
-- | Uses 'LazyText.pack'. Some 'Char' values cannot be represented in
|
||||
-- 'LazyText.Text' and will be replaced with @'\\xFFFD'@.
|
||||
instance From.From String LazyText.Text where
|
||||
@ -1077,14 +1087,6 @@ instance From.From String LazyText.Text where
|
||||
instance From.From LazyText.Text String where
|
||||
from = LazyText.unpack
|
||||
|
||||
-- | Uses 'LazyText.toStrict'.
|
||||
instance From.From LazyText.Text Text.Text where
|
||||
from = LazyText.toStrict
|
||||
|
||||
-- | Uses 'LazyText.encodeUtf8'.
|
||||
instance From.From LazyText.Text LazyByteString.ByteString where
|
||||
from = LazyText.encodeUtf8
|
||||
|
||||
-- TryFromException
|
||||
|
||||
-- | Uses @coerce@.
|
||||
|
@ -1568,6 +1568,28 @@ main = runTestTTAndExit $ "Witch" ~:
|
||||
, f (ShortByteString.pack [0x00]) ~?= ByteString.pack [0x00]
|
||||
, f (ShortByteString.pack [0x0f, 0xf0]) ~?= ByteString.pack [0x0f, 0xf0]
|
||||
]
|
||||
, "From Text LazyText" ~:
|
||||
let f = Witch.from @Text.Text @LazyText.Text in
|
||||
[ f (Text.pack "") ~?= LazyText.pack ""
|
||||
, f (Text.pack "a") ~?= LazyText.pack "a"
|
||||
, f (Text.pack "ab") ~?= LazyText.pack "ab"
|
||||
]
|
||||
, "From Text ByteString" ~:
|
||||
let f = Witch.from @Text.Text @ByteString.ByteString in
|
||||
[ f (Text.pack "") ~?= ByteString.pack []
|
||||
, f (Text.pack "a") ~?= ByteString.pack [0x61]
|
||||
]
|
||||
, "From LazyText Text" ~:
|
||||
let f = Witch.from @LazyText.Text @Text.Text in
|
||||
[ f (LazyText.pack "") ~?= Text.pack ""
|
||||
, f (LazyText.pack "a") ~?= Text.pack "a"
|
||||
, f (LazyText.pack "ab") ~?= Text.pack "ab"
|
||||
]
|
||||
, "From LazyText LazyByteString" ~:
|
||||
let f = Witch.from @LazyText.Text @LazyByteString.ByteString in
|
||||
[ f (LazyText.pack "") ~?= LazyByteString.pack []
|
||||
, f (LazyText.pack "a") ~?= LazyByteString.pack [0x61]
|
||||
]
|
||||
, "From String Text" ~:
|
||||
let f = Witch.from @String @Text.Text in
|
||||
[ f "" ~?= Text.pack ""
|
||||
@ -1580,17 +1602,6 @@ main = runTestTTAndExit $ "Witch" ~:
|
||||
, f (Text.pack "a") ~?= "a"
|
||||
, f (Text.pack "ab") ~?= "ab"
|
||||
]
|
||||
, "From Text LazyText" ~:
|
||||
let f = Witch.from @Text.Text @LazyText.Text in
|
||||
[ f (Text.pack "") ~?= LazyText.pack ""
|
||||
, f (Text.pack "a") ~?= LazyText.pack "a"
|
||||
, f (Text.pack "ab") ~?= LazyText.pack "ab"
|
||||
]
|
||||
, "From Text ByteString" ~:
|
||||
let f = Witch.from @Text.Text @ByteString.ByteString in
|
||||
[ f (Text.pack "") ~?= ByteString.pack []
|
||||
, f (Text.pack "a") ~?= ByteString.pack [0x61]
|
||||
]
|
||||
, "From String LazyText" ~:
|
||||
let f = Witch.from @String @LazyText.Text in
|
||||
[ f "" ~?= LazyText.pack ""
|
||||
@ -1603,17 +1614,6 @@ main = runTestTTAndExit $ "Witch" ~:
|
||||
, f (LazyText.pack "a") ~?= "a"
|
||||
, f (LazyText.pack "ab") ~?= "ab"
|
||||
]
|
||||
, "From LazyText Text" ~:
|
||||
let f = Witch.from @LazyText.Text @Text.Text in
|
||||
[ f (LazyText.pack "") ~?= Text.pack ""
|
||||
, f (LazyText.pack "a") ~?= Text.pack "a"
|
||||
, f (LazyText.pack "ab") ~?= Text.pack "ab"
|
||||
]
|
||||
, "From LazyText LazyByteString" ~:
|
||||
let f = Witch.from @LazyText.Text @LazyByteString.ByteString in
|
||||
[ f (LazyText.pack "") ~?= LazyByteString.pack []
|
||||
, f (LazyText.pack "a") ~?= LazyByteString.pack [0x61]
|
||||
]
|
||||
, "From Integer Day" ~:
|
||||
let f = Witch.from @Integer @Time.Day in
|
||||
[ f 0 ~?= Time.ModifiedJulianDay 0
|
||||
|
Loading…
Reference in New Issue
Block a user