diff --git a/conf.v b/conf.v index fdd0a6e..c3865ca 100644 --- a/conf.v +++ b/conf.v @@ -72,8 +72,9 @@ pub fn load(conf LoadConfig) !T { res.$(field.name) = s.string() } $else $if field.typ is int { res.$(field.name) = s.int() - } $else { - $compile_error('Unsupported config struct field type detected.') + // This seems to not work in V 0.3.2 + //} $else { + // $compile_error('Unsupported config struct field type detected.') } has_value[field.name] = true @@ -91,8 +92,9 @@ pub fn load(conf LoadConfig) !T { res.$(field.name) = env_value } $else $if field.typ is int { res.$(field.name) = env_value.int() - } $else { - $compile_error('Unsupported config struct field type detected.') + // This seems to not work in V 0.3.2 + //} $else { + // $compile_error('Unsupported config struct field type detected.') } has_value[field.name] = true diff --git a/conf_test.v b/conf_test.v new file mode 100644 index 0000000..72e7703 --- /dev/null +++ b/conf_test.v @@ -0,0 +1,43 @@ +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/test/test_simple.toml b/test/test_simple.toml new file mode 100644 index 0000000..489eea3 --- /dev/null +++ b/test/test_simple.toml @@ -0,0 +1,2 @@ +some_int = 2 +some_string = "hi" diff --git a/test/test_single_value.toml b/test/test_single_value.toml new file mode 100644 index 0000000..85c27d0 --- /dev/null +++ b/test/test_single_value.toml @@ -0,0 +1 @@ +some_string = "hi" diff --git a/test/test_zeroed.toml b/test/test_zeroed.toml new file mode 100644 index 0000000..ce4dd51 --- /dev/null +++ b/test/test_zeroed.toml @@ -0,0 +1,2 @@ +some_int = 0 +some_string = ""