Add utility function SplitIntoLines.
This commit is contained in:
@@ -24,6 +24,12 @@ func ContainsString(haystack []string, needle string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lineEndingsRegexp = regexp.MustCompile("(\r\n|\n|\r)")
|
||||||
|
|
||||||
|
func SplitIntoLines(s string) []string {
|
||||||
|
return lineEndingsRegexp.Split(s, -1)
|
||||||
|
}
|
||||||
|
|
||||||
func ExitBecauseOfInternalError(err string) {
|
func ExitBecauseOfInternalError(err string) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package editorconfig
|
package editorconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,3 +17,11 @@ func TestGetParentDir(t *testing.T) {
|
|||||||
t.Error()
|
t.Error()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSplitIntoLines(t *testing.T) {
|
||||||
|
result := SplitIntoLines("Aardvark\nBunny\rCat\r\nDolphin\n")
|
||||||
|
expected := []string{"Aardvark", "Bunny", "Cat", "Dolphin", ""}
|
||||||
|
if !reflect.DeepEqual(result, expected) {
|
||||||
|
t.Error("Did not split string into lines correctly, got lines: " + strings.Join(result, ", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user