Add utils MustGetFileAsString and GetNumberOfLeftSpaces.

This commit is contained in:
Amy Boyd
2016-07-04 15:14:42 +01:00
parent 0e16bc1255
commit eb919067e6
2 changed files with 31 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package editorconfig
import (
"reflect"
"strconv"
"strings"
"testing"
)
@@ -25,3 +26,18 @@ func TestSplitIntoLines(t *testing.T) {
t.Error("Did not split string into lines correctly, got lines: " + strings.Join(result, ", "))
}
}
func TestMustGetFileAsString(t *testing.T) {
license := MustGetFileAsString("../LICENSE")
if !strings.Contains(license, "MIT License") || !strings.Contains(license, "THE SOFTWARE IS PROVIDED \"AS IS\"") {
t.Error("Could not read file")
}
}
func TestGetNumberOfLeftSpaces(t *testing.T) {
for i := 0; i < 20; i++ {
if GetNumberOfLeftSpaces(strings.Repeat(" ", i)) != i {
t.Error("Wrong number of spaces returned when string starts with " + strconv.Itoa(i) + " spaces")
}
}
}