codeberg.org/go-pdf/fpdf@v0.11.1/def_test.go (about) 1 // Copyright ©2023 The go-pdf Authors. All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE file. 4 5 package fpdf 6 7 import ( 8 "math/rand" 9 "reflect" 10 "sort" 11 "testing" 12 ) 13 14 func TestPDFVersionOrder(t *testing.T) { 15 want := []pdfVersion{ 16 0, 17 pdfVersionFrom(0, 1), 18 pdfVersionFrom(0, 10), 19 pdfVersionFrom(1, 0), 20 pdfVersionFrom(1, 1), 21 pdfVersionFrom(1, 2), 22 pdfVers1_3, 23 pdfVers1_4, 24 pdfVers1_5, 25 pdfVersionFrom(1, 10), 26 pdfVersionFrom(2, 0), 27 pdfVersionFrom(2, 1), 28 pdfVersionFrom(2, 10), 29 } 30 sorted := sort.SliceIsSorted(want, func(i, j int) bool { 31 return want[i] < want[j] 32 }) 33 if !sorted { 34 t.Fatalf("PDF-version ordering is flawed") 35 } 36 37 got := make([]pdfVersion, len(want)) 38 copy(got, want) 39 40 rnd := rand.New(rand.NewSource(1234)) 41 rnd.Shuffle(len(got), func(i, j int) { 42 got[i], got[j] = got[j], got[i] 43 }) 44 45 if reflect.DeepEqual(got, want) { 46 t.Fatalf("shuffling failed") 47 } 48 49 sort.Slice(got, func(i, j int) bool { 50 return got[i] < got[j] 51 }) 52 53 if !reflect.DeepEqual(got, want) { 54 t.Fatalf("PDF-version ordering is wrong:\ngot= %q\nwant=%q", got, want) 55 } 56 }