mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
x.json2.decoder2: improve string tests (#23809)
This commit is contained in:
parent
4f98fe982c
commit
c349381aa5
1 changed files with 27 additions and 1 deletions
|
@ -9,7 +9,8 @@ fn test_json_escape_low_chars() {
|
|||
|
||||
fn test_json_string() {
|
||||
assert json.decode[string](r'"te\u2714st"')! == 'te✔st'
|
||||
// assert json.decode[string]('te✔st')! == 'te✔st'
|
||||
assert json.decode[string](r'"te✔st"')! == 'te✔st'
|
||||
assert json.decode[string]('""')! == ''
|
||||
}
|
||||
|
||||
fn test_json_string_emoji() {
|
||||
|
@ -28,3 +29,28 @@ fn test_utf8_strings_are_not_modified() {
|
|||
assert json.decode[string]('"ü"')! == 'ü'
|
||||
assert json.decode[string]('"Schilddrüsenerkrankungen"')! == 'Schilddrüsenerkrankungen'
|
||||
}
|
||||
|
||||
fn test_json_string_invalid_escapes() {
|
||||
mut has_error := false
|
||||
|
||||
json.decode[string](r'"\x"') or {
|
||||
assert err.msg() == '\n"\\\n ^ unknown escape sequence'
|
||||
has_error = true
|
||||
} // Invalid escape
|
||||
|
||||
assert has_error, 'Expected error'
|
||||
has_error = false
|
||||
|
||||
json.decode[string](r'"\u123"') or {
|
||||
assert err.msg() == '\n"\\\n ^ short unicode escape sequence \\u123"'
|
||||
has_error = true
|
||||
} // Incomplete Unicode
|
||||
|
||||
assert has_error, 'Expected error'
|
||||
}
|
||||
|
||||
fn test_json_string_whitespace() {
|
||||
// Test strings with whitespace
|
||||
assert json.decode[string]('" "')! == ' '
|
||||
assert json.decode[string]('"\t\n\r"')! == '\t\n\r'
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue