mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tests: make error handling the same as the main function (#15825)
This commit is contained in:
@ -27,7 +27,7 @@ fn test_header_adds_multiple() {
|
||||
assert h.values(.accept) == ['one', 'two']
|
||||
}
|
||||
|
||||
fn test_header_get() ? {
|
||||
fn test_header_get() {
|
||||
mut h := new_header(key: .dnt, value: 'one')
|
||||
h.add_custom('dnt', 'two')?
|
||||
dnt := h.get_custom('dnt') or { '' }
|
||||
@ -36,7 +36,7 @@ fn test_header_get() ? {
|
||||
assert exact == 'two'
|
||||
}
|
||||
|
||||
fn test_header_set() ? {
|
||||
fn test_header_set() {
|
||||
mut h := new_header(HeaderConfig{ key: .dnt, value: 'one' },
|
||||
key: .dnt
|
||||
value: 'two'
|
||||
@ -65,7 +65,7 @@ fn test_header_delete_not_existing() {
|
||||
assert h.keys.len == 0
|
||||
}
|
||||
|
||||
fn test_custom_header() ? {
|
||||
fn test_custom_header() {
|
||||
mut h := new_header()
|
||||
h.add_custom('AbC', 'dEf')?
|
||||
h.add_custom('aBc', 'GhI')?
|
||||
@ -89,7 +89,7 @@ fn test_custom_header() ? {
|
||||
assert h.keys() == ['accEPT']
|
||||
}
|
||||
|
||||
fn test_contains_custom() ? {
|
||||
fn test_contains_custom() {
|
||||
mut h := new_header()
|
||||
h.add_custom('Hello', 'world')?
|
||||
assert h.contains_custom('hello')
|
||||
@ -99,7 +99,7 @@ fn test_contains_custom() ? {
|
||||
assert h.contains_custom('HELLO', exact: true) == false
|
||||
}
|
||||
|
||||
fn test_get_custom() ? {
|
||||
fn test_get_custom() {
|
||||
mut h := new_header()
|
||||
h.add_custom('Hello', 'world')?
|
||||
assert h.get_custom('hello')? == 'world'
|
||||
@ -115,7 +115,7 @@ fn test_get_custom() ? {
|
||||
}
|
||||
}
|
||||
|
||||
fn test_starting_with() ? {
|
||||
fn test_starting_with() {
|
||||
mut h := new_header()
|
||||
h.add_custom('Hello-1', 'world')?
|
||||
h.add_custom('Hello-21', 'world')?
|
||||
@ -123,7 +123,7 @@ fn test_starting_with() ? {
|
||||
assert h.starting_with('Hello-2')? == 'Hello-21'
|
||||
}
|
||||
|
||||
fn test_custom_values() ? {
|
||||
fn test_custom_values() {
|
||||
mut h := new_header()
|
||||
h.add_custom('Hello', 'world')?
|
||||
assert h.custom_values('hello') == ['world']
|
||||
@ -133,7 +133,7 @@ fn test_custom_values() ? {
|
||||
assert h.custom_values('HELLO', exact: true) == []
|
||||
}
|
||||
|
||||
fn test_coerce() ? {
|
||||
fn test_coerce() {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add(.accept, 'bar')
|
||||
@ -145,7 +145,7 @@ fn test_coerce() ? {
|
||||
assert h.keys() == ['accept'] // takes the first occurrence
|
||||
}
|
||||
|
||||
fn test_coerce_canonicalize() ? {
|
||||
fn test_coerce_canonicalize() {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add(.accept, 'bar')
|
||||
@ -157,7 +157,7 @@ fn test_coerce_canonicalize() ? {
|
||||
assert h.keys() == ['Accept'] // canonicalize header
|
||||
}
|
||||
|
||||
fn test_coerce_custom() ? {
|
||||
fn test_coerce_custom() {
|
||||
mut h := new_header()
|
||||
h.add_custom('Hello', 'foo')?
|
||||
h.add_custom('hello', 'bar')?
|
||||
@ -170,7 +170,7 @@ fn test_coerce_custom() ? {
|
||||
assert h.keys() == ['Hello'] // takes the first occurrence
|
||||
}
|
||||
|
||||
fn test_coerce_canonicalize_custom() ? {
|
||||
fn test_coerce_canonicalize_custom() {
|
||||
mut h := new_header()
|
||||
h.add_custom('foo-BAR', 'foo')?
|
||||
h.add_custom('FOO-bar', 'bar')?
|
||||
@ -182,7 +182,7 @@ fn test_coerce_canonicalize_custom() ? {
|
||||
assert h.keys() == ['Foo-Bar'] // capitalizes the header
|
||||
}
|
||||
|
||||
fn test_render_version() ? {
|
||||
fn test_render_version() {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add_custom('Accept', 'bar')?
|
||||
@ -204,7 +204,7 @@ fn test_render_version() ? {
|
||||
assert s2_0.contains('accept: baz\r\n')
|
||||
}
|
||||
|
||||
fn test_render_coerce() ? {
|
||||
fn test_render_coerce() {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add_custom('Accept', 'bar')?
|
||||
@ -230,7 +230,7 @@ fn test_render_coerce() ? {
|
||||
assert s2_0.contains('host: host\r\n')
|
||||
}
|
||||
|
||||
fn test_render_canonicalize() ? {
|
||||
fn test_render_canonicalize() {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add_custom('Accept', 'bar')?
|
||||
@ -256,7 +256,7 @@ fn test_render_canonicalize() ? {
|
||||
assert s2_0.contains('host: host\r\n')
|
||||
}
|
||||
|
||||
fn test_render_coerce_canonicalize() ? {
|
||||
fn test_render_coerce_canonicalize() {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add_custom('Accept', 'bar')?
|
||||
@ -282,7 +282,7 @@ fn test_render_coerce_canonicalize() ? {
|
||||
assert s2_0.contains('host: host\r\n')
|
||||
}
|
||||
|
||||
fn test_str() ? {
|
||||
fn test_str() {
|
||||
mut h := new_header()
|
||||
h.add(.accept, 'text/html')
|
||||
h.add_custom('Accept', 'image/jpeg')?
|
||||
@ -293,7 +293,7 @@ fn test_str() ? {
|
||||
|| h.str() == 'X-custom: Hello\r\nAccept:text/html\r\nAccept: image/jpeg\r\n'
|
||||
}
|
||||
|
||||
fn test_header_from_map() ? {
|
||||
fn test_header_from_map() {
|
||||
h := new_header_from_map({
|
||||
CommonHeader.accept: 'nothing'
|
||||
CommonHeader.expires: 'yesterday'
|
||||
@ -304,7 +304,7 @@ fn test_header_from_map() ? {
|
||||
assert h.get(.expires) or { '' } == 'yesterday'
|
||||
}
|
||||
|
||||
fn test_custom_header_from_map() ? {
|
||||
fn test_custom_header_from_map() {
|
||||
h := new_custom_header_from_map({
|
||||
'Server': 'VWeb'
|
||||
'foo': 'bar'
|
||||
@ -315,7 +315,7 @@ fn test_custom_header_from_map() ? {
|
||||
assert h.get_custom('foo') or { '' } == 'bar'
|
||||
}
|
||||
|
||||
fn test_header_join() ? {
|
||||
fn test_header_join() {
|
||||
h1 := new_header_from_map({
|
||||
CommonHeader.accept: 'nothing'
|
||||
CommonHeader.expires: 'yesterday'
|
||||
|
@ -174,7 +174,7 @@ fn test_multipart_form_body() {
|
||||
assert parsed_form == form
|
||||
}
|
||||
|
||||
fn test_parse_large_body() ? {
|
||||
fn test_parse_large_body() {
|
||||
body := 'A'.repeat(101) // greater than max_bytes
|
||||
req := 'GET / HTTP/1.1\r\nContent-Length: $body.len\r\n\r\n$body'
|
||||
mut reader_ := reader(req)
|
||||
|
@ -1,6 +1,6 @@
|
||||
module http
|
||||
|
||||
fn test_response_bytestr() ? {
|
||||
fn test_response_bytestr() {
|
||||
{
|
||||
resp := new_response(
|
||||
status: .ok
|
||||
|
@ -1,7 +1,7 @@
|
||||
import net.http
|
||||
import time
|
||||
|
||||
fn test_server_stop() ? {
|
||||
fn test_server_stop() {
|
||||
mut server := &http.Server{
|
||||
accept_timeout: 1 * time.second
|
||||
}
|
||||
@ -15,7 +15,7 @@ fn test_server_stop() ? {
|
||||
assert watch.elapsed() < 999 * time.millisecond
|
||||
}
|
||||
|
||||
fn test_server_close() ? {
|
||||
fn test_server_close() {
|
||||
mut server := &http.Server{
|
||||
accept_timeout: 1 * time.second
|
||||
handler: MyHttpHandler{}
|
||||
@ -60,7 +60,7 @@ fn (mut handler MyHttpHandler) handle(req http.Request) http.Response {
|
||||
|
||||
const cport = 8198
|
||||
|
||||
fn test_server_custom_handler() ? {
|
||||
fn test_server_custom_handler() {
|
||||
mut handler := MyHttpHandler{}
|
||||
mut server := &http.Server{
|
||||
accept_timeout: 1 * time.second
|
||||
|
@ -124,7 +124,7 @@ fn test_smtp_implicit_ssl() {
|
||||
assert client.is_open && client.encrypted
|
||||
}
|
||||
|
||||
fn test_smtp_multiple_recipients() ? {
|
||||
fn test_smtp_multiple_recipients() {
|
||||
$if !network ? {
|
||||
return
|
||||
}
|
||||
@ -132,7 +132,7 @@ fn test_smtp_multiple_recipients() ? {
|
||||
assert true
|
||||
}
|
||||
|
||||
fn test_smtp_body_base64encode() ? {
|
||||
fn test_smtp_body_base64encode() {
|
||||
$if !network ? {
|
||||
return
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ fn testsuite_end() {
|
||||
eprintln('\ndone')
|
||||
}
|
||||
|
||||
fn test_bind() ? {
|
||||
fn test_bind() {
|
||||
$if !network ? {
|
||||
return
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ fn test_escape_unescape() {
|
||||
assert unescaped == original
|
||||
}
|
||||
|
||||
fn test_parse_query() ? {
|
||||
fn test_parse_query() {
|
||||
q1 := urllib.parse_query('format=%22%25l%3A+%25c+%25t%22')?
|
||||
q2 := urllib.parse_query('format="%l:+%c+%t"')?
|
||||
// dump(q1)
|
||||
@ -44,13 +44,13 @@ fn test_parse_query() ? {
|
||||
assert q2.get('format') == '"%l: %c %t"'
|
||||
}
|
||||
|
||||
fn test_parse_query_orders() ? {
|
||||
fn test_parse_query_orders() {
|
||||
query_one := urllib.parse_query('https://someapi.com/endpoint?gamma=zalibaba&tau=1&alpha=alibaba&signature=alibaba123')?
|
||||
qvalues := query_one.values()
|
||||
assert qvalues == ['zalibaba', '1', 'alibaba', 'alibaba123']
|
||||
}
|
||||
|
||||
fn test_parse_missing_host() ? {
|
||||
fn test_parse_missing_host() {
|
||||
// issue #10311
|
||||
url := urllib.parse('http:///')?
|
||||
assert url.str() == 'http://///'
|
||||
@ -58,7 +58,7 @@ fn test_parse_missing_host() ? {
|
||||
|
||||
// testing the case where the key as a null value
|
||||
// e.g ?key=
|
||||
fn test_parse_none_value() ? {
|
||||
fn test_parse_none_value() {
|
||||
query_one := urllib.parse_query('gamma=zalibaba&tau=1&alpha=alibaba&signature=')?
|
||||
qvalues := query_one.values()
|
||||
qvalues_map := query_one.to_map()
|
||||
@ -73,7 +73,7 @@ fn test_parse_none_value() ? {
|
||||
|
||||
// testing the case where the query as empity value
|
||||
// e.g https://www.vlang.dev?alibaba
|
||||
fn test_parse_empty_query_one() ? {
|
||||
fn test_parse_empty_query_one() {
|
||||
query_str := 'alibaba'
|
||||
query_one := urllib.parse_query(query_str)?
|
||||
qvalues := query_one.values()
|
||||
@ -88,7 +88,7 @@ fn test_parse_empty_query_one() ? {
|
||||
|
||||
// testing the case where the query as empity value
|
||||
// e.g https://www.vlang.dev?
|
||||
fn test_parse_empty_query_two() ? {
|
||||
fn test_parse_empty_query_two() {
|
||||
query_str := ''
|
||||
query_one := urllib.parse_query(query_str)?
|
||||
qvalues := query_one.values()
|
||||
@ -99,7 +99,7 @@ fn test_parse_empty_query_two() ? {
|
||||
assert query_str == query_encode
|
||||
}
|
||||
|
||||
fn test_parse() ? {
|
||||
fn test_parse() {
|
||||
urls := [
|
||||
'jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true',
|
||||
'ftp://ftp.is.co.za/rfc/rfc1808.txt',
|
||||
|
Reference in New Issue
Block a user