X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-w3c.git;a=blobdiff_plain;f=tests%2FParsecParserTest.hs;fp=tests%2FParsecParserTest.hs;h=5cba80edd276e7ff0ea2b118e917484517c870ab;hp=0000000000000000000000000000000000000000;hb=6f8578a5f973cf4687dbea90c7a42c008925a2ec;hpb=3d738487d6fb1077d139fd689279a1ebd27a9fdc 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 + ]