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

atoi.v: add common_parse_uint2 with error code return values (#6550)

This commit is contained in:
vmcrash
2020-10-03 19:57:37 +02:00
committed by GitHub
parent d93b0f047a
commit c5e46c9e55
2 changed files with 54 additions and 24 deletions

View File

@ -26,3 +26,37 @@ fn test_parse_int() {
assert strconv.parse_int('123', 10, 65) == 0
assert strconv.parse_int('123', 10, -1) == 0
}
fn test_common_parse_uint2() {
mut result, mut error := strconv.common_parse_uint2('1', 10, 8)
assert result == 1
assert error == 0
result, error = strconv.common_parse_uint2('123', 10, 8)
assert result == 123
assert error == 0
result, error = strconv.common_parse_uint2('123', 10, 65)
assert result == 0
assert error == -2
result, error = strconv.common_parse_uint2('123', 10, -1)
assert result == 0
assert error == -2
result, error = strconv.common_parse_uint2('', 10, 8)
assert result == 0
assert error == 1
result, error = strconv.common_parse_uint2('1a', 10, 8)
assert result == 1
assert error == 2
result, error = strconv.common_parse_uint2('12a', 10, 8)
assert result == 12
assert error == 3
result, error = strconv.common_parse_uint2('123a', 10, 8)
assert result == 123
assert error == 4
}