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 [Account] | ||||||
|                   -> HashMap AccountName DisplayName |                   -> HashMap AccountName DisplayName | ||||||
| displayedAccounts ropts q valuedaccts | displayedAccounts ropts q valuedaccts | ||||||
|     | depth == 0 = HM.singleton "..." $ DisplayName "..." "..." 0 |     | depth == 0 = HM.singleton "..." $ DisplayName "..." "..." 1 | ||||||
|     | otherwise  = HM.mapWithKey (\a _ -> displayedName a) displayedAccts |     | otherwise  = HM.mapWithKey (\a _ -> displayedName a) displayedAccts | ||||||
|   where |   where | ||||||
|     -- Accounts which are to be displayed |     -- Accounts which are to be displayed | ||||||
| @ -352,19 +352,18 @@ displayedAccounts ropts q valuedaccts | |||||||
|       where |       where | ||||||
|         keep name amts = isInteresting name amts || name `HM.member` interestingParents |         keep name amts = isInteresting name amts || name `HM.member` interestingParents | ||||||
| 
 | 
 | ||||||
|     isDisplayed = (`HM.member` displayedAccts) |  | ||||||
| 
 |  | ||||||
|     displayedName name |     displayedName name | ||||||
|         | flat_ ropts = DisplayName name droppedName 0 |         | flat_ ropts = DisplayName name droppedName 1 | ||||||
|         | otherwise   = DisplayName name leaf d |         | otherwise   = DisplayName name leaf $ level - boringParents | ||||||
|       where |       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 |         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 |     -- Accounts interesting for their own sake | ||||||
|     isInteresting name amts = |     isInteresting name amts = | ||||||
|  | |||||||
| @ -139,14 +139,15 @@ instance ToJSON DisplayName where | |||||||
|     toEncoding = toEncoding . displayFull |     toEncoding = toEncoding . displayFull | ||||||
| 
 | 
 | ||||||
| -- | Construct a flat display name, where the full name is also displayed at | -- | Construct a flat display name, where the full name is also displayed at | ||||||
| -- depth 0 | -- depth 1 | ||||||
| flatDisplayName :: AccountName -> DisplayName | 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 | -- | Construct a tree display name, where only the leaf is displayed at its | ||||||
| -- given depth | -- given depth | ||||||
| treeDisplayName :: AccountName -> DisplayName | treeDisplayName :: AccountName -> DisplayName | ||||||
| treeDisplayName a = DisplayName a (accountLeafName a) (accountNameLevel a) | treeDisplayName a = DisplayName a (accountLeafName a) (accountNameLevel a) | ||||||
|  | 
 | ||||||
| -- | Get the full, canonical, name of a PeriodicReportRow tagged by a | -- | Get the full, canonical, name of a PeriodicReportRow tagged by a | ||||||
| -- DisplayName. | -- DisplayName. | ||||||
| prrFullName :: PeriodicReportRow DisplayName a -> AccountName | 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