#!/usr/bin/env runhaskell
import Distribution.Simple
-main = defaultMain
+import System.Cmd
+import System.Exit
+
+main = defaultMainWithHooks (simpleUserHooks { runTests = runTestUnit })
+ where
+ runTestUnit _ _ _ _
+ = system "./dist/build/W3CDateTimeUnitTest/W3CDateTimeUnitTest" >> return ()
--- /dev/null
+module ParsecParserTest
+ ( testData
+ )
+ where
+
+import Data.Time
+import Data.Time.W3C hiding (parse)
+import Data.Time.W3C.Parser.Parsec
+import Test.HUnit
+import Text.Parsec
+
+
+parseW3C :: String -> Either String W3CDateTime
+parseW3C src = case parse w3cDateTime "" src of
+ Left err -> Left (show err)
+ Right w3c -> Right w3c
+
+parseW3C' :: String -> Maybe W3CDateTime
+parseW3C' src = case parse w3cDateTime "" src of
+ Left _ -> Nothing
+ Right w3c -> Just w3c
+
+
+testData :: [Test]
+testData = [ parseW3C "2010"
+ ~?=
+ Right (W3CDateTime 2010 Nothing Nothing Nothing Nothing Nothing Nothing)
+
+ , parseW3C "2010-12"
+ ~?=
+ Right (W3CDateTime 2010 (Just 12) Nothing Nothing Nothing Nothing Nothing)
+
+ , parseW3C "2010-12-31"
+ ~?=
+ Right (W3CDateTime 2010 (Just 12) (Just 31) Nothing Nothing Nothing Nothing)
+
+ , parseW3C "2010-12-31T01:23Z"
+ ~?=
+ Right (W3CDateTime 2010 (Just 12) (Just 31) (Just 1) (Just 23) Nothing (Just (hoursToTimeZone 0)))
+
+ , parseW3C "2010-12-31T01:23:45+09:00"
+ ~?=
+ Right (W3CDateTime 2010 (Just 12) (Just 31) (Just 1) (Just 23) (Just 45) (Just (hoursToTimeZone 9)))
+
+ , parseW3C "2010-12-31T01:23:45.666666+09:00"
+ ~?=
+ Right (W3CDateTime 2010 (Just 12) (Just 31) (Just 1) (Just 23) (Just 45.666666) (Just (hoursToTimeZone 9)))
+
+ , parseW3C' ""
+ ~?=
+ Nothing
+
+ , parseW3C' "99-01-01"
+ ~?=
+ Nothing
+
+ , parseW3C' "2010-01-01T"
+ ~?=
+ Nothing
+
+ , parseW3C' "2010-01-01T10Z"
+ ~?=
+ Nothing
+
+ , parseW3C' "2010-01-01T11:22"
+ ~?=
+ Nothing
+
+ , parseW3C' "2010-01-01T11:22:33"
+ ~?=
+ Nothing
+
+ , parseW3C' "2010-01-01T11:22:33.Z"
+ ~?=
+ Nothing
+ ]
Cabal-version: >= 1.2.3
Extra-source-files:
+Source-Repository head
+ Type: git
+ Location: git://git.cielonegro.org/time-w3c.git
+
+Flag build-test-suite
+ Description: Build the tst suite.
+ Default: False
+
Library
Exposed-modules:
Data.Time.W3C
GHC-Options:
-Wall
+
+Executable W3CDateTimeUnitTest
+ Main-Is:
+ W3CDateTimeUnitTest.hs
+
+ if flag(build-test-suite)
+ Buildable: True
+ Build-Depends: HUnit >= 1.2 && < 2
+ else
+ Buildable: False
+
+ Hs-Source-Dirs:
+ ., tests
+
+ Other-Modules:
+ ParsecParserTest
+
+ Extensions:
+ DeriveDataTypeable
+ FlexibleContexts
+ MultiParamTypeClasses
+
+ GHC-Options:
+ -Wall