github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/text/encoding/japanese/all_test.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package japanese 6 7 import ( 8 "testing" 9 10 "golang.org/x/text/encoding" 11 "golang.org/x/text/encoding/internal" 12 "golang.org/x/text/transform" 13 ) 14 15 func dec(e encoding.Encoding) (dir string, t transform.Transformer, err error) { 16 return "Decode", e.NewDecoder(), nil 17 } 18 func enc(e encoding.Encoding) (dir string, t transform.Transformer, err error) { 19 return "Encode", e.NewEncoder(), internal.ErrASCIIReplacement 20 } 21 22 func TestNonRepertoire(t *testing.T) { 23 testCases := []struct { 24 init func(e encoding.Encoding) (string, transform.Transformer, error) 25 e encoding.Encoding 26 src, want string 27 }{ 28 {dec, EUCJP, "\xfe\xfc", "\ufffd"}, 29 {dec, ISO2022JP, "\x1b$B\x7e\x7e", "\ufffd"}, 30 {dec, ShiftJIS, "\xef\xfc", "\ufffd"}, 31 32 {enc, EUCJP, "갂", ""}, 33 {enc, EUCJP, "a갂", "a"}, 34 {enc, EUCJP, "丌갂", "\x8f\xb0\xa4"}, 35 36 {enc, ISO2022JP, "갂", ""}, 37 {enc, ISO2022JP, "a갂", "a"}, 38 {enc, ISO2022JP, "朗갂", "\x1b$BzF\x1b(B"}, // switch back to ASCII mode at end 39 40 {enc, ShiftJIS, "갂", ""}, 41 {enc, ShiftJIS, "a갂", "a"}, 42 {enc, ShiftJIS, "\u2190갂", "\x81\xa9"}, 43 } 44 for _, tc := range testCases { 45 dir, tr, wantErr := tc.init(tc.e) 46 47 dst, _, err := transform.String(tr, tc.src) 48 if err != wantErr { 49 t.Errorf("%s %v(%q): got %v; want %v", dir, tc.e, tc.src, err, wantErr) 50 } 51 if got := string(dst); got != tc.want { 52 t.Errorf("%s %v(%q):\ngot %q\nwant %q", dir, tc.e, tc.src, got, tc.want) 53 } 54 } 55 }