mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: remove space in front of ? and ! (#14366)
This commit is contained in:
@ -29,7 +29,7 @@ fn test_header_adds_multiple() {
|
||||
|
||||
fn test_header_get() ? {
|
||||
mut h := new_header(key: .dnt, value: 'one')
|
||||
h.add_custom('dnt', 'two') ?
|
||||
h.add_custom('dnt', 'two')?
|
||||
dnt := h.get_custom('dnt') or { '' }
|
||||
exact := h.get_custom('dnt', exact: true) or { '' }
|
||||
assert dnt == 'one'
|
||||
@ -42,7 +42,7 @@ fn test_header_set() ? {
|
||||
value: 'two'
|
||||
)
|
||||
assert h.values(.dnt) == ['one', 'two']
|
||||
h.set_custom('DNT', 'three') ?
|
||||
h.set_custom('DNT', 'three')?
|
||||
assert h.values(.dnt) == ['three']
|
||||
}
|
||||
|
||||
@ -67,8 +67,8 @@ fn test_header_delete_not_existing() {
|
||||
|
||||
fn test_custom_header() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('AbC', 'dEf') ?
|
||||
h.add_custom('aBc', 'GhI') ?
|
||||
h.add_custom('AbC', 'dEf')?
|
||||
h.add_custom('aBc', 'GhI')?
|
||||
assert h.custom_values('AbC', exact: true) == ['dEf']
|
||||
assert h.custom_values('aBc', exact: true) == ['GhI']
|
||||
assert h.custom_values('ABC') == ['dEf', 'GhI']
|
||||
@ -77,13 +77,13 @@ fn test_custom_header() ? {
|
||||
h.delete_custom('AbC')
|
||||
h.delete_custom('aBc')
|
||||
|
||||
h.add_custom('abc', 'def') ?
|
||||
h.add_custom('abc', 'def')?
|
||||
assert h.custom_values('abc') == ['def']
|
||||
assert h.custom_values('ABC') == ['def']
|
||||
assert h.keys() == ['abc']
|
||||
h.delete_custom('abc')
|
||||
|
||||
h.add_custom('accEPT', '*/*') ?
|
||||
h.add_custom('accEPT', '*/*')?
|
||||
assert h.custom_values('ACCept') == ['*/*']
|
||||
assert h.values(.accept) == ['*/*']
|
||||
assert h.keys() == ['accEPT']
|
||||
@ -91,7 +91,7 @@ fn test_custom_header() ? {
|
||||
|
||||
fn test_contains_custom() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('Hello', 'world') ?
|
||||
h.add_custom('Hello', 'world')?
|
||||
assert h.contains_custom('hello')
|
||||
assert h.contains_custom('HELLO')
|
||||
assert h.contains_custom('Hello', exact: true)
|
||||
@ -101,10 +101,10 @@ fn test_contains_custom() ? {
|
||||
|
||||
fn test_get_custom() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('Hello', 'world') ?
|
||||
assert h.get_custom('hello') ? == 'world'
|
||||
assert h.get_custom('HELLO') ? == 'world'
|
||||
assert h.get_custom('Hello', exact: true) ? == 'world'
|
||||
h.add_custom('Hello', 'world')?
|
||||
assert h.get_custom('hello')? == 'world'
|
||||
assert h.get_custom('HELLO')? == 'world'
|
||||
assert h.get_custom('Hello', exact: true)? == 'world'
|
||||
if _ := h.get_custom('hello', exact: true) {
|
||||
// should be none
|
||||
assert false
|
||||
@ -117,15 +117,15 @@ fn test_get_custom() ? {
|
||||
|
||||
fn test_starting_with() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('Hello-1', 'world') ?
|
||||
h.add_custom('Hello-21', 'world') ?
|
||||
assert h.starting_with('Hello-') ? == 'Hello-1'
|
||||
assert h.starting_with('Hello-2') ? == 'Hello-21'
|
||||
h.add_custom('Hello-1', 'world')?
|
||||
h.add_custom('Hello-21', 'world')?
|
||||
assert h.starting_with('Hello-')? == 'Hello-1'
|
||||
assert h.starting_with('Hello-2')? == 'Hello-21'
|
||||
}
|
||||
|
||||
fn test_custom_values() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('Hello', 'world') ?
|
||||
h.add_custom('Hello', 'world')?
|
||||
assert h.custom_values('hello') == ['world']
|
||||
assert h.custom_values('HELLO') == ['world']
|
||||
assert h.custom_values('Hello', exact: true) == ['world']
|
||||
@ -135,7 +135,7 @@ fn test_custom_values() ? {
|
||||
|
||||
fn test_coerce() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo') ?
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add(.accept, 'bar')
|
||||
assert h.values(.accept) == ['foo', 'bar']
|
||||
assert h.keys().len == 2
|
||||
@ -147,7 +147,7 @@ fn test_coerce() ? {
|
||||
|
||||
fn test_coerce_canonicalize() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo') ?
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add(.accept, 'bar')
|
||||
assert h.values(.accept) == ['foo', 'bar']
|
||||
assert h.keys().len == 2
|
||||
@ -159,9 +159,9 @@ fn test_coerce_canonicalize() ? {
|
||||
|
||||
fn test_coerce_custom() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('Hello', 'foo') ?
|
||||
h.add_custom('hello', 'bar') ?
|
||||
h.add_custom('HELLO', 'baz') ?
|
||||
h.add_custom('Hello', 'foo')?
|
||||
h.add_custom('hello', 'bar')?
|
||||
h.add_custom('HELLO', 'baz')?
|
||||
assert h.custom_values('hello') == ['foo', 'bar', 'baz']
|
||||
assert h.keys().len == 3
|
||||
|
||||
@ -172,8 +172,8 @@ fn test_coerce_custom() ? {
|
||||
|
||||
fn test_coerce_canonicalize_custom() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('foo-BAR', 'foo') ?
|
||||
h.add_custom('FOO-bar', 'bar') ?
|
||||
h.add_custom('foo-BAR', 'foo')?
|
||||
h.add_custom('FOO-bar', 'bar')?
|
||||
assert h.custom_values('foo-bar') == ['foo', 'bar']
|
||||
assert h.keys().len == 2
|
||||
|
||||
@ -184,8 +184,8 @@ fn test_coerce_canonicalize_custom() ? {
|
||||
|
||||
fn test_render_version() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo') ?
|
||||
h.add_custom('Accept', 'bar') ?
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add_custom('Accept', 'bar')?
|
||||
h.add(.accept, 'baz')
|
||||
|
||||
s1_0 := h.render(version: .v1_0)
|
||||
@ -206,8 +206,8 @@ fn test_render_version() ? {
|
||||
|
||||
fn test_render_coerce() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo') ?
|
||||
h.add_custom('Accept', 'bar') ?
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add_custom('Accept', 'bar')?
|
||||
h.add(.accept, 'baz')
|
||||
h.add(.host, 'host')
|
||||
|
||||
@ -232,8 +232,8 @@ fn test_render_coerce() ? {
|
||||
|
||||
fn test_render_canonicalize() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo') ?
|
||||
h.add_custom('Accept', 'bar') ?
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add_custom('Accept', 'bar')?
|
||||
h.add(.accept, 'baz')
|
||||
h.add(.host, 'host')
|
||||
|
||||
@ -258,8 +258,8 @@ fn test_render_canonicalize() ? {
|
||||
|
||||
fn test_render_coerce_canonicalize() ? {
|
||||
mut h := new_header()
|
||||
h.add_custom('accept', 'foo') ?
|
||||
h.add_custom('Accept', 'bar') ?
|
||||
h.add_custom('accept', 'foo')?
|
||||
h.add_custom('Accept', 'bar')?
|
||||
h.add(.accept, 'baz')
|
||||
h.add(.host, 'host')
|
||||
|
||||
@ -285,8 +285,8 @@ fn test_render_coerce_canonicalize() ? {
|
||||
fn test_str() ? {
|
||||
mut h := new_header()
|
||||
h.add(.accept, 'text/html')
|
||||
h.add_custom('Accept', 'image/jpeg') ?
|
||||
h.add_custom('X-custom', 'Hello') ?
|
||||
h.add_custom('Accept', 'image/jpeg')?
|
||||
h.add_custom('X-custom', 'Hello')?
|
||||
|
||||
// key order is not guaranteed
|
||||
assert h.str() == 'Accept: text/html\r\nAccept: image/jpeg\r\nX-custom: Hello\r\n'
|
||||
@ -308,7 +308,7 @@ fn test_custom_header_from_map() ? {
|
||||
h := new_custom_header_from_map({
|
||||
'Server': 'VWeb'
|
||||
'foo': 'bar'
|
||||
}) ?
|
||||
})?
|
||||
assert h.contains_custom('server')
|
||||
assert h.contains_custom('foo')
|
||||
assert h.get_custom('server') or { '' } == 'VWeb'
|
||||
@ -323,7 +323,7 @@ fn test_header_join() ? {
|
||||
h2 := new_custom_header_from_map({
|
||||
'Server': 'VWeb'
|
||||
'foo': 'bar'
|
||||
}) ?
|
||||
})?
|
||||
h3 := h1.join(h2)
|
||||
// h1 is unchanged
|
||||
assert h1.contains(.accept)
|
||||
@ -343,35 +343,35 @@ fn test_header_join() ? {
|
||||
}
|
||||
|
||||
fn parse_headers_test(s string, expected map[string]string) ? {
|
||||
assert parse_headers(s) ? == new_custom_header_from_map(expected) ?
|
||||
assert parse_headers(s)? == new_custom_header_from_map(expected)?
|
||||
}
|
||||
|
||||
fn test_parse_headers() ? {
|
||||
parse_headers_test('foo: bar', {
|
||||
'foo': 'bar'
|
||||
}) ?
|
||||
})?
|
||||
parse_headers_test('foo: \t bar', {
|
||||
'foo': 'bar'
|
||||
}) ?
|
||||
})?
|
||||
parse_headers_test('foo: bar\r\n\tbaz', {
|
||||
'foo': 'bar baz'
|
||||
}) ?
|
||||
})?
|
||||
parse_headers_test('foo: bar \r\n\tbaz\r\n buzz', {
|
||||
'foo': 'bar baz buzz'
|
||||
}) ?
|
||||
})?
|
||||
parse_headers_test('foo: bar\r\nbar:baz', {
|
||||
'foo': 'bar'
|
||||
'bar': 'baz'
|
||||
}) ?
|
||||
})?
|
||||
parse_headers_test('foo: bar\r\nbar:baz\r\n', {
|
||||
'foo': 'bar'
|
||||
'bar': 'baz'
|
||||
}) ?
|
||||
})?
|
||||
parse_headers_test('foo: bar\r\nbar:baz\r\n\r\n', {
|
||||
'foo': 'bar'
|
||||
'bar': 'baz'
|
||||
}) ?
|
||||
assert parse_headers('foo: bar\r\nfoo:baz') ?.custom_values('foo') == ['bar', 'baz']
|
||||
})?
|
||||
assert parse_headers('foo: bar\r\nfoo:baz')?.custom_values('foo') == ['bar', 'baz']
|
||||
|
||||
if x := parse_headers(' oops: oh no') {
|
||||
return error('should have errored, but got $x')
|
||||
|
Reference in New Issue
Block a user