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

all: change optional to result in most of the libraries (#16123)

This commit is contained in:
yuyi
2022-10-21 03:14:33 +08:00
committed by GitHub
parent 0d368562f4
commit 51f4d99399
75 changed files with 439 additions and 446 deletions

View File

@@ -1,41 +1,34 @@
module base58
fn main() {
test_encode_int() or {}
test_decode_int() or {}
test_encode_string()
test_fails() or {}
}
fn test_encode_int() ? {
fn test_encode_int() {
a := 0x24 // should be 'd' in base58
assert encode_int(a)? == 'd'
assert encode_int(a)! == 'd'
test_encode_int_walpha()?
test_encode_int_walpha()
}
fn test_encode_int_walpha() ? {
fn test_encode_int_walpha() {
// random alphabet
abc := new_alphabet('abcdefghij\$lmnopqrstuvwxyz0123456789_ABCDEFGHIJLMNOPQRSTUV') or {
panic(@MOD + '.' + @FN + ': this should never happen')
}
a := 0x24 // should be '_' in base58 with our custom alphabet
assert encode_int_walpha(a, abc)? == '_'
assert encode_int_walpha(a, abc)! == '_'
}
fn test_decode_int() ? {
fn test_decode_int() {
a := 'd'
assert decode_int(a)? == 0x24
assert decode_int(a)! == 0x24
test_decode_int_walpha()?
test_decode_int_walpha()
}
fn test_decode_int_walpha() ? {
fn test_decode_int_walpha() {
abc := new_alphabet('abcdefghij\$lmnopqrstuvwxyz0123456789_ABCDEFGHIJLMNOPQRSTUV') or {
panic(@MOD + '.' + @FN + ': this should never happen')
}
a := '_'
assert decode_int_walpha(a, abc)? == 0x24
assert decode_int_walpha(a, abc)! == 0x24
}
fn test_encode_string() {
@@ -49,18 +42,18 @@ fn test_encode_string() {
assert encode_walpha(a, abc) == '0P7yfPSL0pQh2L5'
}
fn test_decode_string() ? {
fn test_decode_string() {
a := 'TtaR6twpTGu8VpY'
assert decode(a)? == 'lorem ipsum'
assert decode(a)! == 'lorem ipsum'
abc := new_alphabet('abcdefghij\$lmnopqrstuvwxyz0123456789_ABCDEFGHIJLMNOPQRSTUV') or {
panic(@MOD + '.' + @FN + ': this should never happen')
}
b := '0P7yfPSL0pQh2L5'
assert decode_walpha(b, abc)? == 'lorem ipsum'
assert decode_walpha(b, abc)! == 'lorem ipsum'
}
fn test_fails() ? {
fn test_fails() ! {
a := -238
b := 0
if z := encode_int(a) {