github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/copy_test.go (about) 1 // Copyright 2016 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package sql 12 13 import ( 14 "testing" 15 16 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 17 ) 18 19 func TestDecodeCopy(t *testing.T) { 20 defer leaktest.AfterTest(t)() 21 22 tests := []struct { 23 in string 24 expect string 25 err bool 26 }{ 27 { 28 in: `new\nline`, 29 expect: "new\nline", 30 }, 31 { 32 in: `\b\f\n\r\t\v\\`, 33 expect: "\b\f\n\r\t\v\\", 34 }, 35 { 36 in: `\0\12\123`, 37 expect: "\000\012\123", 38 }, 39 { 40 in: `\x1\xaf`, 41 expect: "\x01\xaf", 42 }, 43 { 44 in: `T\n\07\xEV\x0fA\xb2C\1`, 45 expect: "T\n\007\x0eV\x0fA\xb2C\001", 46 }, 47 48 // Error cases. 49 50 { 51 in: `\x`, 52 err: true, 53 }, 54 { 55 in: `\xg`, 56 err: true, 57 }, 58 { 59 in: `\`, 60 err: true, 61 }, 62 { 63 in: `\8`, 64 err: true, 65 }, 66 { 67 in: `\a`, 68 err: true, 69 }, 70 } 71 72 for _, test := range tests { 73 out, err := decodeCopy(test.in) 74 if gotErr := err != nil; gotErr != test.err { 75 if gotErr { 76 t.Errorf("%q: unexpected error: %v", test.in, err) 77 continue 78 } 79 t.Errorf("%q: expected error", test.in) 80 continue 81 } 82 if out != test.expect { 83 t.Errorf("%q: got %q, expected %q", test.in, out, test.expect) 84 } 85 } 86 }