diff --git a/conf_test.v b/conf_test.v deleted file mode 100644 index 72e7703..0000000 --- a/conf_test.v +++ /dev/null @@ -1,43 +0,0 @@ -module conf - -struct SimpleConf { - some_int int - some_string string -} - -struct SimpleConfDefaults { - some_int int = 3 - some_string string = 'hi' -} - -fn test_simple() { - conf := load(default_path: 'test/test_simple.toml')! - assert conf == SimpleConf{ - some_int: 2 - some_string: 'hi' - } -} - -fn test_zeroed() { - conf := load(default_path: 'test/test_zeroed.toml')! - assert conf == SimpleConf{ - some_int: 0 - some_string: '' - } -} - -fn test_zeroed_defaults() { - conf := load(default_path: 'test/test_zeroed.toml')! - assert conf == SimpleConfDefaults{ - some_int: 0 - some_string: '' - } -} - -fn test_defaults() { - conf := load(default_path: 'test/test_single_value.toml')! - assert conf == SimpleConfDefaults{ - some_int: 3 - some_string: 'hi' - } -} diff --git a/int_test.v b/int_test.v new file mode 100644 index 0000000..e248319 --- /dev/null +++ b/int_test.v @@ -0,0 +1,183 @@ +module conf + +struct SingleConf { + some_int int +} + +struct SingleConfDefault { + some_int int = 2 +} + +fn test_int_present_no_default() { + mut conf := load(default_path: 'test/int.toml')! + assert conf == SingleConf{ + some_int: 1 + } + + conf = load(default_path: 'test/int_zero.toml')! + assert conf == SingleConf{ + some_int: 0 + } +} + +fn test_int_present_no_default_env() { + mut conf := load( + default_path: 'test/int.toml' + env: { + 'SOME_INT': '3' + } + )! + assert conf == SingleConf{ + some_int: 3 + } + + conf = load( + default_path: 'test/int.toml' + env: { + 'SOME_INT': '' + } + )! + assert conf == SingleConf{ + some_int: 0 + } + + conf = load( + default_path: 'test/int.toml' + env: { + 'TEST_SOME_INT': '3' + } + prefix: 'TEST_' + )! + assert conf == SingleConf{ + some_int: 3 + } +} + +fn test_int_absent_no_default() { + conf := load(default_path: 'test/empty.toml') or { return } + assert false +} + +fn test_int_absent_no_default_env() { + mut conf := load( + default_path: 'test/int.toml' + env: { + 'SOME_INT': '3' + } + )! + assert conf == SingleConf{ + some_int: 3 + } + + conf = load( + default_path: 'test/int.toml' + env: { + 'SOME_INT': '' + } + )! + assert conf == SingleConf{ + some_int: 0 + } + + conf = load( + default_path: 'test/int.toml' + env: { + 'TEST_SOME_INT': '3' + } + prefix: 'TEST_' + )! + assert conf == SingleConf{ + some_int: 3 + } +} + +fn test_int_present_default() { + conf := load(default_path: 'test/int.toml')! + assert conf == SingleConfDefault{ + some_int: 1 + } +} + +fn test_int_present_default_env() { + mut conf := load( + default_path: 'test/int.toml' + env: { + 'SOME_INT': '3' + } + )! + assert conf == SingleConfDefault{ + some_int: 3 + } + + conf = load( + default_path: 'test/int.toml' + env: { + 'SOME_INT': '' + } + )! + assert conf == SingleConfDefault{ + some_int: 0 + } + + conf = load( + default_path: 'test/int.toml' + env: { + 'TEST_SOME_INT': '3' + } + prefix: 'TEST_' + )! + assert conf == SingleConfDefault{ + some_int: 3 + } +} + +fn test_int_absent_default() { + conf := load(default_path: 'test/empty.toml')! + assert conf == SingleConfDefault{ + some_int: 2 + } +} + +fn test_int_absent_default_env() { + mut conf := load( + default_path: 'test/empty.toml' + env: { + 'SOME_INT': '3' + } + )! + assert conf == SingleConfDefault{ + some_int: 3 + } + + conf = load( + default_path: 'test/empty.toml' + env: { + 'SOME_INT': '' + } + )! + assert conf == SingleConfDefault{ + some_int: 0 + } + + conf = load( + default_path: 'test/empty.toml' + env: { + 'TEST_SOME_INT': '3' + } + prefix: 'TEST_' + )! + assert conf == SingleConfDefault{ + some_int: 3 + } +} + +struct SingleConfDefaultEmpty { + some_int int [empty_default] +} + +fn test_int_absent_default_empty() { + conf := load(default_path: 'test/empty.toml')! + assert conf == SingleConfDefaultEmpty{ + some_int: 0 + } +} diff --git a/string_test.v b/string_test.v index 9dfc191..9c7a6a9 100644 --- a/string_test.v +++ b/string_test.v @@ -9,13 +9,13 @@ struct SingleConfDefault { } fn test_string_present_no_default() { - conf := load(default_path: 'test/string.toml')! + mut conf := load(default_path: 'test/string.toml')! assert conf == SingleConf{ some_string: 'hi' } - conf2 := load(default_path: 'test/string_empty.toml')! - assert conf2 == SingleConf{ + conf = load(default_path: 'test/string_empty.toml')! + assert conf == SingleConf{ some_string: '' } } diff --git a/test/int.toml b/test/int.toml index 263b0ce..b8326e0 100644 --- a/test/int.toml +++ b/test/int.toml @@ -1 +1 @@ -some_int = "hi" +some_int = 1 diff --git a/test/int_zero.toml b/test/int_zero.toml new file mode 100644 index 0000000..4dd4d46 --- /dev/null +++ b/test/int_zero.toml @@ -0,0 +1 @@ +some_int = 0 diff --git a/test/test_simple.toml b/test/test_simple.toml deleted file mode 100644 index 489eea3..0000000 --- a/test/test_simple.toml +++ /dev/null @@ -1,2 +0,0 @@ -some_int = 2 -some_string = "hi" diff --git a/test/test_single_value.toml b/test/test_single_value.toml deleted file mode 100644 index 85c27d0..0000000 --- a/test/test_single_value.toml +++ /dev/null @@ -1 +0,0 @@ -some_string = "hi" diff --git a/test/test_zeroed.toml b/test/test_zeroed.toml deleted file mode 100644 index ce4dd51..0000000 --- a/test/test_zeroed.toml +++ /dev/null @@ -1,2 +0,0 @@ -some_int = 0 -some_string = ""