mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 03:20:21 -07:00
Fix date parsing issue for org mode plugin
This patch fixes the date parsing issue currently when an entry like `todo +d 22 01 2022` is used. I have added tests too which demonstrate the current issue so that we can prevent future regression.
This commit is contained in:
parent
769e5f9c94
commit
91f1a0de1e
@ -401,6 +401,14 @@ pDate = skipSpaces *> choice
|
|||||||
, pPrefix "su" "nday" Sunday
|
, pPrefix "su" "nday" Sunday
|
||||||
]
|
]
|
||||||
|
|
||||||
|
numWithoutColon :: Parser Int
|
||||||
|
numWithoutColon = do
|
||||||
|
str <- num
|
||||||
|
c <- get
|
||||||
|
if c == ':'
|
||||||
|
then pfail
|
||||||
|
else pure str
|
||||||
|
|
||||||
pDate' :: Parser (Int, Maybe Int, Maybe Integer)
|
pDate' :: Parser (Int, Maybe Int, Maybe Integer)
|
||||||
pDate' =
|
pDate' =
|
||||||
(,,) <$> num
|
(,,) <$> num
|
||||||
@ -411,6 +419,7 @@ pDate = skipSpaces *> choice
|
|||||||
, pPrefix "jul" "y" 7 , pPrefix "au" "gust" 8
|
, pPrefix "jul" "y" 7 , pPrefix "au" "gust" 8
|
||||||
, pPrefix "s" "eptember" 9 , pPrefix "o" "ctober" 10
|
, pPrefix "s" "eptember" 9 , pPrefix "o" "ctober" 10
|
||||||
, pPrefix "n" "ovember" 11, pPrefix "d" "ecember" 12
|
, pPrefix "n" "ovember" 11, pPrefix "d" "ecember" 12
|
||||||
|
, numWithoutColon
|
||||||
])
|
])
|
||||||
<*> optional (skipSpaces *> num >>= \i -> guard (i >= 25) $> i)
|
<*> optional (skipSpaces *> num >>= \i -> guard (i >= 25) $> i)
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ module XMonad.Util.Parser (
|
|||||||
endBy1,
|
endBy1,
|
||||||
munch,
|
munch,
|
||||||
munch1,
|
munch1,
|
||||||
|
pfail
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import XMonad.Prelude
|
import XMonad.Prelude
|
||||||
@ -136,6 +137,10 @@ instance Alternative Parser where
|
|||||||
runParser :: Parser a -> String -> Maybe a
|
runParser :: Parser a -> String -> Maybe a
|
||||||
runParser (Parser p) = fmap fst . listToMaybe . ReadP.readP_to_S p
|
runParser (Parser p) = fmap fst . listToMaybe . ReadP.readP_to_S p
|
||||||
|
|
||||||
|
-- | Always fails
|
||||||
|
pfail :: Parser a
|
||||||
|
pfail = Parser $ ReadP.pfail
|
||||||
|
|
||||||
-- | Consume and return the next character. Fails if there is no input
|
-- | Consume and return the next character. Fails if there is no input
|
||||||
-- left.
|
-- left.
|
||||||
get :: Parser Char
|
get :: Parser Char
|
||||||
|
@ -22,6 +22,29 @@ spec = do
|
|||||||
prop "prop_encodeLinearity" prop_encodeLinearity
|
prop "prop_encodeLinearity" prop_encodeLinearity
|
||||||
prop "prop_decodeLinearity" prop_decodeLinearity
|
prop "prop_decodeLinearity" prop_decodeLinearity
|
||||||
|
|
||||||
|
describe "pInput" $ do
|
||||||
|
it "works with todo +d 22 january 2021" $ do
|
||||||
|
pInput "todo +d 22 ja 2021"
|
||||||
|
`shouldBe` Just
|
||||||
|
( Deadline
|
||||||
|
"todo"
|
||||||
|
(Time {date = Date (22, Just 1, Just 2021), tod = Nothing})
|
||||||
|
)
|
||||||
|
it "works with todo +d 22 01 2022" $ do
|
||||||
|
pInput "todo +d 22 01 2022"
|
||||||
|
`shouldBe` Just
|
||||||
|
( Deadline
|
||||||
|
"todo"
|
||||||
|
(Time {date = Date (22, Just 1, Just 2022), tod = Nothing})
|
||||||
|
)
|
||||||
|
it "works with todo +d 1 01:01" $ do
|
||||||
|
pInput "todo +d 1 01:01"
|
||||||
|
`shouldBe` Just
|
||||||
|
( Deadline
|
||||||
|
"todo"
|
||||||
|
(Time {date = Date (1, Nothing, Nothing), tod = Just $ TimeOfDay 1 1})
|
||||||
|
)
|
||||||
|
|
||||||
-- Checking for regressions
|
-- Checking for regressions
|
||||||
context "+d +d f" $ do
|
context "+d +d f" $ do
|
||||||
it "encode" $ prop_encodeLinearity (OrgMsg "+d +d f")
|
it "encode" $ prop_encodeLinearity (OrgMsg "+d +d f")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user