1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: change optional to result of io (#16075)

This commit is contained in:
yuyi
2022-10-16 14:28:57 +08:00
committed by GitHub
parent 6e46933c55
commit f6844e9766
187 changed files with 1885 additions and 1874 deletions

View File

@@ -1,9 +1,9 @@
import strconv
fn test_atoi() ? {
assert strconv.atoi('16')? == 16
assert strconv.atoi('+16')? == 16
assert strconv.atoi('-16')? == -16
fn test_atoi() {
assert strconv.atoi('16')! == 16
assert strconv.atoi('+16')! == 16
assert strconv.atoi('-16')! == -16
// invalid strings
if x := strconv.atoi('str') {
@@ -26,20 +26,20 @@ fn test_atoi() ? {
}
}
fn test_parse_int() ? {
fn test_parse_int() {
// Different bases
assert strconv.parse_int('16', 16, 0)? == 0x16
assert strconv.parse_int('16', 8, 0)? == 0o16
assert strconv.parse_int('11', 2, 0)? == 3
assert strconv.parse_int('16', 16, 0)! == 0x16
assert strconv.parse_int('16', 8, 0)! == 0o16
assert strconv.parse_int('11', 2, 0)! == 3
// Different bit sizes
assert strconv.parse_int('127', 10, 8)? == 127
assert strconv.parse_int('128', 10, 8)? == 127
assert strconv.parse_int('32767', 10, 16)? == 32767
assert strconv.parse_int('32768', 10, 16)? == 32767
assert strconv.parse_int('2147483647', 10, 32)? == 2147483647
assert strconv.parse_int('2147483648', 10, 32)? == 2147483647
assert strconv.parse_int('9223372036854775807', 10, 64)? == 9223372036854775807
assert strconv.parse_int('9223372036854775808', 10, 64)? == 9223372036854775807
assert strconv.parse_int('127', 10, 8)! == 127
assert strconv.parse_int('128', 10, 8)! == 127
assert strconv.parse_int('32767', 10, 16)! == 32767
assert strconv.parse_int('32768', 10, 16)! == 32767
assert strconv.parse_int('2147483647', 10, 32)! == 2147483647
assert strconv.parse_int('2147483648', 10, 32)! == 2147483647
assert strconv.parse_int('9223372036854775807', 10, 64)! == 9223372036854775807
assert strconv.parse_int('9223372036854775808', 10, 64)! == 9223372036854775807
assert strconv.parse_int('baobab', 36, 64)? == 683058467
// Invalid bit sizes
if x := strconv.parse_int('123', 10, -1) {