github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/luastrings/normalize_test.go (about) 1 package luastrings 2 3 import ( 4 "testing" 5 ) 6 7 func TestNormalizeNewLines(t *testing.T) { 8 tests := []struct { 9 name string 10 arg string 11 want string 12 }{ 13 { 14 name: "no line endings", 15 arg: "hello there", 16 want: "hello there", 17 }, 18 { 19 name: "only LF", 20 arg: "line\nline\nline", 21 want: "line\nline\nline", 22 }, 23 { 24 name: "CR LF CR", 25 arg: "\r\nline\r\n\rline", 26 want: "\nline\n\nline", 27 }, 28 { 29 name: "LF CR LF", 30 arg: "line\n\r\nline\n\r", 31 want: "line\n\nline\n", 32 }, 33 } 34 for _, tt := range tests { 35 t.Run(tt.name, func(t *testing.T) { 36 if got := NormalizeNewLines([]byte(tt.arg)); string(got) != tt.want { 37 t.Errorf("NormalizeNewLines() = %q, want %q", got, tt.want) 38 } 39 }) 40 } 41 }