+ fileNameWithInfoHeader FileNameWithInfoHeader
+ name []byte
+ }
+ tests := []struct {
+ name string
+ fields fields
+ wantData []byte
+ wantErr bool
+ }{
+ {
+ name: "returns expected bytes",
+ fields: fields{
+ fileNameWithInfoHeader: FileNameWithInfoHeader{
+ Type: [4]byte{0x54, 0x45, 0x58, 0x54}, // TEXT
+ Creator: [4]byte{0x54, 0x54, 0x58, 0x54}, // TTXT
+ FileSize: [4]byte{0x00, 0x43, 0x16, 0xd3}, // File Size
+ RSVD: [4]byte{0, 0, 0, 0},
+ NameScript: [2]byte{0, 0},
+ NameSize: [2]byte{0x00, 0x03},
+ },
+ name: []byte("foo"),
+ },
+ wantData: []byte{
+ 0x54, 0x45, 0x58, 0x54,
+ 0x54, 0x54, 0x58, 0x54,
+ 0x00, 0x43, 0x16, 0xd3,
+ 0, 0, 0, 0,
+ 0, 0,
+ 0x00, 0x03,
+ 0x66, 0x6f, 0x6f,
+ },
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ f := &FileNameWithInfo{
+ FileNameWithInfoHeader: tt.fields.fileNameWithInfoHeader,
+ Name: tt.fields.name,
+ }
+ gotData, err := io.ReadAll(f)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("MarshalBinary() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(gotData, tt.wantData) {
+ t.Errorf("MarshalBinary() gotData = %v, want %v", gotData, tt.wantData)
+ }
+ })
+ }
+}
+
+func TestFileNameWithInfo_UnmarshalBinary(t *testing.T) {
+ type fields struct {
+ fileNameWithInfoHeader FileNameWithInfoHeader
+ name []byte