packages feed

http-date 0.0.1 → 0.0.2

raw patch · 5 files changed

+91/−15 lines, 5 filesdep +HUnitdep +http-datedep +old-locale

Dependencies added: HUnit, http-date, old-locale, test-framework-doctest, test-framework-hunit, test-framework-th-prime, time

Files

Network/HTTP/Date/Formatter.hs view
@@ -12,9 +12,11 @@  ---------------------------------------------------------------- -{-|-  Generating HTTP Date in RFC1123 style.--}+-- | Generating HTTP Date in RFC1123 style.+--+-- >>> formatHTTPDate defaultHTTPDate {hdYear = 1994, hdMonth = 11, hdDay = 15, hdHour = 8, hdMinute = 12, hdSecond = 31, hdWkday = 2}+-- "Tue, 15 Nov 1994 08:12:31 GMT"+ formatHTTPDate :: HTTPDate -> ByteString formatHTTPDate hd =     unsafeCreate 29 $ \ptr -> do
Network/HTTP/Date/Parser.hs view
@@ -11,13 +11,16 @@  ---------------------------------------------------------------- -{-|-  Parsing HTTP Date. Currently only RFC1123 style is supported.--}+-- |+-- Parsing HTTP Date. Currently only RFC1123 style is supported.+--+-- >>> parseHTTPDate "Tue, 15 Nov 1994 08:12:31 GMT"+-- Just (HTTPDate {hdYear = 1994, hdMonth = 11, hdDay = 15, hdHour = 8, hdMinute = 12, hdSecond = 31, hdWkday = 2})+ parseHTTPDate :: ByteString -> Maybe HTTPDate-parseHTTPDate bs = case feed (parse rfc1123Date bs) "" of-    Done _ ut -> Just ut-    _         -> Nothing+parseHTTPDate bs = case parseOnly rfc1123Date bs of+    Right ut -> Just ut+    _        -> Nothing  rfc1123Date :: Parser HTTPDate rfc1123Date = do
http-date.cabal view
@@ -1,5 +1,5 @@ Name:                   http-date-Version:                0.0.1+Version:                0.0.2 Author:                 Kazu Yamamoto <kazu@iij.ad.jp> Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp> License:                BSD3@@ -7,9 +7,10 @@ Synopsis:               HTTP Date parser/formatter Description:            Fast parser and formatter for HTTP Date Category:               Network, Web-Cabal-Version:          >= 1.6+Cabal-Version:          >= 1.8 Build-Type:             Simple-library++Library   if impl(ghc >= 6.12)     GHC-Options:        -Wall -fno-warn-unused-do-bind   else@@ -19,8 +20,26 @@                         Network.HTTP.Date.Formatter                         Network.HTTP.Date.Types                         Network.HTTP.Date.Parser-  Build-Depends:        base >= 4 && < 5,-                        bytestring, array, attoparsec+  Build-Depends:        base >= 4 && < 5+                      , array+                      , attoparsec+                      , bytestring++Test-Suite test+  Type:                 exitcode-stdio-1.0+  HS-Source-Dirs:       test+  Main-Is:              Test.hs+  Other-Modules:        Model+  Build-Depends:        base >= 4 && < 5+                      , bytestring+                      , http-date+                      , old-locale+                      , time+                      , HUnit+                      , test-framework-doctest+                      , test-framework-hunit+                      , test-framework-th-prime+ Source-Repository head   Type:                 git-  Location:             git://github.com/kazu-yamamoto/http-date+  Location:             git clone git://github.com/kazu-yamamoto/http-date
+ test/Model.hs view
@@ -0,0 +1,14 @@+module Model where++import Data.ByteString (ByteString)+import qualified Data.ByteString.Char8 as BS8+import Data.Time+import Data.Time.Clock.POSIX+import System.Locale+import System.Posix.Types++epochTimeToUtcTime :: EpochTime -> UTCTime+epochTimeToUtcTime = posixSecondsToUTCTime . realToFrac++utcToDate :: UTCTime -> ByteString+utcToDate = BS8.pack . formatTime defaultTimeLocale "%a, %d %b %Y %H:%M:%S GMT"
+ test/Test.hs view
@@ -0,0 +1,38 @@+{-# LANGUAGE TemplateHaskell #-}++module Main where++import Control.Monad+import Model+import Network.HTTP.Date+import Test.Framework.Providers.DocTest+import Test.Framework.Providers.HUnit+import Test.Framework.TH.Prime+import Test.HUnit++main :: IO ()+main = $(defaultMainGenerator)++----------------------------------------------------------------++doc_test :: DocTests+doc_test = docTest ["Network/HTTP/Date"] ["-XOverloadedStrings"]++----------------------------------------------------------------++case_formatHTTPDate :: Assertion+case_formatHTTPDate = do+    forM_ [0,100000..10000000000] $ \epochtime -> do+        let m = model epochtime+            o = ours epochtime+        o @?= m+  where+    model = utcToDate . epochTimeToUtcTime+    ours  = formatHTTPDate . epochTimeToHTTPDate++case_parseHTTPDate :: Assertion+case_parseHTTPDate = do+    forM_ [0,100000..10000000000] $ \epochtime -> do+        let m = epochTimeToHTTPDate epochtime+            Just o = parseHTTPDate $ formatHTTPDate m+        o @?= m