github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/luastrings/escape_test.go (about) 1 package luastrings 2 3 import "testing" 4 5 func TestQuote(t *testing.T) { 6 type args struct { 7 s string 8 quote byte 9 } 10 tests := []struct { 11 name string 12 args args 13 want string 14 }{ 15 { 16 name: "single quoted", 17 args: args{ 18 s: `"hi" 'there'`, 19 quote: '\'', 20 }, 21 want: `'"hi" \'there\''`, 22 }, 23 { 24 name: "double quoted", 25 args: args{ 26 s: `"hi" 'there'`, 27 quote: '"', 28 }, 29 want: `"\"hi\" 'there'"`, 30 }, 31 { 32 name: "named escapes", 33 args: args{ 34 s: "\a\b\t\n\v\f", 35 quote: '"', 36 }, 37 want: `"\a\b\t\n\v\f"`, 38 }, 39 { 40 name: "ascii escapes", 41 args: args{ 42 s: "\x00\x01\x7f", 43 quote: '"', 44 }, 45 want: `"\0\1\127"`, 46 }, 47 } 48 for _, tt := range tests { 49 t.Run(tt.name, func(t *testing.T) { 50 if got := Quote(tt.args.s, tt.args.quote); got != tt.want { 51 t.Errorf("Quote() = %v, want %v", got, tt.want) 52 } 53 }) 54 } 55 }