@@ -17,8 +17,9 @@ import Test.Hspec (Spec, context, describe, it, shouldBe,
17
17
import Test.QuickCheck (Arbitrary (.. ), Gen , elements , forAll ,
18
18
property , suchThat )
19
19
import Text.Megaparsec (Parsec , errorBundlePretty , runParser )
20
- import Text.Megaparsec.Time (dayParser , durationParser , hoursParser ,
21
- minutesParser , secondsParser , timeParser )
20
+ import Text.Megaparsec.Time (dateParser , dayParser , durationParser ,
21
+ hoursParser , minutesParser ,
22
+ secondsParser , timeParser )
22
23
import Text.Printf (printf )
23
24
24
25
instance Arbitrary TimeOfDay where
@@ -45,6 +46,15 @@ parseOrPrettyError p = first errorBundlePretty . runParser p "test"
45
46
46
47
spec :: Spec
47
48
spec = do
49
+ describe " date" $ do
50
+ it " time only" $
51
+ parseOrPrettyError dateParser " 11:03" `shouldBe`
52
+ Right (Nothing , TimeOfDay 11 3 0 )
53
+
54
+ it " with day" $
55
+ parseOrPrettyError dateParser " yesterday 11:03" `shouldBe`
56
+ Right (Just (Left (- 1 )), TimeOfDay 11 3 0 )
57
+
48
58
describe " day" $ do
49
59
let weekday d = d < Saturday
50
60
@@ -67,10 +77,10 @@ spec = do
67
77
68
78
context " tomorrow" $ do
69
79
it " capitalized" $
70
- parseOrPrettyError dayParser " Tomorrow " `shouldBe` Right (Left 1 )
80
+ parseOrPrettyError dayParser " Tomorrow" `shouldBe` Right (Left 1 )
71
81
72
82
it " lowercase" $
73
- parseOrPrettyError dayParser " tomorrow " `shouldBe` Right (Left 1 )
83
+ parseOrPrettyError dayParser " tomorrow" `shouldBe` Right (Left 1 )
74
84
75
85
it " future day" . forAll (abs <$> arbitrary) $ \ x ->
76
86
parseOrPrettyError dayParser (printf " +%d" x) `shouldBe` Right (Left x)
0 commit comments