gemtext_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package gemtext
  2. import (
  3. "servitor/style"
  4. "testing"
  5. )
  6. func TestBasic(t *testing.T) {
  7. input := `> blockquote
  8. * bullet point
  9. # large header
  10. ## smaller header
  11. ### smallest header
  12. => https://www.wikipedia.org/ Wikipedia is great!
  13. =>http://example.org/
  14. ` + "```\ncode block\nhere\n```"
  15. markup, links, err := NewMarkup(input)
  16. if err != nil {
  17. t.Fatal(err)
  18. }
  19. if links[0] != "https://www.wikipedia.org/" {
  20. t.Fatalf("first link should be https://www.wikipedia.org/ not %s", links[0])
  21. }
  22. if links[1] != "http://example.org/" {
  23. t.Fatalf("second link should be http://example.org/ not %s", links[1])
  24. }
  25. output := markup.Render(50)
  26. expected := style.QuoteBlock("blockquote") + "\n\n" +
  27. style.Bullet("bullet point") + "\n\n" +
  28. style.Header("large header", 1) + "\n" +
  29. style.Header("smaller header", 2) + "\n" +
  30. style.Header("smallest header", 3) + "\n\n" +
  31. style.LinkBlock("Wikipedia is great!", 1) + "\n\n" +
  32. style.LinkBlock("http://example.org/", 2) + "\n\n" +
  33. style.CodeBlock("code block\nhere")
  34. if expected != output {
  35. t.Fatalf("expected %s not %s", expected, output)
  36. }
  37. }