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

json2: improve readability, add tests utilizing fix #12667 (#12836)

This commit is contained in:
Larpon 2021-12-15 11:20:05 +01:00 committed by GitHub
parent 5b5d0bbb9c
commit 1d41d9daf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -69,10 +69,7 @@ pub fn (f Any) json_str() string {
string {
return json_string(f)
}
int {
return f.str()
}
u64, i64 {
bool, int, u64, i64 {
return f.str()
}
f32 {
@ -89,9 +86,6 @@ pub fn (f Any) json_str() string {
}
return str_f64
}
bool {
return f.str()
}
map[string]Any {
return f.str()
}

View File

@ -15,6 +15,14 @@ fn test_json_escape_low_chars() {
fn test_json_string() {
text := json2.Any('test')
assert text.json_str() == r'te\u2714st'
boolean := json2.Any(true)
assert boolean.json_str() == 'true'
integer := json2.Any(int(-5))
assert integer.json_str() == '-5'
u64integer := json2.Any(u64(5000))
assert u64integer.json_str() == '5000'
i64integer := json2.Any(i64(-17))
assert i64integer.json_str() == '-17'
}
fn test_json_string_emoji() {