From 72a5579d836ef1cfa4ca7321a5310cab70966ed7 Mon Sep 17 00:00:00 2001 From: makpoc Date: Mon, 19 Oct 2015 13:51:49 +0300 Subject: [PATCH] Cover the rest of the (not one-liner) functions in context --- middleware/context_test.go | 132 +++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/middleware/context_test.go b/middleware/context_test.go index be8d0c378..8933134d8 100644 --- a/middleware/context_test.go +++ b/middleware/context_test.go @@ -380,6 +380,138 @@ func TestPathMatches(t *testing.T) { } } +func TestTruncate(t *testing.T) { + context := getContextOrFail(t) + tests := []struct { + inputString string + inputLength int + expected string + }{ + // Test 0 - small length + { + inputString: "string", + inputLength: 1, + expected: "s", + }, + // Test 1 - exact length + { + inputString: "string", + inputLength: 6, + expected: "string", + }, + // Test 2 - bigger length + { + inputString: "string", + inputLength: 10, + expected: "string", + }, + } + + for i, test := range tests { + actual := context.Truncate(test.inputString, test.inputLength) + if actual != test.expected { + t.Errorf(getTestPrefix(i)+"Expected %s, found %s. Input was Truncate(%q, %d)", test.expected, actual, test.inputString, test.inputLength) + } + } +} + +func TestStripHTML(t *testing.T) { + context := getContextOrFail(t) + tests := []struct { + input string + expected string + }{ + // Test 0 - no tags + { + input: `h1`, + expected: `h1`, + }, + // Test 1 - happy path + { + input: `

h1

`, + expected: `h1`, + }, + // Test 2 - tag in quotes + { + input: `">h1`, + expected: `h1`, + }, + // Test 3 - multiple tags + { + input: `

h1

`, + expected: `h1`, + }, + // Test 4 - tags not closed + { + input: `hi`, + expected: `