| 19 | ) |
| 20 | |
| 21 | func TestPostSummary(t *testing.T) { |
| 22 | testCases := map[string]struct { |
| 23 | given writefreely.Post |
| 24 | expected string |
| 25 | }{ |
| 26 | "no special chars": {givenPost("Content."), "Content."}, |
| 27 | "HTML content": {givenPost("Content <p>with a</p> paragraph."), "Content with a paragraph."}, |
| 28 | "content with escaped char": {givenPost("Content's all OK."), "Content's all OK."}, |
| 29 | "multiline content": {givenPost(`Content |
| 30 | in |
| 31 | multiple |
| 32 | lines.`), "Content in multiple lines."}, |
| 33 | } |
| 34 | |
| 35 | for name, test := range testCases { |
| 36 | t.Run(name, func(t *testing.T) { |
| 37 | actual := test.given.Summary() |
| 38 | assert.Equal(t, test.expected, actual) |
| 39 | }) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func givenPost(content string) writefreely.Post { |
| 44 | return writefreely.Post{Title: zero.StringFrom("Title"), Content: content} |