package export_test import ( "os" "testing" "github.com/carlosframework/docs/internal/export" ) // TestWriteSamplePDF is a development aid, not a gate: with // $DOCS_PDF_SAMPLE set to a path, it writes a PDF there so a person // (or a browser drive) can open it in a real reader. Skipped // otherwise, so it costs the gate nothing. // // It exists because everything else in this package checks the PDF // with this package's own reader (pdfread_test.go), and a writer and a // reader that agree with each other can still both be wrong about the // specification. Opening the output in something nobody here wrote is // the only check that closes that gap. func TestWriteSamplePDF(t *testing.T) { path := os.Getenv("DOCS_PDF_SAMPLE") if path == "" { t.Skip("set DOCS_PDF_SAMPLE= to write a sample PDF") } js := `{"type":"doc","content":[ {"type":"heading","attrs":{"level":2},"content":[{"type":"text","text":"What the exporter can set"}]}, {"type":"paragraph","content":[ {"type":"text","text":"Ordinary prose, with "}, {"type":"text","text":"bold","marks":[{"type":"strong"}]}, {"type":"text","text":", "}, {"type":"text","text":"italic","marks":[{"type":"em"}]}, {"type":"text","text":", and "}, {"type":"text","text":"code()","marks":[{"type":"code"}]}, {"type":"text","text":" in it. Accents (café, naïve, Zoë) and punctuation the web is full of — em dashes, “curly quotes” — come through the same path."} ]}, {"type":"paragraph","content":[ {"type":"text","text":"This sentence is set in the serif face","marks":[{"type":"font_serif"}]}, {"type":"text","text":", this one is larger","marks":[{"type":"size_lg"}]}, {"type":"text","text":", and this one is small.","marks":[{"type":"size_sm"}]} ]}, {"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Lists"}]}, {"type":"bullet_list","content":[ {"type":"list_item","content":[{"type":"paragraph","content":[{"type":"text","text":"A bullet, long enough that it has to wrap onto a second line so the hanging indent is visible and can be judged rather than assumed."}]}]}, {"type":"list_item","content":[ {"type":"paragraph","content":[{"type":"text","text":"A bullet with a list inside it"}]}, {"type":"ordered_list","content":[ {"type":"list_item","content":[{"type":"paragraph","content":[{"type":"text","text":"First"}]}]}, {"type":"list_item","content":[{"type":"paragraph","content":[{"type":"text","text":"Second"}]}]} ]} ]} ]}, {"type":"blockquote","content":[ {"type":"paragraph","content":[{"type":"text","text":"A quotation, set italic and grey with a rule down its left edge, long enough to wrap so the rule can be seen to run the whole height of it rather than only beside the first line."}]} ]}, {"type":"paragraph","content":[{"type":"text","text":"A closing paragraph."}]} ]}` doc, err := export.Parse("Sample document", js) if err != nil { t.Fatal(err) } data, report, err := export.PDF(doc) if err != nil { t.Fatal(err) } if err := os.WriteFile(path, data, 0o644); err != nil { t.Fatal(err) } t.Logf("wrote %s (%d bytes), %s", path, len(data), report) }