code_test.go 584 B

123456789101112131415161718192021222324252627282930313233343536
  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 TestCodeParser(t *testing.T) {
  8. tests := []struct {
  9. text string
  10. code *CodeParser
  11. }{
  12. {
  13. text: "`Hello world!",
  14. code: nil,
  15. },
  16. {
  17. text: "`Hello world!`",
  18. code: &CodeParser{
  19. Content: "Hello world!",
  20. },
  21. },
  22. {
  23. text: "`Hello \nworld!`",
  24. code: nil,
  25. },
  26. }
  27. for _, test := range tests {
  28. tokens := tokenizer.Tokenize(test.text)
  29. code := NewCodeParser()
  30. require.Equal(t, test.code, code.Match(tokens))
  31. }
  32. }