Skip to content

Commit

Permalink
skip-blank-lines ignores lines that only consist of spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
webner committed Jul 25, 2015
1 parent bcfdb4c commit 04b8f5a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion template.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func generateFile(config Config, containers Context) bool {
scanner := bufio.NewScanner(bufio.NewReader(&buf))
for scanner.Scan() {
line := scanner.Text()
if len(line) > 0 {
if !isBlank(line) {
fmt.Fprintln(dest, line)
}
}
Expand Down
10 changes: 10 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"os"
"strings"
"unicode"
)

func getEndpoint() (string, error) {
Expand Down Expand Up @@ -50,3 +51,12 @@ func pathExists(path string) (bool, error) {
}
return false, err
}

func isBlank(str string) bool {
for _, r := range str {
if !unicode.IsSpace(r) {
return false
}
}
return true
}
26 changes: 26 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,29 @@ func TestSplitKeyValueSlice(t *testing.T) {

}
}

func TestIsBlank(t *testing.T) {

tests := []struct {
input string
expected bool
}{
{"", true},
{" ", true},
{" ", true},
{"\t", true},
{"\t\n\v\f\r\u0085\u00A0", true},
{"a", false},
{" a ", false},
{"a ", false},
{" a", false},
{"日本語", false},
}

for _, i := range tests {
v := isBlank(i.input)
if v != i.expected {
t.Fatalf("expected '%v'. got '%v'", i.expected, v)
}
}
}

0 comments on commit 04b8f5a

Please sign in to comment.