A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

46 wiersze
1.2 KiB

  1. /*
  2. * Copyright © 2020-2021 Musing Studio LLC.
  3. *
  4. * This file is part of WriteFreely.
  5. *
  6. * WriteFreely is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License, included
  8. * in the LICENSE file in this source code package.
  9. */
  10. package writefreely_test
  11. import (
  12. "testing"
  13. "github.com/guregu/null/zero"
  14. "github.com/stretchr/testify/assert"
  15. "github.com/writefreely/writefreely"
  16. )
  17. func TestPostSummary(t *testing.T) {
  18. testCases := map[string]struct {
  19. given writefreely.Post
  20. expected string
  21. }{
  22. "no special chars": {givenPost("Content."), "Content."},
  23. "HTML content": {givenPost("Content <p>with a</p> paragraph."), "Content with a paragraph."},
  24. "content with escaped char": {givenPost("Content&#39;s all OK."), "Content's all OK."},
  25. "multiline content": {givenPost(`Content
  26. in
  27. multiple
  28. lines.`), "Content in multiple lines."},
  29. }
  30. for name, test := range testCases {
  31. t.Run(name, func(t *testing.T) {
  32. actual := test.given.Summary()
  33. assert.Equal(t, test.expected, actual)
  34. })
  35. }
  36. }
  37. func givenPost(content string) writefreely.Post {
  38. return writefreely.Post{Title: zero.StringFrom("Title"), Content: content}
  39. }