From: PHO Date: Thu, 11 Mar 2010 09:14:13 +0000 (+0900) Subject: test units X-Git-Tag: RELEASE-0.1.0.1~9 X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=6f8578a5f973cf4687dbea90c7a42c008925a2ec;p=time-w3c.git test units --- diff --git a/Data/Time/W3C/Parser/Parsec.hs b/Data/Time/W3C/Parser/Parsec.hs index f73d68c..6b960ac 100644 --- a/Data/Time/W3C/Parser/Parsec.hs +++ b/Data/Time/W3C/Parser/Parsec.hs @@ -117,7 +117,7 @@ read4 = do n1 <- digit' read2 :: (Stream s m Char, Num n) => ParsecT s u m n read2 = do n1 <- digit' n2 <- digit' - return (n1 + 10 + n2) + return (n1 * 10 + n2) digit' :: (Stream s m Char, Num n) => ParsecT s u m n digit' = liftM fromC digit diff --git a/GNUmakefile b/GNUmakefile index 86f31ee..87f5f1a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,3 +1,3 @@ -CONFIGURE_ARGS = -O +CONFIGURE_ARGS = -O -fbuild-test-suite include cabal-package.mk \ No newline at end of file diff --git a/Setup.hs b/Setup.hs index cd7dc32..60a326f 100644 --- a/Setup.hs +++ b/Setup.hs @@ -1,3 +1,9 @@ #!/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 () diff --git a/tests/ParsecParserTest.hs b/tests/ParsecParserTest.hs new file mode 100644 index 0000000..5cba80e --- /dev/null +++ b/tests/ParsecParserTest.hs @@ -0,0 +1,76 @@ +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 + ] diff --git a/tests/W3CDateTimeUnitTest.hs b/tests/W3CDateTimeUnitTest.hs new file mode 100644 index 0000000..e9104dd --- /dev/null +++ b/tests/W3CDateTimeUnitTest.hs @@ -0,0 +1,8 @@ +import Test.HUnit +import qualified ParsecParserTest + +main :: IO () +main = runTestTT (test testData) >> return () + +testData :: [Test] +testData = ParsecParserTest.testData \ No newline at end of file diff --git a/time-w3c.cabal b/time-w3c.cabal index b842172..fef0996 100644 --- a/time-w3c.cabal +++ b/time-w3c.cabal @@ -18,6 +18,14 @@ Build-type: Simple 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 @@ -39,3 +47,27 @@ Library 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