github.com/karrick/gorill@v1.10.3/newline_test.go (about) 1 package gorill 2 3 import "testing" 4 5 func TestNewline(t *testing.T) { 6 t.Run("empty", func(t *testing.T) { 7 if got, want := newline(""), "\n"; got != want { 8 t.Errorf("GOT: %q; WANT: %q", got, want) 9 } 10 }) 11 t.Run("single character", func(t *testing.T) { 12 if got, want := newline("a"), "a\n"; got != want { 13 t.Errorf("GOT: %q; WANT: %q", got, want) 14 } 15 }) 16 t.Run("single newline", func(t *testing.T) { 17 if got, want := newline("\n"), "\n"; got != want { 18 t.Errorf("GOT: %q; WANT: %q", got, want) 19 } 20 }) 21 t.Run("multiple newline", func(t *testing.T) { 22 if got, want := newline("\n\n"), "\n"; got != want { 23 t.Errorf("GOT: %q; WANT: %q", got, want) 24 } 25 }) 26 t.Run("string plus single newline", func(t *testing.T) { 27 if got, want := newline("abc\n"), "abc\n"; got != want { 28 t.Errorf("GOT: %q; WANT: %q", got, want) 29 } 30 }) 31 t.Run("string plus multiple newlines", func(t *testing.T) { 32 if got, want := newline("abc\n\n"), "abc\n"; got != want { 33 t.Errorf("GOT: %q; WANT: %q", got, want) 34 } 35 }) 36 t.Run("string with multiple embedded newlines", func(t *testing.T) { 37 if got, want := newline("abc\n\ndef\n\n"), "abc\n\ndef\n"; got != want { 38 t.Errorf("GOT: %q; WANT: %q", got, want) 39 } 40 }) 41 }