11package main
22
33import (
4+ "bytes"
45 "flag"
56 "os"
7+ "strings"
68 "testing"
79)
810
@@ -89,7 +91,6 @@ func TestSplitKeyValueSlice(t *testing.T) {
8991}
9092
9193func TestIsBlank (t * testing.T ) {
92-
9394 tests := []struct {
9495 input string
9596 expected bool
@@ -113,3 +114,33 @@ func TestIsBlank(t *testing.T) {
113114 }
114115 }
115116}
117+
118+ func TestRemoveBlankLines (t * testing.T ) {
119+ tests := []struct {
120+ input string
121+ expected string
122+ }{
123+ {"" , "" },
124+ {"\r \n \r \n " , "" },
125+ {"line1\n line2" , "line1\n line2" },
126+ {"line1\n \n line2" , "line1\n line2" },
127+ {"\n \n \n \n line1\n \n line2" , "line1\n line2" },
128+ {"\n \n \n \n \n \n \n \n " , "" },
129+
130+ // windows line endings \r\n
131+ {"line1\r \n line2" , "line1\r \n line2" },
132+ {"line1\r \n \r \n line2" , "line1\r \n line2" },
133+
134+ // keep last new line
135+ {"line1\n " , "line1\n " },
136+ {"line1\r \n " , "line1\r \n " },
137+ }
138+
139+ for _ , i := range tests {
140+ output := new (bytes.Buffer )
141+ removeBlankLines (strings .NewReader (i .input ), output )
142+ if output .String () != i .expected {
143+ t .Fatalf ("expected '%v'. got '%v'" , i .expected , output )
144+ }
145+ }
146+ }
0 commit comments