-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapply_string_test.go
More file actions
45 lines (35 loc) · 809 Bytes
/
apply_string_test.go
File metadata and controls
45 lines (35 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package changeset
import (
"strings"
"testing"
"github.com/go-rel/changeset/params"
"github.com/stretchr/testify/assert"
)
func TestApplyString(t *testing.T) {
type User struct {
Name string
}
user := User{}
input := params.Map{
"name": "¡¡¡Hello, Gophers!!!",
}
ch := Cast(user, input, []string{"name"})
ApplyString(ch, "name", func(s string) string {
return strings.TrimPrefix(s, "¡¡¡Hello, ")
})
assert.Equal(t, "Gophers!!!", ch.Changes()["name"])
}
func TestApplyString_ignored(t *testing.T) {
type User struct {
Name int
}
user := User{}
input := params.Map{
"name": 1,
}
ch := Cast(user, input, []string{"name"})
ApplyString(ch, "name", func(s string) string {
return strings.TrimPrefix(s, "¡¡¡Hello, ")
})
assert.Equal(t, 1, ch.Changes()["name"])
}