A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

36 lines
928 B

  1. package writefreely_test
  2. import (
  3. "testing"
  4. "github.com/guregu/null/zero"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/writeas/writefreely"
  7. )
  8. func TestPostSummary(t *testing.T) {
  9. testCases := map[string]struct {
  10. given writefreely.Post
  11. expected string
  12. }{
  13. "no special chars": {givenPost("Content."), "Content."},
  14. "HTML content": {givenPost("Content <p>with a</p> paragraph."), "Content with a paragraph."},
  15. "content with escaped char": {givenPost("Content&#39;s all OK."), "Content's all OK."},
  16. "multiline content": {givenPost(`Content
  17. in
  18. multiple
  19. lines.`), "Content in multiple lines."},
  20. }
  21. for name, test := range testCases {
  22. t.Run(name, func(t *testing.T) {
  23. actual := test.given.Summary()
  24. assert.Equal(t, test.expected, actual)
  25. })
  26. }
  27. }
  28. func givenPost(content string) writefreely.Post {
  29. return writefreely.Post{Title: zero.StringFrom("Title"), Content: content}
  30. }