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:
@ -1,43 +1,43 @@
|
||||
module json2
|
||||
|
||||
fn test_raw_decode_string() {
|
||||
str := raw_decode('"Hello!"')?
|
||||
str := raw_decode('"Hello!"')!
|
||||
assert str.str() == 'Hello!'
|
||||
}
|
||||
|
||||
fn test_raw_decode_string_escape() {
|
||||
jstr := raw_decode('"\u001b"')?
|
||||
jstr := raw_decode('"\u001b"')!
|
||||
str := jstr.str()
|
||||
assert str.len == 1
|
||||
assert str[0] == 27
|
||||
}
|
||||
|
||||
fn test_raw_decode_number() {
|
||||
num := raw_decode('123')?
|
||||
num := raw_decode('123')!
|
||||
assert num.int() == 123
|
||||
}
|
||||
|
||||
fn test_raw_decode_array() {
|
||||
raw_arr := raw_decode('["Foo", 1]')?
|
||||
raw_arr := raw_decode('["Foo", 1]')!
|
||||
arr := raw_arr.arr()
|
||||
assert arr[0] or { 0 }.str() == 'Foo'
|
||||
assert arr[1] or { 0 }.int() == 1
|
||||
}
|
||||
|
||||
fn test_raw_decode_bool() {
|
||||
bol := raw_decode('false')?
|
||||
bol := raw_decode('false')!
|
||||
assert bol.bool() == false
|
||||
}
|
||||
|
||||
fn test_raw_decode_map() {
|
||||
raw_mp := raw_decode('{"name":"Bob","age":20}')?
|
||||
raw_mp := raw_decode('{"name":"Bob","age":20}')!
|
||||
mp := raw_mp.as_map()
|
||||
assert mp['name'] or { 0 }.str() == 'Bob'
|
||||
assert mp['age'] or { 0 }.int() == 20
|
||||
}
|
||||
|
||||
fn test_raw_decode_null() {
|
||||
nul := raw_decode('null')?
|
||||
nul := raw_decode('null')!
|
||||
assert nul is Null
|
||||
}
|
||||
|
||||
@ -50,12 +50,12 @@ fn test_raw_decode_invalid() {
|
||||
}
|
||||
|
||||
fn test_raw_decode_string_with_dollarsign() {
|
||||
str := raw_decode(r'"Hello $world"')?
|
||||
str := raw_decode(r'"Hello $world"')!
|
||||
assert str.str() == r'Hello $world'
|
||||
}
|
||||
|
||||
fn test_raw_decode_map_with_whitespaces() {
|
||||
raw_mp := raw_decode(' \n\t{"name":"Bob","age":20}\n\t')?
|
||||
raw_mp := raw_decode(' \n\t{"name":"Bob","age":20}\n\t')!
|
||||
mp := raw_mp.as_map()
|
||||
assert mp['name'] or { 0 }.str() == 'Bob'
|
||||
assert mp['age'] or { 0 }.int() == 20
|
||||
@ -63,7 +63,7 @@ fn test_raw_decode_map_with_whitespaces() {
|
||||
|
||||
fn test_nested_array_object() {
|
||||
mut parser := new_parser(r'[[[[[],[],[]]]],{"Test":{}},[[]]]', false)
|
||||
decoded := parser.decode()?
|
||||
decoded := parser.decode()!
|
||||
assert parser.n_level == 0
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user