test: expand testing to ints

main
Jef Roosens 2022-12-28 18:57:10 +01:00
parent 8bd7ce0b60
commit a1ab5d55b3
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
8 changed files with 188 additions and 52 deletions

View File

@ -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<SimpleConf>(default_path: 'test/test_simple.toml')!
assert conf == SimpleConf{
some_int: 2
some_string: 'hi'
}
}
fn test_zeroed() {
conf := load<SimpleConf>(default_path: 'test/test_zeroed.toml')!
assert conf == SimpleConf{
some_int: 0
some_string: ''
}
}
fn test_zeroed_defaults() {
conf := load<SimpleConfDefaults>(default_path: 'test/test_zeroed.toml')!
assert conf == SimpleConfDefaults{
some_int: 0
some_string: ''
}
}
fn test_defaults() {
conf := load<SimpleConfDefaults>(default_path: 'test/test_single_value.toml')!
assert conf == SimpleConfDefaults{
some_int: 3
some_string: 'hi'
}
}

183
int_test.v 100644
View File

@ -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<SingleConf>(default_path: 'test/int.toml')!
assert conf == SingleConf{
some_int: 1
}
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<SingleConf>(
default_path: 'test/int.toml'
env: {
'SOME_INT': '3'
}
)!
assert conf == SingleConf{
some_int: 3
}
conf = load<SingleConf>(
default_path: 'test/int.toml'
env: {
'SOME_INT': ''
}
)!
assert conf == SingleConf{
some_int: 0
}
conf = load<SingleConf>(
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<SingleConf>(default_path: 'test/empty.toml') or { return }
assert false
}
fn test_int_absent_no_default_env() {
mut conf := load<SingleConf>(
default_path: 'test/int.toml'
env: {
'SOME_INT': '3'
}
)!
assert conf == SingleConf{
some_int: 3
}
conf = load<SingleConf>(
default_path: 'test/int.toml'
env: {
'SOME_INT': ''
}
)!
assert conf == SingleConf{
some_int: 0
}
conf = load<SingleConf>(
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<SingleConfDefault>(default_path: 'test/int.toml')!
assert conf == SingleConfDefault{
some_int: 1
}
}
fn test_int_present_default_env() {
mut conf := load<SingleConfDefault>(
default_path: 'test/int.toml'
env: {
'SOME_INT': '3'
}
)!
assert conf == SingleConfDefault{
some_int: 3
}
conf = load<SingleConfDefault>(
default_path: 'test/int.toml'
env: {
'SOME_INT': ''
}
)!
assert conf == SingleConfDefault{
some_int: 0
}
conf = load<SingleConfDefault>(
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<SingleConfDefault>(default_path: 'test/empty.toml')!
assert conf == SingleConfDefault{
some_int: 2
}
}
fn test_int_absent_default_env() {
mut conf := load<SingleConfDefault>(
default_path: 'test/empty.toml'
env: {
'SOME_INT': '3'
}
)!
assert conf == SingleConfDefault{
some_int: 3
}
conf = load<SingleConfDefault>(
default_path: 'test/empty.toml'
env: {
'SOME_INT': ''
}
)!
assert conf == SingleConfDefault{
some_int: 0
}
conf = load<SingleConfDefault>(
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<SingleConfDefaultEmpty>(default_path: 'test/empty.toml')!
assert conf == SingleConfDefaultEmpty{
some_int: 0
}
}

View File

@ -9,13 +9,13 @@ struct SingleConfDefault {
} }
fn test_string_present_no_default() { fn test_string_present_no_default() {
conf := load<SingleConf>(default_path: 'test/string.toml')! mut conf := load<SingleConf>(default_path: 'test/string.toml')!
assert conf == SingleConf{ assert conf == SingleConf{
some_string: 'hi' some_string: 'hi'
} }
conf2 := load<SingleConf>(default_path: 'test/string_empty.toml')! conf = load<SingleConf>(default_path: 'test/string_empty.toml')!
assert conf2 == SingleConf{ assert conf == SingleConf{
some_string: '' some_string: ''
} }
} }

View File

@ -1 +1 @@
some_int = "hi" some_int = 1

View File

@ -0,0 +1 @@
some_int = 0

View File

@ -1,2 +0,0 @@
some_int = 2
some_string = "hi"

View File

@ -1 +0,0 @@
some_string = "hi"

View File

@ -1,2 +0,0 @@
some_int = 0
some_string = ""