Bryan O'Sullivan committed 2202ddd

Test reading of integral types

Comments (0)

Files changed (1)


 import Text.Show.Functions ()
 import qualified Data.Bits as Bits (shiftL, shiftR)
-import Data.Char (chr, isLower, isSpace, isUpper, ord)
+import Numeric (showHex)
+import Data.Char (chr, isDigit, isHexDigit, isLower, isSpace, isUpper, ord)
 import Data.Monoid (Monoid(..))
 import Data.String (fromString)
 import Debug.Trace (trace)
 import qualified Data.Text.Lazy.Internal as TL
 import qualified Data.Text.Lazy.Builder as TB
 import qualified Data.Text.Encoding as E
+import Data.Text.Read as T
+import Data.Text.Lazy.Read as TL
 import Data.Text.Encoding.Error
 import Control.Exception (SomeException, bracket, catch, evaluate, try)
 import Data.Text.Foreign
         b2 = TB.fromText (packS s2)
         b3 = TB.fromText (packS s3)
+-- Reading.
+t_decimal (n::Int) s =
+    T.signed T.decimal (T.pack (show n) `T.append` t) == Right (n,t)
+    where t = T.dropWhile isDigit s
+tl_decimal (n::Int) s =
+    TL.signed TL.decimal (TL.pack (show n) `TL.append` t) == Right (n,t)
+    where t = TL.dropWhile isDigit s
+t_hexadecimal (n::Positive Int) s ox =
+    T.hexadecimal (T.concat [p, T.pack (showHex n ""), t]) == Right (n,t)
+    where t = T.dropWhile isHexDigit s
+          p = if ox then "0x" else ""
+tl_hexadecimal (n::Positive Int) s ox =
+    TL.hexadecimal (TL.concat [p, TL.pack (showHex n ""), t]) == Right (n,t)
+    where t = TL.dropWhile isHexDigit s
+          p = if ox then "0x" else ""
 -- Input and output.
 -- Work around lack of Show instance for TextEncoding.
     testProperty "t_builderAssociative" t_builderAssociative
+  testGroup "read" [
+    testProperty "t_decimal" t_decimal,
+    testProperty "tl_decimal" tl_decimal,
+    testProperty "t_hexadecimal" t_hexadecimal,
+    testProperty "tl_hexadecimal" tl_hexadecimal
+  ],
   testGroup "input-output" [
     testProperty "t_write_read" t_write_read,
     testProperty "tl_write_read" tl_write_read,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.