From e99b037340adff7d26893cb1bd25069bd9d657d2 Mon Sep 17 00:00:00 2001 From: Gunnsteinn Hall Date: Fri, 28 Sep 2018 09:50:18 +0000 Subject: [PATCH] PDFDocEncoding tests --- pdf/core/primitives_test.go | 16 ++++++++++++++++ pdf/internal/strutils/pdfdocenc_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 pdf/internal/strutils/pdfdocenc_test.go diff --git a/pdf/core/primitives_test.go b/pdf/core/primitives_test.go index a0cb426d..10ee3650 100644 --- a/pdf/core/primitives_test.go +++ b/pdf/core/primitives_test.go @@ -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) + } + } +} diff --git a/pdf/internal/strutils/pdfdocenc_test.go b/pdf/internal/strutils/pdfdocenc_test.go new file mode 100644 index 00000000..de049593 --- /dev/null +++ b/pdf/internal/strutils/pdfdocenc_test.go @@ -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 +}