numbers: Nat unit tests

This commit is contained in:
Nathan McCarty 2025-01-24 18:09:20 -05:00
parent 2b78275a4b
commit 82b16a0e63

View file

@ -51,7 +51,11 @@ hex = MkBase 16
```idris ```idris
export export
nat : Parser Nat nat : Base -> Parser Nat
export
natBase10 : Parser Nat
natBase10 = nat base10
``` ```
## Unit tests ## Unit tests
@ -68,7 +72,24 @@ roundtrip x p = do
putStrLn "Failed to produce parser for \{string}" putStrLn "Failed to produce parser for \{string}"
pure False pure False
Right result <- runEff (rundownFirst p) [handleParserStateIO state] {m = IO} Right result <- runEff (rundownFirst p) [handleParserStateIO state] {m = IO}
| Left err => ?show_err | Left err => do
printLn err
pure False
putStrLn "Input: \{string} Output: \{show result}" putStrLn "Input: \{string} Output: \{show result}"
pure $ x == result pure $ x == result
``` ```
Do some roundtrip tests with the nat parser
```idris
-- @@test Nat round trip
natRoundTrip : IO Bool
natRoundTrip = pure $
!(roundtrip 0 natBase10)
&& !(roundtrip 1 natBase10)
&& !(roundtrip 100 natBase10)
&& !(roundtrip 1234 natBase10)
&& !(roundtrip 1234567890 natBase10)
&& !(roundtrip 1234567890000 natBase10)
&& !(roundtrip 12345678901234567890 natBase10)
```