Added the general modules test files
authorOwen Waller <o.waller@kulawe.com>
Wed, 10 Sep 2014 17:30:03 +0000 (18:30 +0100)
committerspf13 <steve.francia@gmail.com>
Tue, 4 Nov 2014 16:13:41 +0000 (11:13 -0500)
Added the new general module's test file, general_test.go. This replaces the
helpers_test.go file.

There is also a minor defect fix in general.go's StripHTML function.
The correct xhtml tag for a break is <br /> not </br>. I've also removed
the unnecessary spaces before the replacement "\n".

The new test module also reflects this change.

Conflicts:
helpers/general.go

helpers/content.go
helpers/general_test.go [new file with mode: 0644]

index 802187bc4dc4c37dd2c11fe2f02517291911e841..96e84e5cfd72e705f5d5917617bb83cf7cc1285b 100644 (file)
@@ -37,9 +37,9 @@ func StripHTML(s string) string {
                output = s
        } else {
                s = strings.Replace(s, "\n", " ", -1)
-               s = strings.Replace(s, "</p>", " \n", -1)
-               s = strings.Replace(s, "<br>", " \n", -1)
-               s = strings.Replace(s, "</br>", " \n", -1)
+               s = strings.Replace(s, "</p>", "\n", -1)
+               s = strings.Replace(s, "<br>", "\n", -1)
+               s = strings.Replace(s, "<br />", "\n", -1) // <br /> is the xhtml line break tag
 
                // Walk through the string removing all tags
                b := new(bytes.Buffer)
diff --git a/helpers/general_test.go b/helpers/general_test.go
new file mode 100644 (file)
index 0000000..18cdfcc
--- /dev/null
@@ -0,0 +1,22 @@
+package helpers
+
+import (
+       "testing"
+)
+
+func TestStripHTML(t *testing.T) {
+       type test struct {
+               input, expected string
+       }
+       data := []test{
+               {"<h1>strip h1 tag <h1>", "strip h1 tag "},
+               {"<p> strip p tag </p>", " strip p tag \n"},
+               {"</br> strip br<br>", " strip br\n"},
+       }
+       for i, d := range data {
+               output := StripHTML(d.input)
+               if d.expected != output {
+                       t.Errorf("Test %d failed. Expected %q got %q", i, d.expected, output)
+               }
+       }
+}