Skip to content

Commit

Permalink
Add a helper pkg. (#87)
Browse files Browse the repository at this point in the history
There are some helper functions in various baton connectors. We should probably put the common ones in baton-sdk. At least that way they'll have the same bugs. :)
  • Loading branch information
ggreer authored Nov 21, 2023
1 parent 2d5239b commit 64d87cb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/helpers/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package helpers

import "strings"

func SplitFullName(name string) (string, string) {
names := strings.SplitN(name, " ", 2)
var firstName, lastName string

switch len(names) {
case 1:
firstName = names[0]
case 2:
firstName = names[0]
lastName = names[1]
}

return firstName, lastName
}
21 changes: 21 additions & 0 deletions pkg/helpers/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package helpers

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestHelpers_SplitFullName(t *testing.T) {
firstName, lastName := SplitFullName("Prince")
require.Equal(t, "Prince", firstName)
require.Equal(t, "", lastName)

firstName, lastName = SplitFullName("John Smith")
require.Equal(t, "John", firstName)
require.Equal(t, "Smith", lastName)

firstName, lastName = SplitFullName("John Jacob Jingleheimer Schmidt")
require.Equal(t, "John", firstName)
require.Equal(t, "Jacob Jingleheimer Schmidt", lastName)
}

0 comments on commit 64d87cb

Please sign in to comment.