Skip to content

Commit

Permalink
tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
axenteoctavian committed Jan 22, 2024
1 parent 883b421 commit 74037f1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 42 deletions.
43 changes: 3 additions & 40 deletions common/reflectcommon/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,13 @@ package reflectcommon
import "reflect"

func FitsWithinSignedIntegerRange(value reflect.Value, targetType reflect.Type) bool {
min, err := getMinInt(targetType)
if err != nil {
return false
}
max, err := getMaxInt(targetType)
if err != nil {
return false
}

switch value.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return value.Int() >= min && value.Int() <= max
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
return value.Uint() <= uint64(max)
}

return false
return fitsWithinSignedIntegerRange(value, targetType)
}

func FitsWithinUnsignedIntegerRange(value reflect.Value, targetType reflect.Type) bool {
max, err := getMaxUint(targetType)
if err != nil {
return false
}

switch value.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return value.Int() >= 0 && uint64(value.Int()) <= max
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
return value.Uint() <= max
}

return false
return fitsWithinUnsignedIntegerRange(value, targetType)
}

func FitsWithinFloatRange(value reflect.Value, targetType reflect.Type) bool {
min, err := getMinFloat(targetType)
if err != nil {
return false
}
max, err := getMaxFloat(targetType)
if err != nil {
return false
}

return value.Float() >= min && value.Float() <= max
return fitsWithinFloatRange(value, targetType)
}
2 changes: 1 addition & 1 deletion testscommon/toml/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
Mesage = { Public = true, MessageDescription = [{ Text = "Text1" }, { Text = "Text2"}] }

[TestMap]
Value = { "key" = 0 }
Value = { "key" = 0 }
2 changes: 1 addition & 1 deletion testscommon/toml/overwrite.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ OverridableConfigTomlValues = [
{ File = "config.toml", Path = "TestConfigStruct.ConfigStruct.Description", Value = { Number = "11" } },
{ File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct", Value = { Text = "Overwritten text", Message = { Public = false, MessageDescription = [{ Text = "Overwritten Text1" }] } } },
{ File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription", Value = [{ Text = "Overwritten Text1" }, { Text = "Overwritten Text2" }] },
]
]

0 comments on commit 74037f1

Please sign in to comment.