mirror of
https://github.com/IBM/fp-go.git
synced 2025-11-23 22:14:53 +02:00
39 lines
525 B
Go
39 lines
525 B
Go
|
|
package io
|
||
|
|
|
||
|
|
import (
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/assert"
|
||
|
|
)
|
||
|
|
|
||
|
|
func toUpper(s string) IO[string] {
|
||
|
|
return Of(strings.ToUpper(s))
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestTraverseArray(t *testing.T) {
|
||
|
|
|
||
|
|
src := []string{"a", "b"}
|
||
|
|
|
||
|
|
trv := TraverseArray(toUpper)
|
||
|
|
|
||
|
|
res := trv(src)
|
||
|
|
|
||
|
|
assert.Equal(t, res(), []string{"A", "B"})
|
||
|
|
}
|
||
|
|
|
||
|
|
type (
|
||
|
|
customSlice []string
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestTraverseCustomSlice(t *testing.T) {
|
||
|
|
|
||
|
|
src := customSlice{"a", "b"}
|
||
|
|
|
||
|
|
trv := TraverseArray(toUpper)
|
||
|
|
|
||
|
|
res := trv(src)
|
||
|
|
|
||
|
|
assert.Equal(t, res(), []string{"A", "B"})
|
||
|
|
}
|