github.com/sereiner/library@v0.0.0-20200518095232-1fa3e640cc5f/influxdb/escape/bytes_test.go (about) 1 package escape 2 3 import ( 4 "bytes" 5 "reflect" 6 "strings" 7 "testing" 8 ) 9 10 func TestUnescape(t *testing.T) { 11 tests := []struct { 12 in []byte 13 out []byte 14 }{ 15 { 16 []byte(nil), 17 []byte(nil), 18 }, 19 20 { 21 []byte(""), 22 []byte(nil), 23 }, 24 25 { 26 []byte("\\,\\\"\\ \\="), 27 []byte(",\" ="), 28 }, 29 30 { 31 []byte("\\\\"), 32 []byte("\\\\"), 33 }, 34 35 { 36 []byte("plain and simple"), 37 []byte("plain and simple"), 38 }, 39 } 40 41 for ii, tt := range tests { 42 got := Unescape(tt.in) 43 if !reflect.DeepEqual(got, tt.out) { 44 t.Errorf("[%d] Unescape(%#v) = %#v, expected %#v", ii, string(tt.in), string(got), string(tt.out)) 45 } 46 } 47 } 48 49 func TestAppendUnescaped(t *testing.T) { 50 cases := strings.Split(strings.TrimSpace(` 51 normal 52 inv\alid 53 goo\"d 54 sp\ ace 55 \,\"\ \= 56 f\\\ x 57 `), "\n") 58 59 for _, c := range cases { 60 exp := Unescape([]byte(c)) 61 got := AppendUnescaped(nil, []byte(c)) 62 63 if !bytes.Equal(got, exp) { 64 t.Errorf("AppendUnescaped failed for %#q: got %#q, exp %#q", c, got, exp) 65 } 66 } 67 68 }