optimize line count and limit maximal file size to read; fixes #101

Signed-off-by: Denys Smirnov <denys@sourced.tech>
This commit is contained in:
Denys Smirnov
2018-04-28 17:20:10 +03:00
committed by Denys Smirnov
parent c72d3c4af2
commit 6712d4219f
2 changed files with 106 additions and 52 deletions

View File

@ -27,10 +27,12 @@ func TestGetLines(t *testing.T) {
}
for i, test := range tests {
gotTotal, gotNonBlank := getLines([]byte(test.content))
if gotTotal != test.wantTotal || gotNonBlank != test.wantNonBlank {
t.Errorf("wrong line counts obtained for test case #%d:\n %7s, %7s\nGOT: %7d, %7d\nWANT: %7d, %7d\n", i, "TOTAL", "NON_BLANK",
gotTotal, gotNonBlank, test.wantTotal, test.wantNonBlank)
}
t.Run("", func(t *testing.T) {
gotTotal, gotNonBlank := getLines("", []byte(test.content))
if gotTotal != test.wantTotal || gotNonBlank != test.wantNonBlank {
t.Errorf("wrong line counts obtained for test case #%d:\n %7s, %7s\nGOT: %7d, %7d\nWANT: %7d, %7d\n", i, "TOTAL", "NON_BLANK",
gotTotal, gotNonBlank, test.wantTotal, test.wantNonBlank)
}
})
}
}