aboutsummaryrefslogtreecommitdiffstats
path: root/modules/util
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2024-02-29 19:52:49 +0100
committerGitHub <noreply@github.com>2024-02-29 18:52:49 +0000
commitf6656181e4a07d6c415927220efa2077d509f7c6 (patch)
tree27d195c32a09091ea73dcd22b71f6dd5512162fc /modules/util
parentc7dcb58b1d96970959a5c8ac8d3955e4b7d027df (diff)
downloadgitea-f6656181e4a07d6c415927220efa2077d509f7c6.tar.gz
gitea-f6656181e4a07d6c415927220efa2077d509f7c6.zip
migrate some more "OptionalBool" to "Option[bool]" (#29479)
just some refactoring bits towards replacing **util.OptionalBool** with **optional.Option[bool]** --------- Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Diffstat (limited to 'modules/util')
-rw-r--r--modules/util/util.go10
-rw-r--r--modules/util/util_test.go20
2 files changed, 16 insertions, 14 deletions
diff --git a/modules/util/util.go b/modules/util/util.go
index 28b549f405..615f654e47 100644
--- a/modules/util/util.go
+++ b/modules/util/util.go
@@ -68,13 +68,13 @@ func OptionalBoolOf(b bool) OptionalBool {
return OptionalBoolFalse
}
-// OptionalBoolParse get the corresponding OptionalBool of a string using strconv.ParseBool
-func OptionalBoolParse(s string) OptionalBool {
- b, e := strconv.ParseBool(s)
+// OptionalBoolParse get the corresponding optional.Option[bool] of a string using strconv.ParseBool
+func OptionalBoolParse(s string) optional.Option[bool] {
+ v, e := strconv.ParseBool(s)
if e != nil {
- return OptionalBoolNone
+ return optional.None[bool]()
}
- return OptionalBoolOf(b)
+ return optional.Some(v)
}
// IsEmptyString checks if the provided string is empty
diff --git a/modules/util/util_test.go b/modules/util/util_test.go
index c5830ce01c..819e12ee91 100644
--- a/modules/util/util_test.go
+++ b/modules/util/util_test.go
@@ -8,6 +8,8 @@ import (
"strings"
"testing"
+ "code.gitea.io/gitea/modules/optional"
+
"github.com/stretchr/testify/assert"
)
@@ -173,17 +175,17 @@ func Test_RandomBytes(t *testing.T) {
assert.NotEqual(t, bytes3, bytes4)
}
-func Test_OptionalBool(t *testing.T) {
- assert.Equal(t, OptionalBoolNone, OptionalBoolParse(""))
- assert.Equal(t, OptionalBoolNone, OptionalBoolParse("x"))
+func TestOptionalBoolParse(t *testing.T) {
+ assert.Equal(t, optional.None[bool](), OptionalBoolParse(""))
+ assert.Equal(t, optional.None[bool](), OptionalBoolParse("x"))
- assert.Equal(t, OptionalBoolFalse, OptionalBoolParse("0"))
- assert.Equal(t, OptionalBoolFalse, OptionalBoolParse("f"))
- assert.Equal(t, OptionalBoolFalse, OptionalBoolParse("False"))
+ assert.Equal(t, optional.Some(false), OptionalBoolParse("0"))
+ assert.Equal(t, optional.Some(false), OptionalBoolParse("f"))
+ assert.Equal(t, optional.Some(false), OptionalBoolParse("False"))
- assert.Equal(t, OptionalBoolTrue, OptionalBoolParse("1"))
- assert.Equal(t, OptionalBoolTrue, OptionalBoolParse("t"))
- assert.Equal(t, OptionalBoolTrue, OptionalBoolParse("True"))
+ assert.Equal(t, optional.Some(true), OptionalBoolParse("1"))
+ assert.Equal(t, optional.Some(true), OptionalBoolParse("t"))
+ assert.Equal(t, optional.Some(true), OptionalBoolParse("True"))
}
// Test case for any function which accepts and returns a single string.