172 lines
3.1 KiB
V
172 lines
3.1 KiB
V
module conf
|
|
|
|
struct SingleConf {
|
|
some_bool bool
|
|
}
|
|
|
|
struct SingleConfDefaultFalse {
|
|
some_bool bool [empty_default]
|
|
}
|
|
|
|
struct SingleConfDefaultTrue {
|
|
some_bool bool = true
|
|
}
|
|
|
|
fn test_bool_present_no_default() {
|
|
mut conf := load[SingleConf](default_path: 'test/bool.toml')!
|
|
assert conf == SingleConf{
|
|
some_bool: true
|
|
}
|
|
}
|
|
|
|
fn test_bool_present_no_default_env() {
|
|
mut conf_f := load[SingleConfDefaultFalse](
|
|
default_path: 'test/bool.toml'
|
|
env: {
|
|
'SOME_BOOL': '1'
|
|
}
|
|
)!
|
|
assert conf_f == SingleConfDefaultFalse{
|
|
some_bool: true
|
|
}
|
|
|
|
mut conf_t := load[SingleConfDefaultTrue](
|
|
default_path: 'test/bool.toml'
|
|
env: {
|
|
'SOME_BOOL': ''
|
|
}
|
|
)!
|
|
assert conf_t == SingleConfDefaultTrue{
|
|
some_bool: false
|
|
}
|
|
|
|
conf_f = load[SingleConfDefaultFalse](
|
|
default_path: 'test/bool.toml'
|
|
env: {
|
|
'TEST_SOME_BOOL': 'true'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf_f == SingleConfDefaultFalse{
|
|
some_bool: true
|
|
}
|
|
}
|
|
|
|
fn test_bool_absent_no_default() {
|
|
conf := load[SingleConf](default_path: 'test/empty.toml') or { return }
|
|
assert false
|
|
}
|
|
|
|
fn test_bool_absent_no_default_env() {
|
|
mut conf_f := load[SingleConfDefaultFalse](
|
|
default_path: 'test/bool.toml'
|
|
env: {
|
|
'SOME_BOOL': '1'
|
|
}
|
|
)!
|
|
assert conf_f == SingleConfDefaultFalse{
|
|
some_bool: true
|
|
}
|
|
|
|
mut conf_t := load[SingleConfDefaultTrue](
|
|
default_path: 'test/bool.toml'
|
|
env: {
|
|
'SOME_BOOL': ''
|
|
}
|
|
)!
|
|
assert conf_t == SingleConfDefaultTrue{
|
|
some_bool: false
|
|
}
|
|
|
|
conf_f = load[SingleConfDefaultFalse](
|
|
default_path: 'test/bool.toml'
|
|
env: {
|
|
'TEST_SOME_BOOL': '1'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf_f == SingleConfDefaultFalse{
|
|
some_bool: true
|
|
}
|
|
}
|
|
|
|
fn test_bool_present_default() {
|
|
conf := load[SingleConfDefaultFalse](default_path: 'test/bool.toml')!
|
|
assert conf == SingleConfDefaultFalse{
|
|
some_bool: true
|
|
}
|
|
}
|
|
|
|
fn test_bool_present_default_env() {
|
|
mut conf_f := load[SingleConfDefaultFalse](
|
|
default_path: 'test/bool.toml'
|
|
env: {
|
|
'SOME_BOOL': '1'
|
|
}
|
|
)!
|
|
assert conf_f == SingleConfDefaultFalse{
|
|
some_bool: true
|
|
}
|
|
|
|
mut conf_t := load[SingleConfDefaultTrue](
|
|
default_path: 'test/bool.toml'
|
|
env: {
|
|
'SOME_BOOL': ''
|
|
}
|
|
)!
|
|
assert conf_t == SingleConfDefaultTrue{
|
|
some_bool: false
|
|
}
|
|
|
|
conf_f = load[SingleConfDefaultFalse](
|
|
default_path: 'test/bool.toml'
|
|
env: {
|
|
'TEST_SOME_BOOL': '1'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf_f == SingleConfDefaultFalse{
|
|
some_bool: true
|
|
}
|
|
}
|
|
|
|
fn test_bool_absent_default() {
|
|
conf := load[SingleConfDefaultTrue](default_path: 'test/empty.toml')!
|
|
assert conf == SingleConfDefaultTrue{
|
|
some_bool: true
|
|
}
|
|
}
|
|
|
|
fn test_bool_absent_default_env() {
|
|
mut conf_f := load[SingleConfDefaultFalse](
|
|
default_path: 'test/empty.toml'
|
|
env: {
|
|
'SOME_BOOL': '1'
|
|
}
|
|
)!
|
|
assert conf_f == SingleConfDefaultFalse{
|
|
some_bool: true
|
|
}
|
|
|
|
mut conf_t := load[SingleConfDefaultTrue](
|
|
default_path: 'test/empty.toml'
|
|
env: {
|
|
'SOME_BOOL': ''
|
|
}
|
|
)!
|
|
assert conf_t == SingleConfDefaultTrue{
|
|
some_bool: false
|
|
}
|
|
|
|
conf_f = load[SingleConfDefaultFalse](
|
|
default_path: 'test/empty.toml'
|
|
env: {
|
|
'TEST_SOME_BOOL': 'true'
|
|
}
|
|
prefix: 'TEST_'
|
|
)!
|
|
assert conf_f == SingleConfDefaultFalse{
|
|
some_bool: true
|
|
}
|
|
}
|