2022-02-13 16:06:00 +03:00
|
|
|
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
module urllib
|
|
|
|
|
2023-03-14 09:44:40 +03:00
|
|
|
fn test_add_and_get_key_val() {
|
2022-02-13 16:06:00 +03:00
|
|
|
mut values := Values{}
|
|
|
|
values.add('key', 'value')
|
2023-03-14 09:44:40 +03:00
|
|
|
present_val := values.get('key') or { '' }
|
|
|
|
absent_val := values.get('key1') or { '' }
|
|
|
|
assert present_val == 'value'
|
|
|
|
assert absent_val == ''
|
2022-02-13 16:06:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_get_all_with_key() {
|
|
|
|
mut values := Values{}
|
|
|
|
values.add('key', 'value1')
|
|
|
|
values.add('key', 'value2')
|
|
|
|
key_values := values.get_all('key')
|
|
|
|
assert key_values == ['value1', 'value2']
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_set_with_key() {
|
|
|
|
mut values := Values{}
|
|
|
|
values.add('key', 'value1')
|
|
|
|
values.add('key', 'value2')
|
|
|
|
values.add('key1', 'value2')
|
|
|
|
values.set('key1', 'vlang')
|
|
|
|
key_values := values.get_all('key')
|
|
|
|
key2_values := values.get_all('key1')
|
|
|
|
assert key_values == ['value1', 'value2']
|
|
|
|
assert key2_values == ['vlang']
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_set_missing_key() {
|
|
|
|
mut values := Values{}
|
|
|
|
values.set('err', 'err1')
|
|
|
|
vals := values.get_all('err')
|
|
|
|
assert vals == ['err1']
|
|
|
|
}
|