]> gitweb @ CieloNegro.org - time-w3c.git/blob - tests/ParsecParserTest.hs
Bump version to 0.1.0.1
[time-w3c.git] / tests / ParsecParserTest.hs
1 module ParsecParserTest
2     ( testData
3     )
4     where
5
6 import Data.Time
7 import Data.Time.W3C hiding (parse)
8 import Data.Time.W3C.Parser.Parsec
9 import Test.HUnit
10 import Text.Parsec
11
12
13 parseW3C :: String -> Either String W3CDateTime
14 parseW3C src = case parse w3cDateTime "" src of
15                  Left  err -> Left (show err)
16                  Right w3c -> Right w3c
17
18 parseW3C' :: String -> Maybe W3CDateTime
19 parseW3C' src = case parse w3cDateTime "" src of
20                   Left  _   -> Nothing
21                   Right w3c -> Just w3c
22
23
24 testData :: [Test]
25 testData = [ parseW3C "2010"
26              ~?=
27              Right (W3CDateTime 2010 Nothing Nothing Nothing Nothing Nothing Nothing)
28
29            , parseW3C "2010-12"
30              ~?=
31              Right (W3CDateTime 2010 (Just 12) Nothing Nothing Nothing Nothing Nothing)
32
33            , parseW3C "2010-12-31"
34              ~?=
35              Right (W3CDateTime 2010 (Just 12) (Just 31) Nothing Nothing Nothing Nothing)
36
37            , parseW3C "2010-12-31T01:23Z"
38              ~?=
39              Right (W3CDateTime 2010 (Just 12) (Just 31) (Just 1) (Just 23) Nothing (Just (hoursToTimeZone 0)))
40
41            , parseW3C "2010-12-31T01:23:45+09:00"
42              ~?=
43              Right (W3CDateTime 2010 (Just 12) (Just 31) (Just 1) (Just 23) (Just 45) (Just (hoursToTimeZone 9)))
44
45            , parseW3C "2010-12-31T01:23:45.666666+09:00"
46              ~?=
47              Right (W3CDateTime 2010 (Just 12) (Just 31) (Just 1) (Just 23) (Just 45.666666) (Just (hoursToTimeZone 9)))
48
49            , parseW3C' ""
50              ~?=
51              Nothing
52
53            , parseW3C' "99-01-01"
54              ~?=
55              Nothing
56
57            , parseW3C' "2010-01-01T"
58              ~?=
59              Nothing
60
61            , parseW3C' "2010-01-01T10Z"
62              ~?=
63              Nothing
64
65            , parseW3C' "2010-01-01T11:22"
66              ~?=
67              Nothing
68
69            , parseW3C' "2010-01-01T11:22:33"
70              ~?=
71              Nothing
72
73            , parseW3C' "2010-01-01T11:22:33.Z"
74              ~?=
75              Nothing
76            ]