1package pdfexport23import (4 "testing"56 "codeberg.org/go-pdf/fpdf"7)89func TestWrapInstructionLinesWrapsToSafeWidth(t *testing.T) {10 pdf := fpdf.NewCustom(&fpdf.InitType{11 OrientationStr: "P",12 UnitStr: "mm",13 Size: fpdf.SizeType{14 Wd: halfLetterWidthMM,15 Ht: halfLetterHeightMM,16 },17 })18 if err := registerPDFFonts(pdf); err != nil {19 t.Fatalf("registerPDFFonts error: %v", err)20 }21 pdf.AddPage()2223 body := PuzzleBodyRect(halfLetterWidthMM, halfLetterHeightMM, 2)24 lines := wrapInstructionLines(25 pdf,26 body.W,27 []string{"Shade duplicates; shaded cells cannot touch orthogonally; unshaded cells stay connected."},28 )29 if len(lines) < 2 {30 t.Fatalf("line count = %d, want at least 2 (%v)", len(lines), lines)31 }3233 setInstructionStyle(pdf)34 maxWidth := body.W - instructionWrapInsetMM*235 for _, line := range lines {36 if got := pdf.GetStringWidth(line); got > maxWidth+0.01 {37 t.Fatalf("line %q width = %.2f, want <= %.2f", line, got, maxWidth)38 }39 }40}4142func TestWrapInstructionLinesKeepsShortRulesSingleLine(t *testing.T) {43 pdf := fpdf.NewCustom(&fpdf.InitType{44 OrientationStr: "P",45 UnitStr: "mm",46 Size: fpdf.SizeType{47 Wd: halfLetterWidthMM,48 Ht: halfLetterHeightMM,49 },50 })51 if err := registerPDFFonts(pdf); err != nil {52 t.Fatalf("registerPDFFonts error: %v", err)53 }54 pdf.AddPage()5556 body := PuzzleBodyRect(halfLetterWidthMM, halfLetterHeightMM, 2)57 lines := wrapInstructionLines(pdf, body.W, []string{"Fill rows, columns, and 3x3 boxes with 1-9"})58 if len(lines) != 1 {59 t.Fatalf("line count = %d, want 1 (%v)", len(lines), lines)60 }61}6263func TestTakuzuPlusRuleCopyWrapsToThreePhysicalLines(t *testing.T) {64 pdf := fpdf.NewCustom(&fpdf.InitType{65 OrientationStr: "P",66 UnitStr: "mm",67 Size: fpdf.SizeType{68 Wd: halfLetterWidthMM,69 Ht: halfLetterHeightMM,70 },71 })72 if err := registerPDFFonts(pdf); err != nil {73 t.Fatalf("registerPDFFonts error: %v", err)74 }75 pdf.AddPage()7677 body := PuzzleBodyRect(halfLetterWidthMM, halfLetterHeightMM, 2)78 lines := wrapInstructionLines(pdf, body.W, []string{79 "No three equal adjacent in any row or column.",80 "Rows/columns have equal 0s and 1s, and all rows/columns are unique.",81 "= means same; x means different.",82 })83 if len(lines) != 3 {84 t.Fatalf("line count = %d, want 3 (%v)", len(lines), lines)85 }86}