conf/string_test.v

184 lines
3.2 KiB
Coq
Raw Normal View History

2022-12-28 17:39:20 +01:00
module conf
struct SingleConf {
some_string string
}
struct SingleConfDefault {
some_string string = 'default'
}
fn test_string_present_no_default() {
2023-02-08 10:40:37 +01:00
mut conf := load[SingleConf](default_path: 'test/string.toml')!
2022-12-28 17:39:20 +01:00
assert conf == SingleConf{
some_string: 'hi'
}
2023-02-08 10:40:37 +01:00
conf = load[SingleConf](default_path: 'test/string_empty.toml')!
2022-12-28 18:57:10 +01:00
assert conf == SingleConf{
some_string: ''
}
2022-12-28 17:39:20 +01:00
}
2022-12-28 18:13:20 +01:00
fn test_string_present_no_default_env() {
2023-02-08 10:40:37 +01:00
mut conf := load[SingleConf](
default_path: 'test/string.toml'
env: {
'SOME_STRING': 'env'
}
)!
2022-12-28 18:13:20 +01:00
assert conf == SingleConf{
some_string: 'env'
}
2023-02-08 10:40:37 +01:00
conf = load[SingleConf](
default_path: 'test/string.toml'
env: {
'SOME_STRING': ''
}
)!
assert conf == SingleConf{
some_string: ''
}
2023-02-08 10:40:37 +01:00
conf = load[SingleConf](
default_path: 'test/string.toml'
env: {
'TEST_SOME_STRING': 'env'
}
prefix: 'TEST_'
)!
assert conf == SingleConf{
2022-12-28 18:13:20 +01:00
some_string: 'env'
}
}
2022-12-28 17:39:20 +01:00
fn test_string_absent_no_default() {
2023-02-08 10:40:37 +01:00
conf := load[SingleConf](default_path: 'test/empty.toml') or { return }
2022-12-28 17:39:20 +01:00
assert false
}
2022-12-28 18:13:20 +01:00
fn test_string_absent_no_default_env() {
2023-02-08 10:40:37 +01:00
mut conf := load[SingleConf](
default_path: 'test/string.toml'
env: {
'SOME_STRING': 'env'
}
)!
2022-12-28 18:13:20 +01:00
assert conf == SingleConf{
some_string: 'env'
}
2023-02-08 10:40:37 +01:00
conf = load[SingleConf](
default_path: 'test/string.toml'
env: {
'SOME_STRING': ''
}
)!
assert conf == SingleConf{
some_string: ''
}
2023-02-08 10:40:37 +01:00
conf = load[SingleConf](
default_path: 'test/string.toml'
env: {
'TEST_SOME_STRING': 'env'
}
prefix: 'TEST_'
)!
assert conf == SingleConf{
2022-12-28 18:13:20 +01:00
some_string: 'env'
}
}
2022-12-28 17:39:20 +01:00
fn test_string_present_default() {
2023-02-08 10:40:37 +01:00
conf := load[SingleConfDefault](default_path: 'test/string.toml')!
2022-12-28 17:39:20 +01:00
assert conf == SingleConfDefault{
some_string: 'hi'
}
}
2022-12-28 18:13:20 +01:00
fn test_string_present_default_env() {
2023-02-08 10:40:37 +01:00
mut conf := load[SingleConfDefault](
default_path: 'test/string.toml'
env: {
'SOME_STRING': 'env'
}
)!
2022-12-28 18:13:20 +01:00
assert conf == SingleConfDefault{
some_string: 'env'
}
2023-02-08 10:40:37 +01:00
conf = load[SingleConfDefault](
2022-12-28 18:13:20 +01:00
default_path: 'test/string.toml'
env: {
'SOME_STRING': ''
}
)!
assert conf == SingleConfDefault{
some_string: ''
}
2023-02-08 10:40:37 +01:00
conf = load[SingleConfDefault](
default_path: 'test/string.toml'
env: {
'TEST_SOME_STRING': 'env'
}
2022-12-28 18:13:20 +01:00
prefix: 'TEST_'
)!
assert conf == SingleConfDefault{
2022-12-28 18:13:20 +01:00
some_string: 'env'
}
}
2022-12-28 17:39:20 +01:00
fn test_string_absent_default() {
2023-02-08 10:40:37 +01:00
conf := load[SingleConfDefault](default_path: 'test/empty.toml')!
2022-12-28 17:39:20 +01:00
assert conf == SingleConfDefault{
some_string: 'default'
}
}
2022-12-28 18:13:20 +01:00
fn test_string_absent_default_env() {
2023-02-08 10:40:37 +01:00
mut conf := load[SingleConfDefault](
default_path: 'test/empty.toml'
env: {
'SOME_STRING': 'env'
}
)!
2022-12-28 18:13:20 +01:00
assert conf == SingleConfDefault{
some_string: 'env'
}
2023-02-08 10:40:37 +01:00
conf = load[SingleConfDefault](
2022-12-28 18:13:20 +01:00
default_path: 'test/empty.toml'
env: {
'SOME_STRING': ''
}
)!
assert conf == SingleConfDefault{
some_string: ''
}
2023-02-08 10:40:37 +01:00
conf = load[SingleConfDefault](
default_path: 'test/empty.toml'
env: {
'TEST_SOME_STRING': 'env'
}
2022-12-28 18:13:20 +01:00
prefix: 'TEST_'
)!
assert conf == SingleConfDefault{
2022-12-28 18:13:20 +01:00
some_string: 'env'
}
}
struct SingleConfDefaultEmpty {
some_string string [empty_default]
}
fn test_string_absent_default_empty() {
2023-02-08 10:40:37 +01:00
conf := load[SingleConfDefaultEmpty](default_path: 'test/empty.toml')!
assert conf == SingleConfDefaultEmpty{
some_string: ''
}
}