Skip to content

Commit

Permalink
Add test for dropLastLine
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-vasile committed Nov 15, 2021
1 parent 7b20615 commit 4a3ebd2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/magic/magic_test.go
Expand Up @@ -18,3 +18,31 @@ func TestMagic(t *testing.T) {
}
}
}

var dropTests = []struct {
raw string
cutAt uint32
res string
}{
{"", 0, ""},
{"", 1, ""},
{"å", 2, "å"},
{"\n", 0, "\n"},
{"\n", 1, "\n"},
{"\n\n", 1, "\n"},
{"\n\n", 3, "\n\n"},
{"a\n\n", 3, "a\n"},
{"\na\n", 3, "\na"},
{\n\n", 5, \n\n"},
{"\nå\n", 5, "\nå\n"},
}

func TestDropLastLine(t *testing.T) {
for i, tt := range dropTests {
gotR := dropLastLine([]byte(tt.raw), tt.cutAt)
got, _ := io.ReadAll(gotR)
if got := string(got); got != tt.res {
t.Errorf("dropLastLine %d error: expected %q; got %q", i, tt.res, got)
}
}
}

0 comments on commit 4a3ebd2

Please sign in to comment.