fix(pdfcpu): use custom sort to retrieve the splitted PDFs

This commit is contained in:
Julien Neuhart
2025-04-12 19:40:16 +02:00
parent 7ca1d118a1
commit 9701f88ae3
3 changed files with 98 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
package pdfcpu
import (
"reflect"
"sort"
"testing"
)
func TestDigitSuffixSort(t *testing.T) {
for _, tc := range []struct {
scenario string
values []string
expectedSort []string
}{
{
scenario: "UUIDs with digit suffixes",
values: []string{"2521a33d-1fb4-4279-80fe-8a945285b8f4_12.pdf", "2521a33d-1fb4-4279-80fe-8a945285b8f4_1.pdf", "2521a33d-1fb4-4279-80fe-8a945285b8f4_10.pdf", "2521a33d-1fb4-4279-80fe-8a945285b8f4_3.pdf"},
expectedSort: []string{"2521a33d-1fb4-4279-80fe-8a945285b8f4_1.pdf", "2521a33d-1fb4-4279-80fe-8a945285b8f4_3.pdf", "2521a33d-1fb4-4279-80fe-8a945285b8f4_10.pdf", "2521a33d-1fb4-4279-80fe-8a945285b8f4_12.pdf"},
},
} {
t.Run(tc.scenario, func(t *testing.T) {
sort.Sort(digitSuffixSort(tc.values))
if !reflect.DeepEqual(tc.values, tc.expectedSort) {
t.Fatalf("expected %+v but got: %+v", tc.expectedSort, tc.values)
}
})
}
}