PDFDocEncoding tests

This commit is contained in:
Gunnsteinn Hall 2018-09-28 09:50:18 +00:00
parent 6ec59ca86c
commit e99b037340
2 changed files with 41 additions and 0 deletions

View File

@ -78,3 +78,19 @@ func TestHexStringMulti(t *testing.T) {
}
}
}
func TestPdfDocEncodingDecode(t *testing.T) {
testcases := []struct {
Encoded PdfObjectString
Expected string
}{
{PdfObjectString{val: "Ger\xfer\xfa\xf0ur", isHex: false}, "Gerþrúður"},
}
for _, testcase := range testcases {
dec := testcase.Encoded.Decoded()
if dec != testcase.Expected {
t.Fatalf("%s != %s", dec, testcase.Expected)
}
}
}

View File

@ -0,0 +1,25 @@
package strutils
import (
"testing"
)
func TestPDFDocEncodingDecode(t *testing.T) {
testcases := []struct {
Encoded []byte
Expected string
}{
{[]byte{0x47, 0x65, 0x72, 0xfe, 0x72, 0xfa, 0xf0, 0x75, 0x72}, "Gerþrúður"},
{[]byte("Ger\xfer\xfa\xf0ur"), "Gerþrúður"},
}
v := []byte{0x47, 0x65, 0x72, 0xfe, 0x72, 0xfa, 0xf0, 0x75, 0x72}
for _, testcase := range testcases {
str := PDFDocEncodingToString(testcase.Encoded)
if str != testcase.Expected {
t.Fatalf("Mismatch %s != %s", str, testcase.Expected)
}
}
return
}