packages feed

word8 0.0.2 → 0.0.3

raw patch · 6 files changed

+276/−3 lines, 6 filesdep +bytestringdep +criteriondep +hspecdep ~base

Dependencies added: bytestring, criterion, hspec, word8

Dependency ranges changed: base

Files

Data/Char8.hs view
@@ -104,7 +104,7 @@ isAscii c = _nul <= c && c <= _del  isLatin1 :: Char -> Bool-isLatin1 (C# c#) = ord# c# <# 0xff#+isLatin1 (C# c#) = ord# c# <=# 0xff#  isAsciiUpper :: Char -> Bool isAsciiUpper c = 'A' <= c && c <= 'Z'
+ bench/Bench.hs view
@@ -0,0 +1,17 @@+module Main where++import Criterion.Main+import qualified Data.ByteString as S+import qualified Data.ByteString.Char8 as S8+import qualified Data.Char+import qualified Data.Char8+import qualified Data.Word8++main :: IO ()+main = do+    input <- S.readFile "bench/Bench.hs"+    defaultMain [ +        bench "Data.Char"  $ whnf (S8.map Data.Char.toLower) input+      , bench "Data.Char8" $ whnf (S8.map Data.Char8.toLower) input+      , bench "Data.Word8" $ whnf (S.map Data.Word8.toLower) input+      ]
+ test/Char8Spec.hs view
@@ -0,0 +1,116 @@+module Char8Spec where++import qualified Data.Char as C+import Data.Char8+import Test.Hspec+import Test.Hspec.QuickCheck++spec :: Spec+spec = do+    describe "isControl" $ do+        prop "behaves like model" $ \c ->+            isControl c == C.isControl c++    describe "isSpace" $ do+        prop "behaves like model" $ \c ->+            isSpace c == C.isSpace c++    describe "isLower" $ do+        prop "behaves like model" $ \c ->+            isLower c == C.isLower c++    describe "isUpper" $ do+        prop "behaves like model" $ \c ->+            isUpper c == C.isUpper c++    describe "isAlpha" $ do+        prop "behaves like model" $ \c ->+            isAlpha c == C.isAlpha c++    describe "isAlphaNum" $ do+        prop "behaves like model" $ \c ->+            isAlphaNum c == C.isAlphaNum c++    describe "isPrint" $ do+        prop "behaves like model" $ \c ->+            isPrint c == C.isPrint c++    describe "isDigit" $ do+        prop "behaves like model" $ \c ->+            isDigit c == C.isDigit c++    describe "isOctDigit" $ do+        prop "behaves like model" $ \c ->+            isOctDigit c == C.isOctDigit c++    describe "isHexDigit" $ do+        prop "behaves like model" $ \c ->+            isHexDigit c == C.isHexDigit c++    describe "isLetter" $ do+        prop "behaves like model" $ \c ->+            isLetter c == C.isLetter c++    describe "isMark" $ do+        prop "behaves like model" $ \c ->+            isMark c == C.isMark c++    describe "isNumber" $ do+        prop "behaves like model" $ \c ->+            isNumber c == C.isNumber c++    describe "isPunctuation" $ do+        prop "behaves like model" $ \c ->+            isPunctuation c == C.isPunctuation c++    describe "isSymbol" $ do+        prop "behaves like model" $ \c ->+            isSymbol c == C.isSymbol c++    describe "isSeparator" $ do+        prop "behaves like model" $ \c ->+            isSeparator c == C.isSeparator c++    describe "isAscii" $ do+        prop "behaves like model" $ \c ->+            isAscii c == C.isAscii c++    describe "isLatin1" $ do+        prop "behaves like model" $ \c ->+            isLatin1 c == C.isLatin1 c++    describe "isAsciiUpper" $ do+        prop "behaves like model" $ \c ->+            isAsciiUpper c == C.isAsciiUpper c++    describe "isAsciiLower" $ do+        prop "behaves like model" $ \c ->+            isAsciiLower c == C.isAsciiLower c++    describe "toUpper" $ do+        prop "behaves like model" $ prop_toUpper++    describe "toLower" $ do+        prop "behaves like model" $ \c ->+            toLower c == C.toLower c++    describe "toTitle" $ do+        prop "behaves like model" $ prop_toTitle++prop_toUpper :: Char -> Bool+prop_toUpper c+  | c == _mu        = True+  | c == _ydieresis = True+  | otherwise       = toUpper c == C.toUpper c+    +prop_toTitle :: Char -> Bool+prop_toTitle c+  | c == _mu  = True+  | c == _ydieresis = True+  | otherwise = toTitle c == C.toTitle c++----------------------------------------------------------------++_mu, _ydieresis :: Char+_mu        = '\xb5'+_ydieresis = '\xff'
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
+ test/Word8Spec.hs view
@@ -0,0 +1,115 @@+module Word8Spec where++import qualified Data.Char as C+import Data.Word8+import Test.Hspec+import Test.Hspec.QuickCheck++spec :: Spec+spec = do+    describe "isControl" $ do+        prop "behaves like model" $ \w ->+            isControl w == C.isControl (word8ToChar w)++    describe "isSpace" $ do+        prop "behaves like model" $ \w ->+            isSpace w == C.isSpace (word8ToChar w)++    describe "isLower" $ do+        prop "behaves like model" $ \w ->+            isLower w == C.isLower (word8ToChar w)++    describe "isUpper" $ do+        prop "behaves like model" $ \w ->+            isUpper w == C.isUpper (word8ToChar w)++    describe "isAlpha" $ do+        prop "behaves like model" $ \w ->+            isAlpha w == C.isAlpha (word8ToChar w)++    describe "isAlphaNum" $ do+        prop "behaves like model" $ \w ->+            isAlphaNum w == C.isAlphaNum (word8ToChar w)++    describe "isPrint" $ do+        prop "behaves like model" $ \w ->+            isPrint w == C.isPrint (word8ToChar w)++    describe "isDigit" $ do+        prop "behaves like model" $ \w ->+            isDigit w == C.isDigit (word8ToChar w)++    describe "isOctDigit" $ do+        prop "behaves like model" $ \w ->+            isOctDigit w == C.isOctDigit (word8ToChar w)++    describe "isHexDigit" $ do+        prop "behaves like model" $ \w ->+            isHexDigit w == C.isHexDigit (word8ToChar w)++    describe "isLetter" $ do+        prop "behaves like model" $ \w ->+            isLetter w == C.isLetter (word8ToChar w)++    describe "isMark" $ do+        prop "behaves like model" $ \w ->+            isMark w == C.isMark (word8ToChar w)++    describe "isNumber" $ do+        prop "behaves like model" $ \w ->+            isNumber w == C.isNumber (word8ToChar w)++    describe "isPunctuation" $ do+        prop "behaves like model" $ \w ->+            isPunctuation w == C.isPunctuation (word8ToChar w)++    describe "isSymbol" $ do+        prop "behaves like model" $ \w ->+            isSymbol w == C.isSymbol (word8ToChar w)++    describe "isSeparator" $ do+        prop "behaves like model" $ \w ->+            isSeparator w == C.isSeparator (word8ToChar w)++    describe "isAscii" $ do+        prop "behaves like model" $ \w ->+            isAscii w == C.isAscii (word8ToChar w)++    describe "isLatin1" $ do+        prop "behaves like model" $ \w ->+            isLatin1 w == C.isLatin1 (word8ToChar w)++    describe "isAsciiUpper" $ do+        prop "behaves like model" $ \w ->+            isAsciiUpper w == C.isAsciiUpper (word8ToChar w)++    describe "isAsciiLower" $ do+        prop "behaves like model" $ \w ->+            isAsciiLower w == C.isAsciiLower (word8ToChar w)++    describe "toUpper" $ do+        prop "behaves like model" $ prop_toUpper++    describe "toLower" $ do+        prop "behaves like model" $ \w ->+            word8ToChar (toLower w) == C.toLower (word8ToChar w)++    describe "toTitle" $ do+        prop "behaves like model" $ prop_toTitle++prop_toUpper :: Word8 -> Bool+prop_toUpper w+  | w == _mu        = True+  | w == _ydieresis = True+  | otherwise       = word8ToChar (toUpper w) == C.toUpper (word8ToChar w)++prop_toTitle :: Word8 -> Bool+prop_toTitle w+  | w == _mu  = True+  | w == _ydieresis = True+  | otherwise = word8ToChar (toTitle w) == C.toTitle (word8ToChar w)++----------------------------------------------------------------++word8ToChar :: Word8 -> Char+word8ToChar = C.chr . fromIntegral
word8.cabal view
@@ -1,5 +1,5 @@ Name:                   word8-Version:                0.0.2+Version:                0.0.3 Author:                 Kazu Yamamoto <kazu@iij.ad.jp> Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp> License:                BSD3@@ -7,14 +7,38 @@ Synopsis:               Word8 library Description:            Word8 library to be used with Data.ByteString Category:               Data-Cabal-Version:          >= 1.8+Cabal-Version:          >= 1.10 Build-Type:             Simple  Library+  Default-Language:     Haskell2010   GHC-Options:          -Wall   Exposed-Modules:      Data.Char8                         Data.Word8   Build-Depends:        base >= 4 && < 5++Test-Suite spec+  Type:                 exitcode-stdio-1.0+  Default-Language:     Haskell2010+  Hs-Source-Dirs:       test+  Ghc-Options:          -Wall+  Main-Is:              Spec.hs+  Other-Modules:        Char8Spec+                        Word8Spec+  Build-Depends:        base+                      , word8+                      , hspec++Benchmark criterion+  Type:                 exitcode-stdio-1.0+  Default-Language:     Haskell2010+  Hs-Source-Dirs:       bench+  Ghc-Options:          -Wall+  Main-Is:              Bench.hs+  Build-Depends:        base+                      , bytestring+                      , criterion+                      , word8  Source-Repository head   Type:                 git