From f4af4f7ca06dfa51ed1958865f08e738e058dc34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Mon, 27 Jul 2020 17:15:59 +0200 Subject: [PATCH] release v0.4.4 --- CHANGELOG.md | 5 +- package.yaml | 2 +- src/Parsec.hs | 4 +- src/Query.hs | 118 ++++++------ src/Task.hs | 4 +- test/ParsecSpec.hs | 448 +++++++++++++++++++++++++-------------------- test/TaskSpec.hs | 59 +++--- 7 files changed, 343 insertions(+), 297 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec57a64..66f51e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.4.4] - 2020-07-27 + ### Fixed - Bad build state for update cmd [#27] @@ -174,7 +176,8 @@ First release :tada: - Linux binaries -[unreleased]: https://github.com/soywod/unfog.cli/compare/v0.4.3...HEAD +[unreleased]: https://github.com/soywod/unfog.cli/compare/v0.4.4...HEAD +[0.4.4]: https://github.com/soywod/unfog.cli/compare/v0.4.3...v0.4.4 [0.4.3]: https://github.com/soywod/unfog.cli/compare/v0.4.2...v0.4.3 [0.4.2]: https://github.com/soywod/unfog.cli/compare/v0.4.1...v0.4.2 [0.4.1]: https://github.com/soywod/unfog.cli/compare/v0.4.0...v0.4.1 diff --git a/package.yaml b/package.yaml index fc14d55..1ed829f 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: unfog -version: 0.4.3 +version: 0.4.4 github: "soywod/unfog.cli" license: BSD3 author: "Clément DOUIN" diff --git a/src/Parsec.hs b/src/Parsec.hs index 9af6468..4d6991e 100644 --- a/src/Parsec.hs +++ b/src/Parsec.hs @@ -52,8 +52,8 @@ data Arg = Arg { _type :: ArgType emptyArgTree :: Arg emptyArgTree = Arg { _ids = [] - , _type = Cmd - , _cmd = "" + , _type = Qry + , _cmd = "list" , _desc = "" , _tags = [] , _due = Nothing diff --git a/src/Query.hs b/src/Query.hs index 405757c..88f36d7 100644 --- a/src/Query.hs +++ b/src/Query.hs @@ -1,21 +1,20 @@ module Query where -import qualified Data.ByteString.Lazy.Char8 as BL -import Control.Exception -import Data.Aeson hiding ( Error ) -import Data.Fixed -import Data.List -import Data.Maybe -import Data.Time -import System.Process ( system ) -import Text.Read - -import Event -import Response -import State -import Store -import Task +import Control.Exception +import Data.Aeson hiding (Error) +import qualified Data.ByteString.Lazy.Char8 as BL +import Data.Fixed +import Data.List +import Data.Maybe +import Data.Time +import Event import qualified Parsec +import Response +import State +import Store +import System.Process (system) +import Task +import Text.Read data Query = List Parsec.Arg @@ -31,67 +30,61 @@ data Query handle :: Parsec.Arg -> IO () handle args = do evts <- readEvents - now <- getCurrentTime + now <- getCurrentTime let state = applyEvents now evts - let qry = getQuery args + let qry = getQuery args execute args state qry getQuery :: Parsec.Arg -> Query getQuery args = case Parsec._cmd args of "list" -> List args "info" -> case Parsec._ids args of - [] -> Error "show" "invalid arguments" + [] -> Error "show" "invalid arguments" id : _ -> Info args "worktime" -> Wtime args - "status" -> Status - "upgrade" -> Upgrade - "version" -> Version - "help" -> Help + "status" -> Status + "upgrade" -> Upgrade + "version" -> Version + "help" -> Help execute :: Parsec.Arg -> State -> Query -> IO () execute args state query = do let rtype = if Parsec._json (Parsec._opts args) then JSON else Text - let more = Parsec._more (Parsec._opts args) + let more = Parsec._more (Parsec._opts args) case query of List args -> listTasks args state query rtype - Info args -> do now <- getCurrentTime - let ctx = _ctx state - let id = head $ Parsec._ids args - let fByTags = filterByTags $ _ctx state - let fByDone = filterByDone $ "done" `elem` ctx + let ctx = _ctx state + let id = head $ Parsec._ids args + let fByTags = filterByTags $ _ctx state + let fByDone = filterByDone $ "done" `elem` ctx let fByNumber = findById id let maybeTask = fByNumber . fByTags . fByDone $ _tasks state case maybeTask of - Nothing -> printErr rtype $ "show: task [" ++ show id ++ "] not found" - Just task -> printTask rtype task { _wtime = getTotalWtime now task } - + Nothing -> printErr rtype $ "show: task [" ++ show id ++ "] not found" + Just task -> printTask rtype task {_wtime = getTotalWtime now task} Wtime args -> do now <- getCurrentTime - let tags = Parsec._tags args `union` _ctx state - let min = Parsec.parseMinDate now args - let max = Parsec.parseMaxDate now args - let refs = map _ref $ filterByTags tags $ _tasks state + let tags = Parsec._tags args `union` _ctx state + let min = Parsec.parseMinDate now args + let max = Parsec.parseMaxDate now args + let refs = map _ref $ filterByTags tags $ _tasks state let tasks = filterByRefs refs $ _tasks state let wtime = getWtimePerDay now min max tasks let ctx = if null tags then "global" else "for [" ++ unwords tags ++ "]" printWtime rtype more ("unfog: wtime " ++ ctx) wtime - Status -> do now <- getCurrentTime case filter ((> 0) . _active) $ _tasks state of - [] -> printEmptyStatus rtype + [] -> printEmptyStatus rtype task : _ -> printStatus rtype task - Upgrade -> system - "curl -sSL https://raw.githubusercontent.com/soywod/unfog.cli/master/bin/install.sh | sh" + "curl -sSL https://raw.githubusercontent.com/soywod/unfog.cli/master/bin/install.sh | sh" >> return () - - Version -> printVersion rtype "0.4.3" - - Help -> do + Version -> printVersion rtype "0.4.4" + Help -> do putStrLn "Usage: unfog cmd (args)" putStrLn "" putStrLn "Create a task:" @@ -128,27 +121,26 @@ execute args state query = do putStrLn "" putStrLn "Display total worktime by context:" putStrLn "worktime|wtime (+tags) ([min:time) (]max:time) (--json)" - Error command message -> printErr rtype $ command ++ ": " ++ message listTasks :: Parsec.Arg -> State -> Query -> ResponseType -> IO () listTasks args state query rtype - | Parsec._onlyIds (Parsec._opts args) - = printTasksId rtype . map Task._id . fByTags . fByDone $ allTasks - | Parsec._onlyTags (Parsec._opts args) - = printTasksTags rtype . nub . concatMap Task._tags $ allTasks - | otherwise - = do - now <- getCurrentTime - let ctx = _ctx state - let fByTags = filterByTags ctx - let fByDone = filterByDone $ "done" `elem` ctx - let tasks = mapWithWtime now . fByTags . fByDone $ _tasks state - let ctxStr = if null ctx then "" else " [" ++ unwords ctx ++ "]" - let onlyIds = Parsec._onlyIds (Parsec._opts args) - let onlyTags = Parsec._onlyTags (Parsec._opts args) - printTasks rtype ("unfog: list" ++ ctxStr) tasks - where - allTasks = _tasks state - fByTags = filterByTags . _ctx $ state - fByDone = filterByDone . elem "done" . _ctx $ state + | Parsec._onlyIds (Parsec._opts args) = + printTasksId rtype . map Task._id . fByTags . fByDone $ allTasks + | Parsec._onlyTags (Parsec._opts args) = + printTasksTags rtype . nub . concatMap Task._tags $ allTasks + | otherwise = + do + now <- getCurrentTime + let ctx = _ctx state + let fByTags = filterByTags ctx + let fByDone = filterByDone $ "done" `elem` ctx + let tasks = mapWithWtime now . fByTags . fByDone $ _tasks state + let ctxStr = if null ctx then "" else " [" ++ unwords ctx ++ "]" + let onlyIds = Parsec._onlyIds (Parsec._opts args) + let onlyTags = Parsec._onlyTags (Parsec._opts args) + printTasks rtype ("unfog: list" ++ ctxStr) tasks + where + allTasks = _tasks state + fByTags = filterByTags . _ctx $ state + fByDone = filterByDone . elem "done" . _ctx $ state diff --git a/src/Task.hs b/src/Task.hs index e557aa6..2a7f9bb 100644 --- a/src/Task.hs +++ b/src/Task.hs @@ -177,8 +177,8 @@ wtimePerDay (WtimeTask id desc _) (start, stop) = nextWtimes where day = show currDay currDay = utctDay start - endOfDay = read $ show currDay ++ " 23:59:59.999999999" :: UTCTime - nextDay = read $ show (addDays 1 currDay) ++ " 00:00:00" :: UTCTime + endOfDay = read $ show currDay ++ " 23:59:59 UTC" :: UTCTime + nextDay = read $ show (addDays 1 currDay) ++ " 00:00:00 UTC" :: UTCTime nextWtimes = if stop < endOfDay then [(day, [WtimeTask id desc $ realToFrac $ diffUTCTime stop start])] else diff --git a/test/ParsecSpec.hs b/test/ParsecSpec.hs index c227a23..e1c553c 100644 --- a/test/ParsecSpec.hs +++ b/test/ParsecSpec.hs @@ -1,11 +1,10 @@ module ParsecSpec - ( spec + ( spec, ) where -import Test.Hspec - -import Parsec +import Parsec +import Test.Hspec spec :: Spec spec = parallel $ do @@ -20,43 +19,55 @@ spec = parallel $ do it "with desc" $ do parseArgs "add desc1 desc2 desc3" - `shouldBe` emptyArgTree { _cmd = "add", _desc = "desc1 desc2 desc3" } - parseArgs "add + :desc [desc desc{}" `shouldBe` emptyArgTree - { _cmd = "add" - , _desc = "+ :desc [desc desc{}" - } + `shouldBe` emptyArgTree {_cmd = "add", _type = Cmd, _desc = "desc1 desc2 desc3"} + parseArgs "add + :desc [desc desc{}" + `shouldBe` emptyArgTree + { _cmd = "add", + _type = Cmd, + _desc = "+ :desc [desc desc{}" + } it "with tags" $ do parseArgs "add +tag1 +tag2" - `shouldBe` emptyArgTree { _cmd = "add", _tags = ["tag1", "tag2"] } - parseArgs "add +tag1 -tag1 +tag2" `shouldBe` emptyArgTree - { _cmd = "add" - , _desc = "-tag1" - , _tags = ["tag1", "tag2"] - } + `shouldBe` emptyArgTree {_cmd = "add", _type = Cmd, _tags = ["tag1", "tag2"]} + parseArgs "add +tag1 -tag1 +tag2" + `shouldBe` emptyArgTree + { _cmd = "add", + _type = Cmd, + _desc = "-tag1", + _tags = ["tag1", "tag2"] + } it "with due" $ do - parseArgs "add :10:20 " `shouldBe` emptyArgTree - { _cmd = "add" - , _due = Just $ ArgDate Rel 10 0 0 20 0 - } - parseArgs "add ::20" `shouldBe` emptyArgTree - { _cmd = "add" - , _due = Just $ ArgDate Rel 0 0 0 20 0 - } + parseArgs "add :10:20 " + `shouldBe` emptyArgTree + { _cmd = "add", + _type = Cmd, + _due = Just $ ArgDate Rel 10 0 0 20 0 + } + parseArgs "add ::20" + `shouldBe` emptyArgTree + { _cmd = "add", + _type = Cmd, + _due = Just $ ArgDate Rel 0 0 0 20 0 + } it "with different order" $ do - let expectedTree = emptyArgTree - { _cmd = "add" - , _desc = "desc" - , _tags = ["tag"] - , _due = Just $ ArgDate Rel 0 0 0 20 0 - , _opts = ArgOpts { _json = True - , _more = False - , _onlyIds = False - , _onlyTags = False - } - } + let expectedTree = + emptyArgTree + { _cmd = "add", + _type = Cmd, + _desc = "desc", + _tags = ["tag"], + _due = Just $ ArgDate Rel 0 0 0 20 0, + _opts = + ArgOpts + { _json = True, + _more = False, + _onlyIds = False, + _onlyTags = False + } + } parseArgs "a desc +tag ::20 --json" `shouldBe` expectedTree parseArgs "a +tag desc --json ::20" `shouldBe` expectedTree parseArgs "a ::20 --json desc +tag" `shouldBe` expectedTree @@ -69,32 +80,38 @@ spec = parallel $ do it "with desc" $ do parseArgs "edit 1 desc" - `shouldBe` emptyArgTree { _cmd = "edit", _ids = [1], _desc = "desc" } + `shouldBe` emptyArgTree {_cmd = "edit", _type = Cmd, _ids = [1], _desc = "desc"} it "with tags" $ do parseArgs "edit 1 +tag" - `shouldBe` emptyArgTree { _cmd = "edit", _ids = [1], _tags = ["tag"] } - parseArgs "edit 2 +tag -tag +tag2" `shouldBe` emptyArgTree - { _cmd = "edit" - , _ids = [2] - , _tags = ["tag2"] - } + `shouldBe` emptyArgTree {_cmd = "edit", _type = Cmd, _ids = [1], _tags = ["tag"]} + parseArgs "edit 2 +tag -tag +tag2" + `shouldBe` emptyArgTree + { _cmd = "edit", + _type = Cmd, + _ids = [2], + _tags = ["tag2"] + } it "with due" $ do - parseArgs "edit 2 :10:20 " `shouldBe` emptyArgTree - { _cmd = "edit" - , _ids = [2] - , _due = Just $ ArgDate Rel 10 0 0 20 0 - } + parseArgs "edit 2 :10:20 " + `shouldBe` emptyArgTree + { _cmd = "edit", + _type = Cmd, + _ids = [2], + _due = Just $ ArgDate Rel 10 0 0 20 0 + } it "with opt" $ do - parseArgs "e 1 desc +tag --json" `shouldBe` emptyArgTree - { _cmd = "edit" - , _desc = "desc" - , _tags = ["tag"] - , _ids = [1] - , _opts = ArgOpts True False False False - } + parseArgs "e 1 desc +tag --json" + `shouldBe` emptyArgTree + { _cmd = "edit", + _type = Cmd, + _desc = "desc", + _tags = ["tag"], + _ids = [1], + _opts = ArgOpts True False False False + } describe "set expr" $ do it "invalid args" $ do @@ -105,33 +122,39 @@ spec = parallel $ do it "with desc" $ do parseArgs "set 1 desc" - `shouldBe` emptyArgTree { _cmd = "set", _ids = [1], _desc = "desc" } + `shouldBe` emptyArgTree {_cmd = "set", _type = Cmd, _ids = [1], _desc = "desc"} it "with tags" $ do parseArgs "set 1 +tag" - `shouldBe` emptyArgTree { _cmd = "set", _ids = [1], _tags = ["tag"] } - parseArgs "s 2 +tag -tag +tag2" `shouldBe` emptyArgTree - { _cmd = "set" - , _ids = [2] - , _desc = "-tag" - , _tags = ["tag", "tag2"] - } + `shouldBe` emptyArgTree {_cmd = "set", _type = Cmd, _ids = [1], _tags = ["tag"]} + parseArgs "s 2 +tag -tag +tag2" + `shouldBe` emptyArgTree + { _cmd = "set", + _type = Cmd, + _ids = [2], + _desc = "-tag", + _tags = ["tag", "tag2"] + } it "with due" $ do - parseArgs "set 2 :10:20 " `shouldBe` emptyArgTree - { _cmd = "set" - , _ids = [2] - , _due = Just $ ArgDate Rel 10 0 0 20 0 - } + parseArgs "set 2 :10:20 " + `shouldBe` emptyArgTree + { _cmd = "set", + _type = Cmd, + _ids = [2], + _due = Just $ ArgDate Rel 10 0 0 20 0 + } it "with opt" $ do - parseArgs "set 1 desc +tag --json" `shouldBe` emptyArgTree - { _cmd = "set" - , _desc = "desc" - , _tags = ["tag"] - , _ids = [1] - , _opts = ArgOpts True False False False - } + parseArgs "set 1 desc +tag --json" + `shouldBe` emptyArgTree + { _cmd = "set", + _type = Cmd, + _desc = "desc", + _tags = ["tag"], + _ids = [1], + _opts = ArgOpts True False False False + } describe "start expr" $ do it "invalid args" $ do @@ -139,14 +162,16 @@ spec = parallel $ do parseArgs "start bad-id" `shouldBe` emptyArgTree it "with id" $ do - parseArgs "start 1" `shouldBe` emptyArgTree { _cmd = "start", _ids = [1] } + parseArgs "start 1" `shouldBe` emptyArgTree {_cmd = "start", _type = Cmd, _ids = [1]} parseArgs "start 1 2" - `shouldBe` emptyArgTree { _cmd = "start", _ids = [1, 2] } - parseArgs "+ 1 --json" `shouldBe` emptyArgTree - { _cmd = "start" - , _ids = [1] - , _opts = ArgOpts True False False False - } + `shouldBe` emptyArgTree {_cmd = "start", _type = Cmd, _ids = [1, 2]} + parseArgs "+ 1 --json" + `shouldBe` emptyArgTree + { _cmd = "start", + _type = Cmd, + _ids = [1], + _opts = ArgOpts True False False False + } describe "stop expr" $ do it "invalid args" $ do @@ -154,12 +179,14 @@ spec = parallel $ do parseArgs "stop bad-id" `shouldBe` emptyArgTree it "with id" $ do - parseArgs "stop 1" `shouldBe` emptyArgTree { _cmd = "stop", _ids = [1] } - parseArgs "- 1 --json" `shouldBe` emptyArgTree - { _cmd = "stop" - , _ids = [1] - , _opts = ArgOpts True False False False - } + parseArgs "stop 1" `shouldBe` emptyArgTree {_cmd = "stop", _type = Cmd, _ids = [1]} + parseArgs "- 1 --json" + `shouldBe` emptyArgTree + { _cmd = "stop", + _type = Cmd, + _ids = [1], + _opts = ArgOpts True False False False + } describe "toggle expr" $ do it "invalid args" $ do @@ -168,12 +195,14 @@ spec = parallel $ do it "with id" $ do parseArgs "toggle 1" - `shouldBe` emptyArgTree { _cmd = "toggle", _ids = [1] } - parseArgs "t 1 --json" `shouldBe` emptyArgTree - { _cmd = "toggle" - , _ids = [1] - , _opts = ArgOpts True False False False - } + `shouldBe` emptyArgTree {_cmd = "toggle", _type = Cmd, _ids = [1]} + parseArgs "t 1 --json" + `shouldBe` emptyArgTree + { _cmd = "toggle", + _type = Cmd, + _ids = [1], + _opts = ArgOpts True False False False + } describe "done expr" $ do it "invalid args" $ do @@ -181,12 +210,14 @@ spec = parallel $ do parseArgs "done bad-id" `shouldBe` emptyArgTree it "with id" $ do - parseArgs "done 1" `shouldBe` emptyArgTree { _cmd = "done", _ids = [1] } - parseArgs "d 1 --json" `shouldBe` emptyArgTree - { _cmd = "done" - , _ids = [1] - , _opts = ArgOpts True False False False - } + parseArgs "done 1" `shouldBe` emptyArgTree {_cmd = "done", _type = Cmd, _ids = [1]} + parseArgs "d 1 --json" + `shouldBe` emptyArgTree + { _cmd = "done", + _type = Cmd, + _ids = [1], + _opts = ArgOpts True False False False + } describe "undone expr" $ do it "invalid args" $ do @@ -195,12 +226,14 @@ spec = parallel $ do it "with id" $ do parseArgs "undone 1" - `shouldBe` emptyArgTree { _cmd = "undone", _ids = [1] } - parseArgs "u 1 --json" `shouldBe` emptyArgTree - { _cmd = "undone" - , _ids = [1] - , _opts = ArgOpts True False False False - } + `shouldBe` emptyArgTree {_cmd = "undone", _type = Cmd, _ids = [1]} + parseArgs "u 1 --json" + `shouldBe` emptyArgTree + { _cmd = "undone", + _type = Cmd, + _ids = [1], + _opts = ArgOpts True False False False + } describe "delete expr" $ do it "invalid args" $ do @@ -209,12 +242,14 @@ spec = parallel $ do it "with id" $ do parseArgs "delete 1" - `shouldBe` emptyArgTree { _cmd = "delete", _ids = [1] } - parseArgs "D 1 --json" `shouldBe` emptyArgTree - { _cmd = "delete" - , _ids = [1] - , _opts = ArgOpts True False False False - } + `shouldBe` emptyArgTree {_cmd = "delete", _type = Cmd, _ids = [1]} + parseArgs "D 1 --json" + `shouldBe` emptyArgTree + { _cmd = "delete", + _type = Cmd, + _ids = [1], + _opts = ArgOpts True False False False + } describe "remove expr" $ do it "invalid args" $ do @@ -223,38 +258,45 @@ spec = parallel $ do it "with id" $ do parseArgs "remove 1" - `shouldBe` emptyArgTree { _cmd = "remove", _ids = [1] } - parseArgs "r 1 --json" `shouldBe` emptyArgTree - { _cmd = "remove" - , _ids = [1] - , _opts = ArgOpts True False False False - } + `shouldBe` emptyArgTree {_cmd = "remove", _type = Cmd, _ids = [1]} + parseArgs "r 1 --json" + `shouldBe` emptyArgTree + { _cmd = "remove", + _type = Cmd, + _ids = [1], + _opts = ArgOpts True False False False + } describe "context expr" $ do it "clear context" $ do - parseArgs "context" `shouldBe` emptyArgTree { _cmd = "context" } + parseArgs "context" `shouldBe` emptyArgTree {_cmd = "context", _type = Cmd} it "with tags" $ do - parseArgs "context +tag1 +tag2 tag3" `shouldBe` emptyArgTree - { _cmd = "context" - , _tags = ["tag1", "tag2", "tag3"] - } + parseArgs "context +tag1 +tag2 tag3" + `shouldBe` emptyArgTree + { _cmd = "context", + _type = Cmd, + _tags = ["tag1", "tag2", "tag3"] + } it "with opt" $ do - parseArgs "c +tag1 tag2 --json" `shouldBe` emptyArgTree - { _cmd = "context" - , _tags = ["tag1", "tag2"] - , _opts = ArgOpts True False False False - } + parseArgs "c +tag1 tag2 --json" + `shouldBe` emptyArgTree + { _cmd = "context", + _type = Cmd, + _tags = ["tag1", "tag2"], + _opts = ArgOpts True False False False + } describe "list expr" $ do it "with opt" $ do - parseArgs "list " `shouldBe` emptyArgTree { _type = Qry, _cmd = "list" } - parseArgs "l --json" `shouldBe` emptyArgTree - { _type = Qry - , _cmd = "list" - , _opts = ArgOpts True False False False - } + parseArgs "list " `shouldBe` emptyArgTree {_type = Qry, _cmd = "list"} + parseArgs "l --json" + `shouldBe` emptyArgTree + { _type = Qry, + _cmd = "list", + _opts = ArgOpts True False False False + } describe "info expr" $ do it "invalid args" $ do @@ -263,94 +305,104 @@ spec = parallel $ do it "with id" $ do parseArgs "info 1" - `shouldBe` emptyArgTree { _type = Qry, _cmd = "info", _ids = [1] } - parseArgs "i 1 --json" `shouldBe` emptyArgTree - { _type = Qry - , _cmd = "info" - , _ids = [1] - , _opts = ArgOpts True False False False - } + `shouldBe` emptyArgTree {_type = Qry, _cmd = "info", _ids = [1]} + parseArgs "i 1 --json" + `shouldBe` emptyArgTree + { _type = Qry, + _cmd = "info", + _ids = [1], + _opts = ArgOpts True False False False + } describe "worktime expr" $ do it "global" $ do parseArgs "worktime" - `shouldBe` emptyArgTree { _type = Qry, _cmd = "worktime" } + `shouldBe` emptyArgTree {_type = Qry, _cmd = "worktime"} it "with tags" $ do - parseArgs "worktime tag +tag2" `shouldBe` emptyArgTree - { _type = Qry - , _cmd = "worktime" - , _tags = ["tag", "tag2"] - } + parseArgs "worktime tag +tag2" + `shouldBe` emptyArgTree + { _type = Qry, + _cmd = "worktime", + _tags = ["tag", "tag2"] + } it "with opts" $ do - parseArgs "worktime +tag tag2 --json" `shouldBe` emptyArgTree - { _type = Qry - , _cmd = "worktime" - , _tags = ["tag", "tag2"] - , _opts = ArgOpts True False False False - } + parseArgs "worktime +tag tag2 --json" + `shouldBe` emptyArgTree + { _type = Qry, + _cmd = "worktime", + _tags = ["tag", "tag2"], + _opts = ArgOpts True False False False + } it "with min date" $ do - parseArgs "w [10 tag" `shouldBe` emptyArgTree - { _type = Qry - , _cmd = "worktime" - , _tags = ["tag"] - , _minDate = Just $ ArgDate Rel 10 0 0 0 0 - } + parseArgs "w [10 tag" + `shouldBe` emptyArgTree + { _type = Qry, + _cmd = "worktime", + _tags = ["tag"], + _minDate = Just $ ArgDate Rel 10 0 0 0 0 + } it "with min time" $ do - parseArgs "w tag [:20" `shouldBe` emptyArgTree - { _type = Qry - , _cmd = "worktime" - , _tags = ["tag"] - , _minDate = Just $ ArgDate Rel 0 0 0 20 0 - } + parseArgs "w tag [:20" + `shouldBe` emptyArgTree + { _type = Qry, + _cmd = "worktime", + _tags = ["tag"], + _minDate = Just $ ArgDate Rel 0 0 0 20 0 + } it "with min datetime" $ do - parseArgs "w [10:20 tag" `shouldBe` emptyArgTree - { _type = Qry - , _cmd = "worktime" - , _tags = ["tag"] - , _minDate = Just $ ArgDate Rel 10 0 0 20 0 - } + parseArgs "w [10:20 tag" + `shouldBe` emptyArgTree + { _type = Qry, + _cmd = "worktime", + _tags = ["tag"], + _minDate = Just $ ArgDate Rel 10 0 0 20 0 + } it "with max date" $ do - parseArgs "w tag ]10" `shouldBe` emptyArgTree - { _type = Qry - , _cmd = "worktime" - , _tags = ["tag"] - , _maxDate = Just $ ArgDate Rel 10 0 0 0 0 - } + parseArgs "w tag ]10" + `shouldBe` emptyArgTree + { _type = Qry, + _cmd = "worktime", + _tags = ["tag"], + _maxDate = Just $ ArgDate Rel 10 0 0 0 0 + } it "with max time" $ do - parseArgs "w ]:20 tag" `shouldBe` emptyArgTree - { _type = Qry - , _cmd = "worktime" - , _tags = ["tag"] - , _maxDate = Just $ ArgDate Rel 0 0 0 20 0 - } + parseArgs "w ]:20 tag" + `shouldBe` emptyArgTree + { _type = Qry, + _cmd = "worktime", + _tags = ["tag"], + _maxDate = Just $ ArgDate Rel 0 0 0 20 0 + } it "with max datetime" $ do - parseArgs "w tag ]10:20" `shouldBe` emptyArgTree - { _type = Qry - , _cmd = "worktime" - , _tags = ["tag"] - , _maxDate = Just $ ArgDate Rel 10 0 0 20 0 - } + parseArgs "w tag ]10:20" + `shouldBe` emptyArgTree + { _type = Qry, + _cmd = "worktime", + _tags = ["tag"], + _maxDate = Just $ ArgDate Rel 10 0 0 20 0 + } it "with min and max datetimes" $ do - parseArgs "w [10:20 ]14 tag" `shouldBe` emptyArgTree - { _type = Qry - , _cmd = "worktime" - , _tags = ["tag"] - , _minDate = Just $ ArgDate Rel 10 0 0 20 0 - , _maxDate = Just $ ArgDate Rel 14 0 0 0 0 - } + parseArgs "w [10:20 ]14 tag" + `shouldBe` emptyArgTree + { _type = Qry, + _cmd = "worktime", + _tags = ["tag"], + _minDate = Just $ ArgDate Rel 10 0 0 20 0, + _maxDate = Just $ ArgDate Rel 14 0 0 0 0 + } describe "help expr" $ do it "with aliases" $ do - parseArgs "help" `shouldBe` emptyArgTree { _type = Qry, _cmd = "help" } - parseArgs "h" `shouldBe` emptyArgTree { _type = Qry, _cmd = "help" } - parseArgs "--help" `shouldBe` emptyArgTree { _type = Qry, _cmd = "help" } - parseArgs "-h" `shouldBe` emptyArgTree { _type = Qry, _cmd = "help" } + parseArgs "help" `shouldBe` emptyArgTree {_type = Qry, _cmd = "help"} + parseArgs "h" `shouldBe` emptyArgTree {_type = Qry, _cmd = "help"} + parseArgs "--help" `shouldBe` emptyArgTree {_type = Qry, _cmd = "help"} + parseArgs "-h" `shouldBe` emptyArgTree {_type = Qry, _cmd = "help"} diff --git a/test/TaskSpec.hs b/test/TaskSpec.hs index a2c10ae..032fbc2 100644 --- a/test/TaskSpec.hs +++ b/test/TaskSpec.hs @@ -1,105 +1,104 @@ module TaskSpec - ( spec + ( spec, ) where -import Data.Time -import Test.Hspec - -import Task +import Data.Time +import Task +import Test.Hspec spec :: Spec spec = parallel $ do - let emptyActiveTask = emptyTask { _id = 1, _desc = "desc", _active = 1 } - let emptyTask' = emptyActiveTask { _active = 0 } + let emptyActiveTask = emptyTask {_id = 1, _desc = "desc", _active = 1} + let emptyTask' = emptyActiveTask {_active = 0} describe "getWtimePerDay" $ do - let d10 = read "2019-12-22 10:00:00" :: UTCTime - let d12 = read "2019-12-22 12:00:00" :: UTCTime - let d14 = read "2019-12-22 14:00:00" :: UTCTime - let d16 = read "2019-12-22 16:00:00" :: UTCTime - let d18 = read "2019-12-22 18:00:00" :: UTCTime + let d10 = read "2019-12-22 10:00:00 UTC" :: UTCTime + let d12 = read "2019-12-22 12:00:00 UTC" :: UTCTime + let d14 = read "2019-12-22 14:00:00 UTC" :: UTCTime + let d16 = read "2019-12-22 16:00:00 UTC" :: UTCTime + let d18 = read "2019-12-22 18:00:00 UTC" :: UTCTime it "start" $ do - let tasks = [emptyActiveTask { _starts = [d10, d16], _stops = [d12] }] + let tasks = [emptyActiveTask {_starts = [d10, d16], _stops = [d12]}] getWtimePerDay d18 Nothing Nothing tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 4]))] it "start stop" $ do - let tasks = [emptyTask' { _starts = [d10, d14], _stops = [d12, d16] }] + let tasks = [emptyTask' {_starts = [d10, d14], _stops = [d12, d16]}] getWtimePerDay d18 Nothing Nothing tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 4]))] it "[ start" $ do - let tasks = [emptyActiveTask { _starts = [d16] }] + let tasks = [emptyActiveTask {_starts = [d16]}] getWtimePerDay d18 (Just d10) Nothing tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 2]))] it "start [" $ do - let tasks = [emptyActiveTask { _starts = [d10] }] + let tasks = [emptyActiveTask {_starts = [d10]}] getWtimePerDay d18 (Just d14) Nothing tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 4]))] it "[ start stop" $ do - let tasks = [emptyActiveTask { _starts = [d14], _stops = [d16] }] + let tasks = [emptyActiveTask {_starts = [d14], _stops = [d16]}] getWtimePerDay d18 (Just d10) Nothing tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 2]))] it "start [ stop" $ do - let tasks = [emptyActiveTask { _starts = [d12], _stops = [d16] }] + let tasks = [emptyActiveTask {_starts = [d12], _stops = [d16]}] getWtimePerDay d18 (Just d14) Nothing tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 2]))] it "start stop [" $ do - let tasks = [emptyActiveTask { _starts = [d14], _stops = [d16] }] + let tasks = [emptyActiveTask {_starts = [d14], _stops = [d16]}] getWtimePerDay d18 (Just d18) Nothing tasks `shouldBe` [] it "] start" $ do - let tasks = [emptyActiveTask { _starts = [d14] }] + let tasks = [emptyActiveTask {_starts = [d14]}] getWtimePerDay d18 Nothing (Just d10) tasks `shouldBe` [] it "start ]" $ do - let tasks = [emptyActiveTask { _starts = [d10] }] + let tasks = [emptyActiveTask {_starts = [d10]}] getWtimePerDay d18 Nothing (Just d12) tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 2]))] it "] start stop" $ do - let tasks = [emptyActiveTask { _starts = [d14], _stops = [d16] }] + let tasks = [emptyActiveTask {_starts = [d14], _stops = [d16]}] getWtimePerDay d18 Nothing (Just d10) tasks `shouldBe` [] it "start ] stop" $ do - let tasks = [emptyActiveTask { _starts = [d12], _stops = [d16] }] + let tasks = [emptyActiveTask {_starts = [d12], _stops = [d16]}] getWtimePerDay d18 Nothing (Just d14) tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 2]))] it "start stop ]" $ do - let tasks = [emptyActiveTask { _starts = [d14], _stops = [d16] }] + let tasks = [emptyActiveTask {_starts = [d14], _stops = [d16]}] getWtimePerDay d18 Nothing (Just d18) tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 2]))] it "[ start stop ]" $ do - let tasks = [emptyActiveTask { _starts = [d12], _stops = [d16] }] + let tasks = [emptyActiveTask {_starts = [d12], _stops = [d16]}] getWtimePerDay d18 (Just d10) (Just d18) tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 4]))] it "start [ stop ]" $ do - let tasks = [emptyActiveTask { _starts = [d12], _stops = [d16] }] + let tasks = [emptyActiveTask {_starts = [d12], _stops = [d16]}] getWtimePerDay d18 (Just d14) (Just d18) tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 2]))] it "[ start ] stop" $ do - let tasks = [emptyActiveTask { _starts = [d12], _stops = [d18] }] + let tasks = [emptyActiveTask {_starts = [d12], _stops = [d18]}] getWtimePerDay d18 (Just d10) (Just d16) tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 4]))] it "start stop []" $ do - let tasks = [emptyActiveTask { _starts = [d10], _stops = [d14] }] + let tasks = [emptyActiveTask {_starts = [d10], _stops = [d14]}] getWtimePerDay d18 (Just d16) (Just d18) tasks `shouldBe` [] it "[] start stop" $ do - let tasks = [emptyActiveTask { _starts = [d16], _stops = [d18] }] + let tasks = [emptyActiveTask {_starts = [d16], _stops = [d18]}] getWtimePerDay d18 (Just d10) (Just d12) tasks `shouldBe` [] it "start [] stop" $ do - let tasks = [emptyActiveTask { _starts = [d10], _stops = [d18] }] + let tasks = [emptyActiveTask {_starts = [d10], _stops = [d18]}] getWtimePerDay d18 (Just d14) (Just d16) tasks `shouldBe` [("2019-12-22", ([WtimeTask 1 "desc" $ 60 * 60 * 2]))]