From 3a4b4b334e21626315c67c993cff0bd06e9260a1 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Wed, 8 Feb 2023 10:40:37 +0100 Subject: [PATCH] chore: ran v fmt for V 0.3.3 changes --- bool_test.v | 32 ++++++++++++++++---------------- conf.v | 16 ++++++++-------- conf_test.v | 2 +- int_test.v | 36 ++++++++++++++++++------------------ string_test.v | 36 ++++++++++++++++++------------------ 5 files changed, 61 insertions(+), 61 deletions(-) diff --git a/bool_test.v b/bool_test.v index 1418bde..2f760e2 100644 --- a/bool_test.v +++ b/bool_test.v @@ -13,14 +13,14 @@ struct SingleConfDefaultTrue { } fn test_bool_present_no_default() { - mut conf := load(default_path: 'test/bool.toml')! + 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( + mut conf_f := load[SingleConfDefaultFalse]( default_path: 'test/bool.toml' env: { 'SOME_BOOL': '1' @@ -30,7 +30,7 @@ fn test_bool_present_no_default_env() { some_bool: true } - mut conf_t := load( + mut conf_t := load[SingleConfDefaultTrue]( default_path: 'test/bool.toml' env: { 'SOME_BOOL': '' @@ -40,7 +40,7 @@ fn test_bool_present_no_default_env() { some_bool: false } - conf_f = load( + conf_f = load[SingleConfDefaultFalse]( default_path: 'test/bool.toml' env: { 'TEST_SOME_BOOL': 'true' @@ -53,12 +53,12 @@ fn test_bool_present_no_default_env() { } fn test_bool_absent_no_default() { - conf := load(default_path: 'test/empty.toml') or { return } + conf := load[SingleConf](default_path: 'test/empty.toml') or { return } assert false } fn test_bool_absent_no_default_env() { - mut conf_f := load( + mut conf_f := load[SingleConfDefaultFalse]( default_path: 'test/bool.toml' env: { 'SOME_BOOL': '1' @@ -68,7 +68,7 @@ fn test_bool_absent_no_default_env() { some_bool: true } - mut conf_t := load( + mut conf_t := load[SingleConfDefaultTrue]( default_path: 'test/bool.toml' env: { 'SOME_BOOL': '' @@ -78,7 +78,7 @@ fn test_bool_absent_no_default_env() { some_bool: false } - conf_f = load( + conf_f = load[SingleConfDefaultFalse]( default_path: 'test/bool.toml' env: { 'TEST_SOME_BOOL': '1' @@ -91,14 +91,14 @@ fn test_bool_absent_no_default_env() { } fn test_bool_present_default() { - conf := load(default_path: 'test/bool.toml')! + conf := load[SingleConfDefaultFalse](default_path: 'test/bool.toml')! assert conf == SingleConfDefaultFalse{ some_bool: true } } fn test_bool_present_default_env() { - mut conf_f := load( + mut conf_f := load[SingleConfDefaultFalse]( default_path: 'test/bool.toml' env: { 'SOME_BOOL': '1' @@ -108,7 +108,7 @@ fn test_bool_present_default_env() { some_bool: true } - mut conf_t := load( + mut conf_t := load[SingleConfDefaultTrue]( default_path: 'test/bool.toml' env: { 'SOME_BOOL': '' @@ -118,7 +118,7 @@ fn test_bool_present_default_env() { some_bool: false } - conf_f = load( + conf_f = load[SingleConfDefaultFalse]( default_path: 'test/bool.toml' env: { 'TEST_SOME_BOOL': '1' @@ -131,14 +131,14 @@ fn test_bool_present_default_env() { } fn test_bool_absent_default() { - conf := load(default_path: 'test/empty.toml')! + conf := load[SingleConfDefaultTrue](default_path: 'test/empty.toml')! assert conf == SingleConfDefaultTrue{ some_bool: true } } fn test_bool_absent_default_env() { - mut conf_f := load( + mut conf_f := load[SingleConfDefaultFalse]( default_path: 'test/empty.toml' env: { 'SOME_BOOL': '1' @@ -148,7 +148,7 @@ fn test_bool_absent_default_env() { some_bool: true } - mut conf_t := load( + mut conf_t := load[SingleConfDefaultTrue]( default_path: 'test/empty.toml' env: { 'SOME_BOOL': '' @@ -158,7 +158,7 @@ fn test_bool_absent_default_env() { some_bool: false } - conf_f = load( + conf_f = load[SingleConfDefaultFalse]( default_path: 'test/empty.toml' env: { 'TEST_SOME_BOOL': 'true' diff --git a/conf.v b/conf.v index cf2405e..dfdf3d4 100644 --- a/conf.v +++ b/conf.v @@ -20,8 +20,8 @@ pub struct LoadConfig { // function returns an error. It returns two values, with the first indicating // whether the env vars were actually present. fn (ld LoadConfig) get_env_var(field_name string) !(bool, string) { - env_var_name := '$ld.prefix$field_name.to_upper()' - env_file_name := '$ld.prefix$field_name.to_upper()$ld.file_suffix' + env_var_name := '${ld.prefix}${field_name.to_upper()}' + env_file_name := '${ld.prefix}${field_name.to_upper()}${ld.file_suffix}' if env_var_name !in ld.env && env_file_name !in ld.env { return false, '' @@ -29,7 +29,7 @@ fn (ld LoadConfig) get_env_var(field_name string) !(bool, string) { // If they're both set, we report a conflict if env_var_name in ld.env && env_file_name in ld.env { - return error('Only one of $env_var_name or $env_file_name can be defined.') + return error('Only one of ${env_var_name} or ${env_file_name} can be defined.') } // If it's the env var itself, we return it. @@ -42,7 +42,7 @@ fn (ld LoadConfig) get_env_var(field_name string) !(bool, string) { // Otherwise, we process the file return true, os.read_file(ld.env[env_file_name]) or { - error('Failed to read file defined in $env_file_name: ${err.msg()}.') + error('Failed to read file defined in ${env_file_name}: ${err.msg()}.') } } @@ -50,7 +50,7 @@ fn (ld LoadConfig) get_env_var(field_name string) !(bool, string) { // file & environment variables. For each field, it will select either a value // given from an environment variable, a value defined in the config file or a // configured default if present, in that order. -pub fn load(ld LoadConfig) !T { +pub fn load[T](ld LoadConfig) !T { // Ensure all struct fields consist of supported types $for field in T.fields { $if field.typ is string || field.typ is int || field.typ is bool { @@ -59,14 +59,14 @@ pub fn load(ld LoadConfig) !T { // this seems to be bugged. If I replace this call with a // $compile_error call, the error *always* happens, even if all // fields are correct. - return error('Field $field.name is of an unsupported type.') + return error('Field ${field.name} is of an unsupported type.') } } mut res := T{} // This array allows us to determine later whether the variable is actually // zero or just a null'ed struct field - mut has_value := Set{} + mut has_value := Set[string]{} // Later, this could be read from an env var as well. path := ld.default_path @@ -138,7 +138,7 @@ pub fn load(ld LoadConfig) !T { // If there's no value provided in any way, we notify the user with an // error. if !has_value.exists(field.name) { - return error("Missing config variable '$field.name' with no provided default. Either add it to the config file or provide it using an environment variable.") + return error("Missing config variable '${field.name}' with no provided default. Either add it to the config file or provide it using an environment variable.") } } return res diff --git a/conf_test.v b/conf_test.v index 4877724..255d591 100644 --- a/conf_test.v +++ b/conf_test.v @@ -5,6 +5,6 @@ struct WrongTypeConfig { } fn test_wrong_type() { - conf := load() or { return } + conf := load[WrongTypeConfig]() or { return } assert false } diff --git a/int_test.v b/int_test.v index defddc8..88ddd3f 100644 --- a/int_test.v +++ b/int_test.v @@ -9,19 +9,19 @@ struct SingleConfDefault { } fn test_int_present_no_default() { - mut conf := load(default_path: 'test/int.toml')! + mut conf := load[SingleConf](default_path: 'test/int.toml')! assert conf == SingleConf{ some_int: 1 } - conf = load(default_path: 'test/int_zero.toml')! + conf = load[SingleConf](default_path: 'test/int_zero.toml')! assert conf == SingleConf{ some_int: 0 } } fn test_int_present_no_default_env() { - mut conf := load( + mut conf := load[SingleConf]( default_path: 'test/int.toml' env: { 'SOME_INT': '3' @@ -31,7 +31,7 @@ fn test_int_present_no_default_env() { some_int: 3 } - conf = load( + conf = load[SingleConf]( default_path: 'test/int.toml' env: { 'SOME_INT': '' @@ -41,7 +41,7 @@ fn test_int_present_no_default_env() { some_int: 0 } - conf = load( + conf = load[SingleConf]( default_path: 'test/int.toml' env: { 'TEST_SOME_INT': '3' @@ -54,12 +54,12 @@ fn test_int_present_no_default_env() { } fn test_int_absent_no_default() { - conf := load(default_path: 'test/empty.toml') or { return } + conf := load[SingleConf](default_path: 'test/empty.toml') or { return } assert false } fn test_int_absent_no_default_env() { - mut conf := load( + mut conf := load[SingleConf]( default_path: 'test/int.toml' env: { 'SOME_INT': '3' @@ -69,7 +69,7 @@ fn test_int_absent_no_default_env() { some_int: 3 } - conf = load( + conf = load[SingleConf]( default_path: 'test/int.toml' env: { 'SOME_INT': '' @@ -79,7 +79,7 @@ fn test_int_absent_no_default_env() { some_int: 0 } - conf = load( + conf = load[SingleConf]( default_path: 'test/int.toml' env: { 'TEST_SOME_INT': '3' @@ -92,14 +92,14 @@ fn test_int_absent_no_default_env() { } fn test_int_present_default() { - conf := load(default_path: 'test/int.toml')! + conf := load[SingleConfDefault](default_path: 'test/int.toml')! assert conf == SingleConfDefault{ some_int: 1 } } fn test_int_present_default_env() { - mut conf := load( + mut conf := load[SingleConfDefault]( default_path: 'test/int.toml' env: { 'SOME_INT': '3' @@ -109,7 +109,7 @@ fn test_int_present_default_env() { some_int: 3 } - conf = load( + conf = load[SingleConfDefault]( default_path: 'test/int.toml' env: { 'SOME_INT': '' @@ -119,7 +119,7 @@ fn test_int_present_default_env() { some_int: 0 } - conf = load( + conf = load[SingleConfDefault]( default_path: 'test/int.toml' env: { 'TEST_SOME_INT': '3' @@ -132,14 +132,14 @@ fn test_int_present_default_env() { } fn test_int_absent_default() { - conf := load(default_path: 'test/empty.toml')! + conf := load[SingleConfDefault](default_path: 'test/empty.toml')! assert conf == SingleConfDefault{ some_int: 2 } } fn test_int_absent_default_env() { - mut conf := load( + mut conf := load[SingleConfDefault]( default_path: 'test/empty.toml' env: { 'SOME_INT': '3' @@ -149,7 +149,7 @@ fn test_int_absent_default_env() { some_int: 3 } - conf = load( + conf = load[SingleConfDefault]( default_path: 'test/empty.toml' env: { 'SOME_INT': '' @@ -159,7 +159,7 @@ fn test_int_absent_default_env() { some_int: 0 } - conf = load( + conf = load[SingleConfDefault]( default_path: 'test/empty.toml' env: { 'TEST_SOME_INT': '3' @@ -176,7 +176,7 @@ struct SingleConfDefaultEmpty { } fn test_int_absent_default_empty() { - conf := load(default_path: 'test/empty.toml')! + conf := load[SingleConfDefaultEmpty](default_path: 'test/empty.toml')! assert conf == SingleConfDefaultEmpty{ some_int: 0 } diff --git a/string_test.v b/string_test.v index 9c7a6a9..18e1034 100644 --- a/string_test.v +++ b/string_test.v @@ -9,19 +9,19 @@ struct SingleConfDefault { } fn test_string_present_no_default() { - mut conf := load(default_path: 'test/string.toml')! + mut conf := load[SingleConf](default_path: 'test/string.toml')! assert conf == SingleConf{ some_string: 'hi' } - conf = load(default_path: 'test/string_empty.toml')! + conf = load[SingleConf](default_path: 'test/string_empty.toml')! assert conf == SingleConf{ some_string: '' } } fn test_string_present_no_default_env() { - mut conf := load( + mut conf := load[SingleConf]( default_path: 'test/string.toml' env: { 'SOME_STRING': 'env' @@ -31,7 +31,7 @@ fn test_string_present_no_default_env() { some_string: 'env' } - conf = load( + conf = load[SingleConf]( default_path: 'test/string.toml' env: { 'SOME_STRING': '' @@ -41,7 +41,7 @@ fn test_string_present_no_default_env() { some_string: '' } - conf = load( + conf = load[SingleConf]( default_path: 'test/string.toml' env: { 'TEST_SOME_STRING': 'env' @@ -54,12 +54,12 @@ fn test_string_present_no_default_env() { } fn test_string_absent_no_default() { - conf := load(default_path: 'test/empty.toml') or { return } + conf := load[SingleConf](default_path: 'test/empty.toml') or { return } assert false } fn test_string_absent_no_default_env() { - mut conf := load( + mut conf := load[SingleConf]( default_path: 'test/string.toml' env: { 'SOME_STRING': 'env' @@ -69,7 +69,7 @@ fn test_string_absent_no_default_env() { some_string: 'env' } - conf = load( + conf = load[SingleConf]( default_path: 'test/string.toml' env: { 'SOME_STRING': '' @@ -79,7 +79,7 @@ fn test_string_absent_no_default_env() { some_string: '' } - conf = load( + conf = load[SingleConf]( default_path: 'test/string.toml' env: { 'TEST_SOME_STRING': 'env' @@ -92,14 +92,14 @@ fn test_string_absent_no_default_env() { } fn test_string_present_default() { - conf := load(default_path: 'test/string.toml')! + conf := load[SingleConfDefault](default_path: 'test/string.toml')! assert conf == SingleConfDefault{ some_string: 'hi' } } fn test_string_present_default_env() { - mut conf := load( + mut conf := load[SingleConfDefault]( default_path: 'test/string.toml' env: { 'SOME_STRING': 'env' @@ -109,7 +109,7 @@ fn test_string_present_default_env() { some_string: 'env' } - conf = load( + conf = load[SingleConfDefault]( default_path: 'test/string.toml' env: { 'SOME_STRING': '' @@ -119,7 +119,7 @@ fn test_string_present_default_env() { some_string: '' } - conf = load( + conf = load[SingleConfDefault]( default_path: 'test/string.toml' env: { 'TEST_SOME_STRING': 'env' @@ -132,14 +132,14 @@ fn test_string_present_default_env() { } fn test_string_absent_default() { - conf := load(default_path: 'test/empty.toml')! + conf := load[SingleConfDefault](default_path: 'test/empty.toml')! assert conf == SingleConfDefault{ some_string: 'default' } } fn test_string_absent_default_env() { - mut conf := load( + mut conf := load[SingleConfDefault]( default_path: 'test/empty.toml' env: { 'SOME_STRING': 'env' @@ -149,7 +149,7 @@ fn test_string_absent_default_env() { some_string: 'env' } - conf = load( + conf = load[SingleConfDefault]( default_path: 'test/empty.toml' env: { 'SOME_STRING': '' @@ -159,7 +159,7 @@ fn test_string_absent_default_env() { some_string: '' } - conf = load( + conf = load[SingleConfDefault]( default_path: 'test/empty.toml' env: { 'TEST_SOME_STRING': 'env' @@ -176,7 +176,7 @@ struct SingleConfDefaultEmpty { } fn test_string_absent_default_empty() { - conf := load(default_path: 'test/empty.toml')! + conf := load[SingleConfDefaultEmpty](default_path: 'test/empty.toml')! assert conf == SingleConfDefaultEmpty{ some_string: '' }