Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Pathfinder
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Go
Utilities
Pathfinder
Commits
b88fef16
Verified
Commit
b88fef16
authored
1 year ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
fix:
#7
parent
6b61bc3a
No related branches found
Branches containing commit
Tags
v0.7.2
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
issue_2_test.go
+10
-0
10 additions, 0 deletions
issue_2_test.go
issue_7_test.go
+19
-12
19 additions, 12 deletions
issue_7_test.go
set.go
+8
-1
8 additions, 1 deletion
set.go
with
37 additions
and
13 deletions
issue_2_test.go
+
10
−
0
View file @
b88fef16
...
...
@@ -135,7 +135,17 @@ func TestReplacePathForConfig(t *testing.T) {
},
}
nn
,
err2
:=
GetValue
[
MainTestStruct
](
config
,
"Sub.Default.Paths.Template"
)
assert
.
Nil
(
t
,
err2
)
assert
.
Equal
(
t
,
nn
,
PathValue
(
"../../../default.html"
))
err
:=
SetValue
[
*
MainTestStruct
](
&
config
,
"Sub.Default.Paths.Template"
,
"test"
)
assert
.
Nil
(
t
,
err
)
nn
,
err3
:=
GetValue
[
MainTestStruct
](
config
,
"Sub.Default.Paths.Template"
)
assert
.
Nil
(
t
,
err3
)
assert
.
Equal
(
t
,
nn
,
PathValue
(
"test"
))
}
This diff is collapsed.
Click to expand it.
issue_7_test.go
+
19
−
12
View file @
b88fef16
package
pathfinder
import
(
"github.com/stretchr/testify/assert"
"testing"
)
//// Ihre Fehlerdefinitionen
//func newInvalidPathError(path string) error {
// return fmt.Errorf("invalid path: %s", path)
//}
//
//func newCannotSetError(path string) error {
// return fmt.Errorf("cannot set: %s", path)
//}
// ... weitere Fehlerdefinitionen
// Test für SetValue
func
TestSetValue
(
t
*
testing
.
T
)
{
type
Inner
struct
{
...
...
@@ -23,13 +13,22 @@ func TestSetValue(t *testing.T) {
type
Outer
struct
{
InnerField
*
Inner
}
obj
:=
&
Outer
{
InnerField
:
&
Inner
{
Field
:
"oldValue"
,
},
}
err
:=
SetValue
(
obj
,
"InnerField.Field"
,
PathValue
(
"newValue"
))
v
,
err
:=
GetValue
[
Outer
](
*
obj
,
"InnerField.Field"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
assert
.
Equal
(
t
,
v
,
PathValue
(
"oldValue"
))
nv
:=
PathValue
(
"newValue"
)
err
=
SetValue
[
*
Outer
](
obj
,
"InnerField.Field"
,
nv
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
...
...
@@ -37,4 +36,12 @@ func TestSetValue(t *testing.T) {
if
obj
.
InnerField
.
Field
!=
"newValue"
{
t
.
Fatalf
(
"expected newValue, got: %s"
,
obj
.
InnerField
.
Field
)
}
v
,
err
=
GetValue
[
Outer
](
*
obj
,
"InnerField.Field"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
assert
.
Equal
(
t
,
v
,
nv
)
}
This diff is collapsed.
Click to expand it.
set.go
+
8
−
1
View file @
b88fef16
...
...
@@ -51,7 +51,14 @@ func SetValue[D any](obj D, keyWithDots string, newValue any) error {
return
newCannotSetError
(
"Wert ist nicht adressierbar"
)
}
newKey
:=
strings
.
Join
(
keySlice
[
keyIndex
+
1
:
],
"."
)
return
SetValue
(
newValueCopyPtr
,
newKey
,
newValue
)
err
:=
SetValue
(
newValueCopyPtr
,
newKey
,
newValue
)
if
err
!=
nil
{
return
err
}
v
.
SetMapIndex
(
reflect
.
ValueOf
(
key
),
reflect
.
ValueOf
(
newValueCopy
)
.
Elem
())
return
nil
}
if
v
.
Kind
()
==
reflect
.
Ptr
&&
v
.
Elem
()
.
Kind
()
==
reflect
.
Interface
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment