Skip to content

Commit

Permalink
re-encode card
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverpool committed Oct 23, 2024
1 parent cd89ae2 commit 2847935
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions decoder_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vcard

import (
"bytes"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -133,6 +134,29 @@ func TestDecoder(t *testing.T) {
}
}
}

var buf bytes.Buffer
err = NewEncoder(&buf).Encode(card)
if err != nil {
t.Fatal("Expected no error when encoding card, got:", err)
}
// the encoding is not canonical, so we can't compare it
// we re-decode the encoded part instead
cardReEncoded, err := NewDecoder(&buf).Decode()
if err != nil {
t.Fatal("Expected no error when re-decoding card, got:", err)
}
if !reflect.DeepEqual(cardReEncoded, test.card) {
t.Errorf("Invalid re-parsed card: expected \n%+v\n but got \n%+v", test.card, cardReEncoded)
for k, fields := range test.card {
if reflect.DeepEqual(fields, cardReEncoded[k]) {
continue
}
for i := range fields {
t.Log(k, i, fields[i], cardReEncoded[k][i])
}
}
}
}
}

Expand Down

0 comments on commit 2847935

Please sign in to comment.