image_test.go 781 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package parser
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/require"
  5. "github.com/usememos/memos/plugin/gomark/parser/tokenizer"
  6. )
  7. func TestImageParser(t *testing.T) {
  8. tests := []struct {
  9. text string
  10. image *ImageParser
  11. }{
  12. {
  13. text: "![](https://example.com)",
  14. image: &ImageParser{
  15. AltText: "",
  16. URL: "https://example.com",
  17. },
  18. },
  19. {
  20. text: "! [](https://example.com)",
  21. image: nil,
  22. },
  23. {
  24. text: "![alte]( htt ps :/ /example.com)",
  25. image: nil,
  26. },
  27. {
  28. text: "![al te](https://example.com)",
  29. image: &ImageParser{
  30. AltText: "al te",
  31. URL: "https://example.com",
  32. },
  33. },
  34. }
  35. for _, test := range tests {
  36. tokens := tokenizer.Tokenize(test.text)
  37. require.Equal(t, test.image, NewImageParser().Match(tokens))
  38. }
  39. }