diff --git a/src/Encoding/UnixToUnix.hs b/src/Encoding/UnixToUnix.hs index dd0a090..e226ff5 100644 --- a/src/Encoding/UnixToUnix.hs +++ b/src/Encoding/UnixToUnix.hs @@ -14,10 +14,10 @@ import qualified Data.Text.IO as T decuu :: String -> String -- decuu = C.unpack . U.fromRight . UU.decode . BSU.fromString decuu input = - case UU.decode (BSU.fromString input) of + case UU.decode (T.encodeUtf8 (T.pack input)) of Right decoded -> T.unpack (T.decodeUtf8 decoded) Left _ -> "Error decoding UU.\n" encuu :: String -> String -encuu = C.unpack . UU.encode . BSU.fromString - +-- encuu = C.unpack . UU.encode . BSU.fromString +encuu = T.unpack . T.decodeUtf8 . UU.encode . T.encodeUtf8 . T.pack diff --git a/test/Main.hs b/test/Main.hs index 4fe0652..0ff692a 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -10,6 +10,7 @@ import Encoding.Base16 (enc16, dec16) import Encoding.Base8 (enc8, dec8) import Encoding.Base2 (enc2, dec2) import Encoding.QuotedPrintable (encqp, decqp) +import Encoding.UnixToUnix (encuu, decuu) import System.Exit (exitFailure, exitSuccess) testEnc91 :: Test @@ -123,6 +124,19 @@ testDecQp = TestCase $ do assertEqual "for (decqp \"QP=20works=20by=20using=20the=20equals=20sign=20=3D=20as=20an=20escape=20=\r\ncharacter.=20It=20also=20limits=20line=20length=20to=2076,=20as=20some=20=\r\nsoftware=20has=20limits=20on=20line=20length.\")," "QP works by using the equals sign = as an escape character. It also limits line length to 76, as some software has limits on line length." (decqp "QP=20works=20by=20using=20the=20equals=20sign=20=3D=20as=20an=20escape=20=\ncharacter.=20It=20also=20limits=20line=20length=20to=2076,=20as=20some=20=\nsoftware=20has=20limits=20on=20line=20length.") assertEqual "for (decqp \"=F0=9F=98=82\")," "😂" (decqp "=F0=9F=98=82") +testEnUu :: Test +testEnUu = TestCase $ do + assertEqual "for (encuu \"Hello, World!\")," "110 145 154 154 157 54 40 127 157 162 154 144 41" (encuu "Hello, World!") + assertEqual "for (encuu \"Haskell\")," "110 141 163 153 145 154 154" (encuu "Haskell") + assertEqual "for (encuu \"😂\")," "360 237 230 202" (encuu "😂") + +testDecUu :: Test +testDecUu = TestCase $ do + assertEqual "for (decuu \"110 145 154 154 157 54 40 127 157 162 154 144 41\")," "Hello, World!" (decuu "110 145 154 154 157 54 40 127 157 162 154 144 41") + assertEqual "for (decuu \"110 141 163 153 145 154 154\")," "Haskell" (decuu "110 141 163 153 145 154 154") + assertEqual "for (decuu \"360 237 230 202\")," "😂" (decuu "360 237 230 202") + + tests :: Test tests = TestList [TestLabel "Test enc91" testEnc91, TestLabel "Test dec91" testDec91,