markdown_test.go 942 B

123456789101112131415161718192021222324252627282930313233343536
  1. package markdown
  2. import (
  3. "servitor/style"
  4. "testing"
  5. )
  6. func TestBasic(t *testing.T) {
  7. input := `[Here's a link!](https://wikipedia.org)
  8. ![This is a beautiful image!](https://miro.medium.com/v2/resize:fit:900/0*L31Zh4YhAv3Wokco)
  9. * Nested list
  10. * Nesting`
  11. markup, links, err := NewMarkup(input)
  12. if err != nil {
  13. t.Fatal(err)
  14. }
  15. if links[0] != "https://wikipedia.org" {
  16. t.Fatalf("first link should be https://wikipedia.org not %s", links[0])
  17. }
  18. if links[1] != "https://miro.medium.com/v2/resize:fit:900/0*L31Zh4YhAv3Wokco" {
  19. t.Fatalf("second link should be https://miro.medium.com/v2/resize:fit:900/0*L31Zh4YhAv3Wokco not %s", links[1])
  20. }
  21. output := markup.Render(50)
  22. expected := style.Link("Here's a link!", 1) + "\n\n" +
  23. style.LinkBlock("This is a beautiful image!", 2) + "\n\n" +
  24. style.Bullet("Nested list\n"+style.Bullet("Nesting"))
  25. if expected != output {
  26. t.Fatalf("expected %s not %s", expected, output)
  27. }
  28. }