aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-11-30 14:12:01 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-11-30 14:12:01 -0500
commit4d8aa867c7f4661167a4742fbdd865ed2449503e (patch)
tree67c9aeedaa3eb36585d1747e1f96e8c4708fc707 /test
parentd302aaec38b9d295d39c4d87b53ee610bc9e0e07 (diff)
Add `base` parameter to integer parsing functions
Diffstat (limited to 'test')
-rw-r--r--test/integers.tm21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/integers.tm b/test/integers.tm
index 1b1f7569..67175f7a 100644
--- a/test/integers.tm
+++ b/test/integers.tm
@@ -105,3 +105,24 @@ func main()
assert Int64(6).get_bit(2) == yes
assert Int64(6).get_bit(3) == yes
assert Int64(6).get_bit(4) == no
+
+ assert Int.parse("123") == 123
+ assert Int.parse("0x10") == 16
+ assert Int.parse("0o10") == 8
+ assert Int.parse("0b10") == 2
+ assert Int.parse("abc") == none
+
+ assert Int.parse("-123") == -123
+ assert Int.parse("-0x10") == -16
+ assert Int.parse("-0o10") == -8
+ assert Int.parse("-0b10") == -2
+
+ for base in (2).to(36)
+ assert Int.parse("10", base=base) == base
+
+ assert Int.parse("111", base=1) == 3
+
+ assert Int.parse("z", base=36) == 35
+ assert Int.parse("Z", base=36) == 35
+ assert Int.parse("-z", base=36) == -35
+ assert Int.parse("-Z", base=36) == -35