| 1 |
package zipextra |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/hex" |
| 5 |
"testing" |
| 6 |
) |
| 7 |
|
| 8 |
func TestInfoZIPUnicodeComment(t *testing.T) { |
| 9 |
tests := []struct { |
| 10 |
version uint8 |
| 11 |
crc32 uint32 |
| 12 |
comment string |
| 13 |
raw string |
| 14 |
}{ |
| 15 |
{1, 0x3c27b58d, "a comment 🌩", "75631300018db5273c6120636f6d6d656e7420f09f8ca9"}, |
| 16 |
{1, 0x9cc1778e, "another comment ¿", "75631700018e77c19c616e6f7468657220636f6d6d656e7420c2bf"}, |
| 17 |
{1, 0x643c7f60, "wild comment appeared! â„¢", "75631f0001607f3c6477696c6420636f6d6d656e742061707065617265642120e284a2"}, |
| 18 |
} |
| 19 |
|
| 20 |
for _, test := range tests { |
| 21 |
|
| 22 |
raw := NewInfoZIPUnicodeComment(test.comment).Encode() |
| 23 |
if test.raw != hex.EncodeToString(raw) { |
| 24 |
t.Errorf("expected %s, got %s", test.raw, hex.EncodeToString(raw)) |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
ucom, err := testHeader(t, raw, ExtraFieldUCom).InfoZIPUnicodeComment() |
| 29 |
if err != nil { |
| 30 |
t.Fatal(err) |
| 31 |
} |
| 32 |
|
| 33 |
if test.raw != hex.EncodeToString(ucom.Encode()) { |
| 34 |
t.Errorf("expected %s, got %s", test.raw, hex.EncodeToString(ucom.Encode())) |
| 35 |
} |
| 36 |
} |
| 37 |
} |