Skip to content

Commit

Permalink
Merge pull request #204 from gabriel-vasile/droplastline
Browse files Browse the repository at this point in the history
Add test for dropLastLine
  • Loading branch information
gabriel-vasile committed Nov 15, 2021
2 parents 7c1d63d + 9852b1c commit bfdc13a
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion internal/magic/magic_test.go
@@ -1,6 +1,9 @@
package magic

import "testing"
import (
"io"
"testing"
)

var magicTests = []struct {
raw string
Expand All @@ -18,3 +21,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 bfdc13a

Please sign in to comment.