1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
package crlf
import (
"testing"
"golang.org/x/text/transform"
)
func TestNormalize(t *testing.T) {
testCases := []struct {
in string
want string
}{
{"hello, world\r\n", "hello, world\n"},
{"hello, world\r", "hello, world\n"},
{"hello, world\n", "hello, world\n"},
{"", ""},
{"\r\n", "\n"},
{"hello,\r\nworld", "hello,\nworld"},
{"hello,\rworld", "hello,\nworld"},
{"hello,\nworld", "hello,\nworld"},
{"hello,\n\rworld", "hello,\n\nworld"},
{"hello,\r\n\r\nworld", "hello,\n\nworld"},
}
n := new(Normalize)
for _, c := range testCases {
got, _, err := transform.String(n, c.in)
if err != nil {
t.Errorf("error transforming %q: %v", c.in, err)
continue
}
if got != c.want {
t.Errorf("transforming %q: got %q, want %q", c.in, got, c.want)
}
}
}
func TestToCRLF(t *testing.T) {
testCases := []struct {
in string
want string
}{
{"hello, world\n", "hello, world\r\n"},
{"", ""},
{"\n", "\r\n"},
{"hello,\nworld", "hello,\r\nworld"},
{"hello,\n\nworld", "hello,\r\n\r\nworld"},
}
for _, c := range testCases {
got, _, err := transform.String(ToCRLF{}, c.in)
if err != nil {
t.Errorf("error transforming %q: %v", c.in, err)
continue
}
if got != c.want {
t.Errorf("transforming %q: got %q, want %q", c.in, got, c.want)
}
}
}
|