port remaining Read.Common tests
This commit is contained in:
		
							parent
							
								
									f124007acf
								
							
						
					
					
						commit
						d1a7cc1c09
					
				| @ -345,7 +345,6 @@ samplejournal = readJournal' $ T.unlines | ||||
| tests_Hledger_Read = TestList $ | ||||
|   tests_readJournal' | ||||
|   ++ [ | ||||
|    tests_Hledger_Read_Common, | ||||
| --    LedgerReader.tests_Hledger_Read_LedgerReader, | ||||
|    TimeclockReader.tests_Hledger_Read_TimeclockReader, | ||||
|    TimedotReader.tests_Hledger_Read_TimedotReader, | ||||
|  | ||||
| @ -92,7 +92,6 @@ module Hledger.Read.Common ( | ||||
|   singlespacep, | ||||
| 
 | ||||
|   -- * tests | ||||
|   tests_Hledger_Read_Common, | ||||
|   easytests_Common, | ||||
| ) | ||||
| where | ||||
| @ -500,12 +499,6 @@ spaceandamountormissingp = | ||||
|     lift $ skipSome spacenonewline | ||||
|     Mixed . (:[]) <$> amountp | ||||
| 
 | ||||
| test_spaceandamountormissingp = TestCase $ do | ||||
|     assertParseEqual' (parseWithState mempty spaceandamountormissingp " $47.18") (Mixed [usd 47.18]) | ||||
|     assertParseEqual' (parseWithState mempty spaceandamountormissingp "$47.18") missingmixedamt | ||||
|     assertParseEqual' (parseWithState mempty spaceandamountormissingp " ") missingmixedamt | ||||
|     assertParseEqual' (parseWithState mempty spaceandamountormissingp "") missingmixedamt | ||||
| 
 | ||||
| -- | Parse a single-commodity amount, with optional symbol on the left or | ||||
| -- right, optional unit or total price, and optional (ignored) | ||||
| -- ledger-style balance assertion or fixed lot price declaration. | ||||
| @ -691,28 +684,6 @@ numberp suggestedStyle = label "number" $ do | ||||
|       Left errMsg -> fail errMsg | ||||
|       Right (q, p, d, g) -> pure (sign q, p, d, g) | ||||
| 
 | ||||
| test_numberp = TestCase $ do | ||||
|   let t `is` n = assertParseEqual (rtp (numberp Nothing) t) n | ||||
|   let assertFails = assertBool "numberp" . isLeft . rtp (numberp Nothing) | ||||
|   assertFails "" | ||||
|   "0"          `is` (0, 0, Nothing, Nothing) | ||||
|   "1"          `is` (1, 0, Nothing, Nothing) | ||||
|   "1.1"        `is` (1.1, 1, Just '.', Nothing) | ||||
|   "1,000.1"    `is` (1000.1, 1, Just '.', Just $ DigitGroups ',' [3]) | ||||
|   "1.00.000,1" `is` (100000.1, 1, Just ',', Just $ DigitGroups '.' [3,2]) | ||||
|   "1,000,000"  `is` (1000000, 0, Nothing, Just $ DigitGroups ',' [3,3])  -- could be simplified to [3] | ||||
|   "1."         `is` (1, 0, Just '.', Nothing) | ||||
|   "1,"         `is` (1, 0, Just ',', Nothing) | ||||
|   ".1"         `is` (0.1, 1, Just '.', Nothing) | ||||
|   ",1"         `is` (0.1, 1, Just ',', Nothing) | ||||
|   assertFails "1,000.000,1" | ||||
|   assertFails "1.000,000.1" | ||||
|   assertFails "1,000.000.1" | ||||
|   assertFails "1,,1" | ||||
|   assertFails "1..1" | ||||
|   assertFails ".1," | ||||
|   assertFails ",1." | ||||
| 
 | ||||
| exponentp :: TextParser m Int | ||||
| exponentp = char' 'e' *> signp <*> decimal <?> "exponent" | ||||
| 
 | ||||
| @ -1227,12 +1198,10 @@ match' p = do | ||||
|   (!txt, p) <- match p | ||||
|   pure (txt, p) | ||||
| 
 | ||||
| tests_Hledger_Read_Common = TestList [ | ||||
|    test_numberp | ||||
|   ,test_spaceandamountormissingp | ||||
|   ] | ||||
| --- * tests | ||||
| 
 | ||||
| easytests_Common = tests "Common" [ | ||||
| 
 | ||||
|   tests "amountp" [ | ||||
|     test "basic"                  $ expectParseEq amountp "$47.18"     (usd 47.18) | ||||
|    ,test "ends with decimal mark" $ expectParseEq amountp "$1."        (usd 1  `withPrecision` 0) | ||||
| @ -1263,4 +1232,34 @@ easytests_Common = tests "Common" [ | ||||
|             }  | ||||
|         }  | ||||
|     ] | ||||
| 
 | ||||
|   ,let p = lift (numberp Nothing) :: JournalParser IO (Quantity, Int, Maybe Char, Maybe DigitGroupStyle) in | ||||
|    tests "numberp" [ | ||||
|      test "." $ expectParseEq p "0"          (0, 0, Nothing, Nothing) | ||||
|     ,test "." $ expectParseEq p "1"          (1, 0, Nothing, Nothing) | ||||
|     ,test "." $ expectParseEq p "1.1"        (1.1, 1, Just '.', Nothing) | ||||
|     ,test "." $ expectParseEq p "1,000.1"    (1000.1, 1, Just '.', Just $ DigitGroups ',' [3]) | ||||
|     ,test "." $ expectParseEq p "1.00.000,1" (100000.1, 1, Just ',', Just $ DigitGroups '.' [3,2]) | ||||
|     ,test "." $ expectParseEq p "1,000,000"  (1000000, 0, Nothing, Just $ DigitGroups ',' [3,3])  -- could be simplified to [3] | ||||
|     ,test "." $ expectParseEq p "1."         (1, 0, Just '.', Nothing) | ||||
|     ,test "." $ expectParseEq p "1,"         (1, 0, Just ',', Nothing) | ||||
|     ,test "." $ expectParseEq p ".1"         (0.1, 1, Just '.', Nothing) | ||||
|     ,test "." $ expectParseEq p ",1"         (0.1, 1, Just ',', Nothing) | ||||
|     ,test "." $ expectParseError p "" "" | ||||
|     ,test "." $ expectParseError p "1,000.000,1" "" | ||||
|     ,test "." $ expectParseError p "1.000,000.1" "" | ||||
|     ,test "." $ expectParseError p "1,000.000.1" "" | ||||
|     ,test "." $ expectParseError p "1,,1" "" | ||||
|     ,test "." $ expectParseError p "1..1" "" | ||||
|     ,test "." $ expectParseError p ".1," "" | ||||
|     ,test "." $ expectParseError p ",1." "" | ||||
|     ] | ||||
|    | ||||
|   ,tests "spaceandamountormissingp" [ | ||||
|      test "space and amount" $ expectParseEq spaceandamountormissingp " $47.18" (Mixed [usd 47.18]) | ||||
|     ,test "empty string" $ expectParseEq spaceandamountormissingp "" missingmixedamt | ||||
|     ,_test "just space" $ expectParseEq spaceandamountormissingp " " missingmixedamt  -- XXX should it ? | ||||
|     -- ,test "just amount" $ expectParseError spaceandamountormissingp "$47.18" ""  -- succeeds, consuming nothing | ||||
|     ] | ||||
| 
 | ||||
|   ] | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user