make --depth activate -s like ledger's -d'<=N'
This commit is contained in:
		
							parent
							
								
									037e762b1b
								
							
						
					
					
						commit
						27c1f06055
					
				| @ -126,10 +126,10 @@ showBalanceReport opts args l = acctsstr ++ (if collapse then "" else totalstr) | |||||||
|       matchedacctnames = balancereportacctnames l sub apats t |       matchedacctnames = balancereportacctnames l sub apats t | ||||||
|       t = (if empty then id else pruneZeroBalanceLeaves) $ ledgerAccountTree maxdepth l |       t = (if empty then id else pruneZeroBalanceLeaves) $ ledgerAccountTree maxdepth l | ||||||
|       apats = fst $ parseAccountDescriptionArgs args |       apats = fst $ parseAccountDescriptionArgs args | ||||||
|       sub = SubTotal `elem` opts |       maxdepth = fromMaybe 9999 $ depthFromOpts opts | ||||||
|  |       sub = SubTotal `elem` opts || (isJust $ depthFromOpts opts) | ||||||
|       empty = Empty `elem` opts |       empty = Empty `elem` opts | ||||||
|       collapse = Collapse `elem` opts |       collapse = Collapse `elem` opts | ||||||
|       maxdepth = fromMaybe 9999 $ depthFromOpts opts |  | ||||||
|       totalstr = if isZeroMixedAmount total  |       totalstr = if isZeroMixedAmount total  | ||||||
|                  then ""  |                  then ""  | ||||||
|                  else printf "--------------------\n%20s\n" $ showMixedAmount total |                  else printf "--------------------\n%20s\n" $ showMixedAmount total | ||||||
|  | |||||||
| @ -117,7 +117,7 @@ endDateFromOpts opts = | |||||||
| 
 | 
 | ||||||
| -- | Get the value of the depth option, if any. | -- | Get the value of the depth option, if any. | ||||||
| depthFromOpts :: [Opt] -> Maybe Int | depthFromOpts :: [Opt] -> Maybe Int | ||||||
| depthFromOpts opts =  | depthFromOpts opts = | ||||||
|     case depthopts of |     case depthopts of | ||||||
|       (x:_) -> Just $ read x |       (x:_) -> Just $ read x | ||||||
|       _     -> Nothing |       _     -> Nothing | ||||||
|  | |||||||
							
								
								
									
										38
									
								
								Tests.hs
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								Tests.hs
									
									
									
									
									
								
							| @ -127,7 +127,7 @@ balancecommand_tests = TestList [ | |||||||
|    "                  $1  liabilities\n" ++ |    "                  $1  liabilities\n" ++ | ||||||
|    "") |    "") | ||||||
|  , |  , | ||||||
|   "balance report with --subtotal" ~: |   "balance report with -s" ~: | ||||||
|   ([SubTotal], []) `gives` |   ([SubTotal], []) `gives` | ||||||
|   ("                 $-1  assets\n" ++ |   ("                 $-1  assets\n" ++ | ||||||
|    "                 $-2    cash\n" ++ |    "                 $-2    cash\n" ++ | ||||||
| @ -140,6 +140,28 @@ balancecommand_tests = TestList [ | |||||||
|    "                 $-1    salary\n" ++ |    "                 $-1    salary\n" ++ | ||||||
|    "                  $1  liabilities:debts\n" ++ |    "                  $1  liabilities:debts\n" ++ | ||||||
|    "") |    "") | ||||||
|  |  , | ||||||
|  |   "balance report --depth limits -s" ~: | ||||||
|  |   ([SubTotal,Depth "1"], []) `gives` | ||||||
|  |   ("                 $-1  assets\n" ++ | ||||||
|  |    "                  $2  expenses\n" ++ | ||||||
|  |    "                 $-2  income\n" ++ | ||||||
|  |    "                  $1  liabilities\n" ++ | ||||||
|  |    "") | ||||||
|  |  , | ||||||
|  |   "balance report --depth activates -s" ~: | ||||||
|  |   ([Depth "2"], []) `gives` | ||||||
|  |   ("                 $-1  assets\n" ++ | ||||||
|  |    "                 $-2    cash\n" ++ | ||||||
|  |    "                  $1    saving\n" ++ | ||||||
|  |    "                  $2  expenses\n" ++ | ||||||
|  |    "                  $1    food\n" ++ | ||||||
|  |    "                  $1    supplies\n" ++ | ||||||
|  |    "                 $-2  income\n" ++ | ||||||
|  |    "                 $-1    gifts\n" ++ | ||||||
|  |    "                 $-1    salary\n" ++ | ||||||
|  |    "                  $1  liabilities:debts\n" ++ | ||||||
|  |    "") | ||||||
|  , |  , | ||||||
|   "balance report with account pattern o" ~: |   "balance report with account pattern o" ~: | ||||||
|   ([], ["o"]) `gives` |   ([], ["o"]) `gives` | ||||||
| @ -149,7 +171,7 @@ balancecommand_tests = TestList [ | |||||||
|    "                 $-1\n" ++ |    "                 $-1\n" ++ | ||||||
|    "") |    "") | ||||||
|  , |  , | ||||||
|   "balance report with account pattern o and --subtotal" ~: |   "balance report with account pattern o and -s" ~: | ||||||
|   ([SubTotal], ["o"]) `gives` |   ([SubTotal], ["o"]) `gives` | ||||||
|   ("                  $1  expenses:food\n" ++ |   ("                  $1  expenses:food\n" ++ | ||||||
|    "                 $-2  income\n" ++ |    "                 $-2  income\n" ++ | ||||||
| @ -227,18 +249,6 @@ balancecommand_tests = TestList [ | |||||||
|   ([Collapse], ["cash"]) `gives` |   ([Collapse], ["cash"]) `gives` | ||||||
|   ("                 $-2  assets:cash\n" ++ |   ("                 $-2  assets:cash\n" ++ | ||||||
|    "") |    "") | ||||||
|  , |  | ||||||
|   "balance report with --depth 1" ~: |  | ||||||
|   ([SubTotal,Collapse,Depth "1"], ["assets"]) `gives` |  | ||||||
|   ("                 $-1  assets\n" ++ |  | ||||||
|    "") |  | ||||||
|  , |  | ||||||
|   "balance report with --depth 2" ~: |  | ||||||
|   ([SubTotal,Collapse,Depth "2"], ["assets"]) `gives` |  | ||||||
|   ("                 $-1  assets\n" ++ |  | ||||||
|    "                 $-2    cash\n" ++ |  | ||||||
|    "                  $1    saving\n" ++ |  | ||||||
|    "") |  | ||||||
|  , |  , | ||||||
|   "balance report with cost basis" ~: do |   "balance report with cost basis" ~: do | ||||||
|     let l = cacheLedger [] $  |     let l = cacheLedger [] $  | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user