mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-30 13:48:51 +08:00
PDFDocEncoding tests
This commit is contained in:
parent
6ec59ca86c
commit
e99b037340
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
25
pdf/internal/strutils/pdfdocenc_test.go
Normal file
25
pdf/internal/strutils/pdfdocenc_test.go
Normal 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user