-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |