-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
visualiser: Allow spacing in node names (#38)
* visualiser: Allow spacing in node names * visualiser: Allow spacing in node names * visualiser: Allow spacing in node names
- Loading branch information
1 parent
efe6adb
commit f7b8b22
Showing
6 changed files
with
99 additions
and
18 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
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
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,15 @@ | ||
package util | ||
|
||
import "unicode" | ||
|
||
func CamelCaseToSpacing(s string) string { | ||
var result []rune | ||
for i, r := range s { | ||
if unicode.IsUpper(r) && i > 0 { | ||
result = append(result, ' ') | ||
} | ||
|
||
result = append(result, r) | ||
} | ||
return string(result) | ||
} |
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,31 @@ | ||
package util_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/luno/workflow/internal/util" | ||
) | ||
|
||
func TestCamelCaseToSpacing(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expected string | ||
}{ | ||
{"camelCase", "camel Case"}, | ||
{"thisIsATest", "this Is A Test"}, | ||
{"helloWorld", "hello World"}, | ||
{"singleWord", "single Word"}, | ||
{"Lowercase", "Lowercase"}, // No change if no camel case | ||
{"", ""}, // Empty string case | ||
} | ||
|
||
for i, test := range tests { | ||
t.Run(fmt.Sprintf("case %v: %v", i+1, test.input), func(t *testing.T) { | ||
result := util.CamelCaseToSpacing(test.input) | ||
require.Equal(t, test.expected, result) | ||
}) | ||
} | ||
} |
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
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