]> gitweb @ CieloNegro.org - time-w3c.git/commitdiff
test units
authorPHO <pho@cielonegro.org>
Thu, 11 Mar 2010 09:14:13 +0000 (18:14 +0900)
committerPHO <pho@cielonegro.org>
Thu, 11 Mar 2010 09:14:13 +0000 (18:14 +0900)
Data/Time/W3C/Parser/Parsec.hs
GNUmakefile
Setup.hs
tests/ParsecParserTest.hs [new file with mode: 0644]
tests/W3CDateTimeUnitTest.hs [new file with mode: 0644]
time-w3c.cabal

index f73d68c24a98f93ebf419b721867bf1f1b22b04e..6b960acc2d6d01bc5b1e21f66159e771e4f4b46a 100644 (file)
@@ -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'
 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
 
 digit' :: (Stream s m Char, Num n) => ParsecT s u m n
 digit' = liftM fromC digit
index 86f31eeb380de4b533c94cf58bc95e5d881c2cb9..87f5f1aa0cccc0625ba952179f0259b1e919c6d9 100644 (file)
@@ -1,3 +1,3 @@
-CONFIGURE_ARGS = -O
+CONFIGURE_ARGS = -O -fbuild-test-suite
 
 include cabal-package.mk
\ No newline at end of file
 
 include cabal-package.mk
\ No newline at end of file
index cd7dc32771c50dfce0f84edbdd953488e9dd68cd..60a326f276468501a09b8a484bb4c5cdda91b06a 100644 (file)
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,3 +1,9 @@
 #!/usr/bin/env runhaskell
 import Distribution.Simple
 #!/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 (file)
index 0000000..5cba80e
--- /dev/null
@@ -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 (file)
index 0000000..e9104dd
--- /dev/null
@@ -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
index b8421729673dd77e3369e617e845f45971a05cf1..fef0996405b63bd823aa3143e3eae5312b9bf706 100644 (file)
@@ -18,6 +18,14 @@ Build-type:          Simple
 Cabal-version:       >= 1.2.3
 Extra-source-files:
 
 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
 Library
     Exposed-modules:
         Data.Time.W3C
@@ -39,3 +47,27 @@ Library
 
     GHC-Options:
         -Wall
 
     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