Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 package charset | 1 package charset |
2 | 2 |
3 import ( | 3 import ( |
4 "io/ioutil" | 4 "io/ioutil" |
5 "strings" | 5 "strings" |
6 "testing" | 6 "testing" |
7 | 7 |
8 "code.google.com/p/go.text/transform" | 8 "code.google.com/p/go.text/transform" |
9 ) | 9 ) |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 {"イウエオカ", "\xb2\xb3\xb4\xb5\xb6", "SJIS"}, | 57 {"イウエオカ", "\xb2\xb3\xb4\xb5\xb6", "SJIS"}, |
58 {"これは漢字です。", "\xa4\xb3\xa4\xec\xa4\u03f4\xc1\xbb\xfa\xa4\u01e4\xb9\xa1\x a3", "EUC-JP"}, | 58 {"これは漢字です。", "\xa4\xb3\xa4\xec\xa4\u03f4\xc1\xbb\xfa\xa4\u01e4\xb9\xa1\x a3", "EUC-JP"}, |
59 {"Hello, 世界!", "Hello, \x1b$B@$3&\x1b(B!", "ISO-2022-JP"}, | 59 {"Hello, 世界!", "Hello, \x1b$B@$3&\x1b(B!", "ISO-2022-JP"}, |
60 {"네이트 | 즐거움의 시작, 슈파스(Spaβ) NATE", "\xb3\xd7\xc0\xcc\xc6\xae | \xc1\xf1\x b0\xc5\xbf\xf2\xc0\xc7 \xbd\xc3\xc0\xdb, \xbd\xb4\xc6\xc4\xbd\xba(Spa\xa5\xe2) N ATE", "EUC-KR"}, | 60 {"네이트 | 즐거움의 시작, 슈파스(Spaβ) NATE", "\xb3\xd7\xc0\xcc\xc6\xae | \xc1\xf1\x b0\xc5\xbf\xf2\xc0\xc7 \xbd\xc3\xc0\xdb, \xbd\xb4\xc6\xc4\xbd\xba(Spa\xa5\xe2) N ATE", "EUC-KR"}, |
61 } | 61 } |
62 | 62 |
63 func TestDecode(t *testing.T) { | 63 func TestDecode(t *testing.T) { |
64 for _, tc := range testCases { | 64 for _, tc := range testCases { |
65 e := Encoding(tc.otherEncoding) | 65 e := Encoding(tc.otherEncoding) |
66 if e == nil { | 66 if e == nil { |
67 » » » t.Errorf("Could not create decoder for %s", tc.otherEnco ding) | 67 » » » t.Errorf("%s: not found", tc.otherEncoding) |
nigeltao
2013/11/18 04:16:18
I would make these error messages consistently be
andybalholm
2013/11/18 17:01:28
Done.
| |
68 continue | 68 continue |
69 } | 69 } |
70 | 70 |
71 s, err := transformString(e.NewDecoder(), tc.other) | 71 s, err := transformString(e.NewDecoder(), tc.other) |
72 | 72 |
73 if err != nil { | 73 if err != nil { |
74 » » » t.Errorf("error decoding %q from %s: %s", tc.other, tc.o therEncoding, err) | 74 » » » t.Errorf("%s: decode %q: %v", tc.otherEncoding, tc.other , err) |
75 continue | 75 continue |
76 } | 76 } |
77 | 77 |
78 if s != tc.utf8 { | 78 if s != tc.utf8 { |
79 t.Errorf("%s: got %q, want %q", tc.otherEncoding, s, tc. utf8) | 79 t.Errorf("%s: got %q, want %q", tc.otherEncoding, s, tc. utf8) |
80 } | 80 } |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 func TestEncode(t *testing.T) { | 84 func TestEncode(t *testing.T) { |
85 for _, tc := range testCases { | 85 for _, tc := range testCases { |
86 e := Encoding(tc.otherEncoding) | 86 e := Encoding(tc.otherEncoding) |
87 if e == nil { | 87 if e == nil { |
88 » » » t.Errorf("Could not create encoder for %s", tc.otherEnco ding) | 88 » » » t.Errorf("%s: not found", tc.otherEncoding) |
89 continue | 89 continue |
90 } | 90 } |
91 | 91 |
92 s, err := transformString(e.NewEncoder(), tc.utf8) | 92 s, err := transformString(e.NewEncoder(), tc.utf8) |
93 | 93 |
94 if err != nil { | 94 if err != nil { |
95 » » » t.Errorf("error encoding %q to %s: %s", tc.utf8, tc.othe rEncoding, err) | 95 » » » t.Errorf("%s: encode %q: %s", tc.otherEncoding, tc.utf8, err) |
96 continue | 96 continue |
97 } | 97 } |
98 | 98 |
99 if s != tc.other { | 99 if s != tc.other { |
100 t.Errorf("%s: got %q, want %q", tc.otherEncoding, s, tc. other) | 100 t.Errorf("%s: got %q, want %q", tc.otherEncoding, s, tc. other) |
101 } | 101 } |
102 } | 102 } |
103 } | 103 } |
LEFT | RIGHT |