lib: more runPeriodicTransaction tests (lifted from #1085 and spanIntervalIntersect)
This commit is contained in:
		
							parent
							
								
									e9d300bef3
								
							
						
					
					
						commit
						568cb32677
					
				| @ -45,6 +45,17 @@ _ptgen str = do | |||||||
|           nullperiodictransaction{ ptperiodexpr=t , ptspan=s, ptinterval=i, ptpostings=["a" `post` usd 1] } |           nullperiodictransaction{ ptperiodexpr=t , ptspan=s, ptinterval=i, ptpostings=["a" `post` usd 1] } | ||||||
|           nulldatespan |           nulldatespan | ||||||
| 
 | 
 | ||||||
|  | _ptgenspan str span = do | ||||||
|  |   let | ||||||
|  |     t = T.pack str | ||||||
|  |     (i,s) = parsePeriodExpr' nulldate t | ||||||
|  |   case checkPeriodicTransactionStartDate i s t of | ||||||
|  |     Just e  -> error' e | ||||||
|  |     Nothing -> | ||||||
|  |       mapM_ (putStr . showTransaction) $ | ||||||
|  |         runPeriodicTransaction | ||||||
|  |           nullperiodictransaction{ ptperiodexpr=t , ptspan=s, ptinterval=i, ptpostings=["a" `post` usd 1] } | ||||||
|  |           span | ||||||
| 
 | 
 | ||||||
| --deriving instance Show PeriodicTransaction | --deriving instance Show PeriodicTransaction | ||||||
| -- for better pretty-printing: | -- for better pretty-printing: | ||||||
| @ -199,6 +210,28 @@ instance Show PeriodicTransaction where | |||||||
| -- >>> let reportperiod="daily from 2018/01/03" in let (i,s) = parsePeriodExpr' nulldate reportperiod in runPeriodicTransaction (nullperiodictransaction{ptperiodexpr=reportperiod, ptspan=s, ptinterval=i, ptpostings=["a" `post` usd 1]}) (DateSpan (Just $ parsedate "2018-01-01") (Just $ parsedate "2018-01-03")) | -- >>> let reportperiod="daily from 2018/01/03" in let (i,s) = parsePeriodExpr' nulldate reportperiod in runPeriodicTransaction (nullperiodictransaction{ptperiodexpr=reportperiod, ptspan=s, ptinterval=i, ptpostings=["a" `post` usd 1]}) (DateSpan (Just $ parsedate "2018-01-01") (Just $ parsedate "2018-01-03")) | ||||||
| -- [] | -- [] | ||||||
| -- | -- | ||||||
|  | -- >>> _ptgenspan "every 3 months from 2019-05" (mkdatespan "2020-01-01" "2020-02-01") | ||||||
|  | --   | ||||||
|  | -- >>> _ptgenspan "every 3 months from 2019-05" (mkdatespan "2020-02-01" "2020-03-01") | ||||||
|  | -- 2020/02/01 | ||||||
|  | --     ; generated-transaction:~ every 3 months from 2019-05 | ||||||
|  | --     a           $1.00 | ||||||
|  | -- <BLANKLINE> | ||||||
|  | -- >>> _ptgenspan "every 3 days from 2018" (mkdatespan "2018-01-01" "2018-01-05") | ||||||
|  | -- 2018/01/01 | ||||||
|  | --     ; generated-transaction:~ every 3 days from 2018 | ||||||
|  | --     a           $1.00 | ||||||
|  | -- <BLANKLINE> | ||||||
|  | -- 2018/01/04 | ||||||
|  | --     ; generated-transaction:~ every 3 days from 2018 | ||||||
|  | --     a           $1.00 | ||||||
|  | -- <BLANKLINE> | ||||||
|  | -- >>> _ptgenspan "every 3 days from 2018" (mkdatespan "2018-01-02" "2018-01-05") | ||||||
|  | -- 2018/01/04 | ||||||
|  | --     ; generated-transaction:~ every 3 days from 2018 | ||||||
|  | --     a           $1.00 | ||||||
|  | -- <BLANKLINE> | ||||||
|  | 
 | ||||||
| runPeriodicTransaction :: PeriodicTransaction -> DateSpan -> [Transaction] | runPeriodicTransaction :: PeriodicTransaction -> DateSpan -> [Transaction] | ||||||
| runPeriodicTransaction PeriodicTransaction{..} requestedspan = | runPeriodicTransaction PeriodicTransaction{..} requestedspan = | ||||||
|     [ t{tdate=d} | (DateSpan (Just d) _) <- alltxnspans, spanContainsDate requestedspan d ] |     [ t{tdate=d} | (DateSpan (Just d) _) <- alltxnspans, spanContainsDate requestedspan d ] | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user