mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
lib: Using --drop in tree mode with boring parent ellision no longer considers all parents boring. Add tests to check this fact.
This commit is contained in:
parent
015492553e
commit
e089358758
@ -344,7 +344,7 @@ displayedAccounts :: ReportOpts -> Query
|
||||
-> HashMap AccountName [Account]
|
||||
-> HashMap AccountName DisplayName
|
||||
displayedAccounts ropts q valuedaccts
|
||||
| depth == 0 = HM.singleton "..." $ DisplayName "..." "..." 0
|
||||
| depth == 0 = HM.singleton "..." $ DisplayName "..." "..." 1
|
||||
| otherwise = HM.mapWithKey (\a _ -> displayedName a) displayedAccts
|
||||
where
|
||||
-- Accounts which are to be displayed
|
||||
@ -352,19 +352,18 @@ displayedAccounts ropts q valuedaccts
|
||||
where
|
||||
keep name amts = isInteresting name amts || name `HM.member` interestingParents
|
||||
|
||||
isDisplayed = (`HM.member` displayedAccts)
|
||||
|
||||
displayedName name
|
||||
| flat_ ropts = DisplayName name droppedName 0
|
||||
| otherwise = DisplayName name leaf d
|
||||
| flat_ ropts = DisplayName name droppedName 1
|
||||
| otherwise = DisplayName name leaf $ level - boringParents
|
||||
where
|
||||
leaf = accountNameFromComponents . reverse . map accountLeafName $
|
||||
droppedName : takeWhile (not . isDisplayed) parents
|
||||
d | no_elide_ ropts = accountNameLevel droppedName
|
||||
| otherwise = accountNameLevel droppedName - length boringParents
|
||||
boringParents = filter (not . isDisplayed) parents
|
||||
parents = parentAccountNames droppedName
|
||||
droppedName = accountNameDrop (drop_ ropts) name
|
||||
leaf = accountNameFromComponents . reverse . map accountLeafName $
|
||||
droppedName : takeWhile notDisplayed parents
|
||||
|
||||
level = accountNameLevel name - drop_ ropts
|
||||
parents = take (level - 1) $ parentAccountNames name
|
||||
boringParents = if no_elide_ ropts then 0 else length $ filter notDisplayed parents
|
||||
notDisplayed = not . (`HM.member` displayedAccts)
|
||||
|
||||
-- Accounts interesting for their own sake
|
||||
isInteresting name amts =
|
||||
|
@ -139,14 +139,15 @@ instance ToJSON DisplayName where
|
||||
toEncoding = toEncoding . displayFull
|
||||
|
||||
-- | Construct a flat display name, where the full name is also displayed at
|
||||
-- depth 0
|
||||
-- depth 1
|
||||
flatDisplayName :: AccountName -> DisplayName
|
||||
flatDisplayName a = DisplayName a a 0
|
||||
flatDisplayName a = DisplayName a a 1
|
||||
|
||||
-- | Construct a tree display name, where only the leaf is displayed at its
|
||||
-- given depth
|
||||
treeDisplayName :: AccountName -> DisplayName
|
||||
treeDisplayName a = DisplayName a (accountLeafName a) (accountNameLevel a)
|
||||
|
||||
-- | Get the full, canonical, name of a PeriodicReportRow tagged by a
|
||||
-- DisplayName.
|
||||
prrFullName :: PeriodicReportRow DisplayName a -> AccountName
|
||||
|
43
tests/balance/drop.test
Normal file
43
tests/balance/drop.test
Normal file
@ -0,0 +1,43 @@
|
||||
# 1. Drop works in flat mode
|
||||
<
|
||||
2018/1/1
|
||||
(b:j) 1
|
||||
|
||||
2018/1/1
|
||||
(b:j:q) 1
|
||||
|
||||
2018/1/1
|
||||
(c) 1
|
||||
|
||||
2018/1/1
|
||||
(b:i:p) 1
|
||||
|
||||
2018/1/1
|
||||
(a:k) 1
|
||||
|
||||
$ hledger -f - balance --flat --no-total --drop 1
|
||||
1 k
|
||||
1 i:p
|
||||
1 j
|
||||
1 j:q
|
||||
1 ...
|
||||
>=
|
||||
|
||||
## 2. Drop works in tree mode with no boring parent ellision
|
||||
$ hledger -f - balance --tree --no-elide --no-total --drop 1
|
||||
1 k
|
||||
1 i
|
||||
1 p
|
||||
2 j
|
||||
1 q
|
||||
1 ...
|
||||
>=
|
||||
|
||||
## 3. Drop works in tree mode with boring parent ellision
|
||||
$ hledger -f - balance --tree --no-total --drop 1
|
||||
1 k
|
||||
1 i:p
|
||||
2 j
|
||||
1 q
|
||||
1 ...
|
||||
>=
|
Loading…
Reference in New Issue
Block a user