MCPcopy Create free account
hub / github.com/gotenberg/gotenberg / TestAlphanumericSort

Function TestAlphanumericSort

pkg/gotenberg/sort_test.go:9–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestAlphanumericSort(t *testing.T) {
10 for _, tc := range []struct {
11 scenario string
12 values []string
13 expectedSort []string
14 }{
15 {
16 scenario: "numeric and letters",
17 values: []string{"10qux.pdf", "2_baz.txt", "2_aza.txt", "1bar.pdf", "Afoo.txt", "Bbar.docx", "25zeta.txt", "3.pdf", "4_foo.pdf"},
18 expectedSort: []string{"1bar.pdf", "2_aza.txt", "2_baz.txt", "3.pdf", "4_foo.pdf", "10qux.pdf", "25zeta.txt", "Afoo.txt", "Bbar.docx"},
19 },
20 {
21 scenario: "numeric suffixes with extensions",
22 values: []string{"sample1_10.pdf", "sample1_11.pdf", "sample1_4.pdf", "sample1_3.pdf", "sample1_1.pdf", "sample1_2.pdf"},
23 expectedSort: []string{"sample1_1.pdf", "sample1_2.pdf", "sample1_3.pdf", "sample1_4.pdf", "sample1_10.pdf", "sample1_11.pdf"},
24 },
25 {
26 scenario: "numeric suffixes",
27 values: []string{"sample1_10", "sample1_11", "sample1_4", "sample1_3", "sample1_1", "sample1_2"},
28 expectedSort: []string{"sample1_1", "sample1_2", "sample1_3", "sample1_4", "sample1_10", "sample1_11"},
29 },
30 {
31 scenario: "hrtime (PHP library)",
32 values: []string{"245654773395259", "245654773395039", "245654773395149", "245654773394919", "245654773394369"},
33 expectedSort: []string{"245654773394369", "245654773394919", "245654773395039", "245654773395149", "245654773395259"},
34 },
35 {
36 // https://github.com/gotenberg/gotenberg/issues/1287.
37 scenario: "different basenames with numeric suffixes",
38 values: []string{"RIJNMOND-attach-Opdrachtbevestiging_P0007104.pdf", "Bundle-25029.pdf"},
39 expectedSort: []string{"Bundle-25029.pdf", "RIJNMOND-attach-Opdrachtbevestiging_P0007104.pdf"},
40 },
41 } {
42 t.Run(tc.scenario, func(t *testing.T) {
43 sort.Sort(AlphanumericSort(tc.values))
44
45 if !reflect.DeepEqual(tc.values, tc.expectedSort) {
46 t.Fatalf("expected %+v but got: %+v", tc.expectedSort, tc.values)
47 }
48 })
49 }
50}

Callers

nothing calls this directly

Calls 2

AlphanumericSortTypeAlias · 0.85
RunMethod · 0.65

Tested by

no test coverage detected