summaryrefslogtreecommitdiff
path: root/internal/example
diff options
context:
space:
mode:
Diffstat (limited to 'internal/example')
-rw-r--r--internal/example/example.go25
1 files changed, 23 insertions, 2 deletions
diff --git a/internal/example/example.go b/internal/example/example.go
index d6a114c..b29561c 100644
--- a/internal/example/example.go
+++ b/internal/example/example.go
@@ -22,6 +22,8 @@ import (
"os"
"path/filepath"
"strings"
+
+ "github.com/jung-kurt/gofpdf"
)
var gofpdfDir string
@@ -36,8 +38,7 @@ func setRoot() {
wdStr, err := os.Getwd()
if err == nil {
gofpdfDir = ""
- sepStr := string(os.PathSeparator)
- list := strings.Split(wdStr, sepStr)
+ list := strings.Split(filepath.ToSlash(wdStr), "/")
for j := len(list) - 1; j >= 0 && list[j] != "gofpdf"; j-- {
gofpdfDir = filepath.Join(gofpdfDir, "..")
}
@@ -87,12 +88,32 @@ func Filename(baseStr string) string {
return PdfFile(baseStr + ".pdf")
}
+// referenceCompare compares the specified file with the file's reference copy
+// located in the 'reference' subdirectory. All bytes of the two files are
+// compared except for the value of the /CreationDate field in the PDF. This
+// function succeeds if both files are equivalent except for their
+// /CreationDate values or if the reference file does not exist.
+func referenceCompare(fileStr string) (err error) {
+ var refFileStr, refDirStr, dirStr, baseFileStr string
+ dirStr, baseFileStr = filepath.Split(fileStr)
+ refDirStr = filepath.Join(dirStr, "reference")
+ err = os.MkdirAll(refDirStr, 0755)
+ if err == nil {
+ refFileStr = filepath.Join(refDirStr, baseFileStr)
+ err = gofpdf.ComparePDFFiles(fileStr, refFileStr)
+ }
+ return
+}
+
// Summary generates a predictable report for use by test examples. If the
// specified error is nil, the filename delimiters are normalized and the
// filename printed to standard output with a success message. If the specified
// error is not nil, its String() value is printed to standard output.
func Summary(err error, fileStr string) {
if err == nil {
+ err = referenceCompare(fileStr)
+ }
+ if err == nil {
fileStr = filepath.ToSlash(fileStr)
fmt.Printf("Successfully generated %s\n", fileStr)
} else {