summaryrefslogtreecommitdiffstats
path: root/helpers/content_test.go
diff options
context:
space:
mode:
authorbep <bjorn.erik.pedersen@gmail.com>2015-02-05 21:44:15 +0100
committerAnthony Fok <foka@debian.org>2015-02-05 14:04:48 -0700
commit48b6777ea212073d32c3fb59ea3754d5cf8348de (patch)
tree8482e1b2fadfc7a1736e2803dba9e662396efabe /helpers/content_test.go
parent2bee4a157068edcd9a159ee848bec46c061d34b1 (diff)
Fix Truncate
TruncateWordsToWholeSentence knows if the summary is truncated, so let "him" decide. Fixes #880
Diffstat (limited to 'helpers/content_test.go')
-rw-r--r--helpers/content_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/helpers/content_test.go b/helpers/content_test.go
index 6191eb158..44cee2f50 100644
--- a/helpers/content_test.go
+++ b/helpers/content_test.go
@@ -3,6 +3,7 @@ package helpers
import (
"github.com/stretchr/testify/assert"
"html/template"
+ "strings"
"testing"
)
@@ -33,3 +34,30 @@ func TestStripEmptyNav(t *testing.T) {
func TestBytesToHTML(t *testing.T) {
assert.Equal(t, template.HTML("dobedobedo"), BytesToHTML([]byte("dobedobedo")))
}
+
+func TestTruncateWordsToWholeSentence(t *testing.T) {
+ type test struct {
+ input, expected string
+ max int
+ truncated bool
+ }
+ data := []test{
+ {"a b c", "a b c", 12, false},
+ {"a b c", "a b c", 3, false},
+ {"a", "a", 1, false},
+ {"This is a sentence.", "This is a sentence.", 5, false},
+ {"This is also a sentence!", "This is also a sentence!", 1, false},
+ {"To be. Or not to be. That's the question.", "To be.", 1, true},
+ {" \nThis is not a sentence\n ", "This is not a", 4, true},
+ }
+ for i, d := range data {
+ output, truncated := TruncateWordsToWholeSentence(strings.Fields(d.input), d.max)
+ if d.expected != output {
+ t.Errorf("Test %d failed. Expected %q got %q", i, d.expected, output)
+ }
+
+ if d.truncated != truncated {
+ t.Errorf("Test %d failed. Expected truncated=%t got %t", i, d.truncated, truncated)
+ }
+ }
+}