diff --git a/html_highlight_test.go b/html_highlight_test.go index f88cd13..e9a18c6 100644 --- a/html_highlight_test.go +++ b/html_highlight_test.go @@ -1,38 +1,31 @@ package static import ( + "io" "io/ioutil" - "strings" + "os" + "path/filepath" "testing" -) -func TestSyntaxHighlight(t *testing.T) { - r := ioutil.NopCloser(strings.NewReader(` -

-package main
+	"github.com/tj/assert"
+)
 
-func main() {
-	fmt.Println("foo")
+func fixture(t testing.TB, name string) io.ReadCloser {
+	path := filepath.Join("testdata", name)
+	f, err := os.Open(path)
+	assert.NoError(t, err, "open")
+	return f
 }
-
-

-foo: bar
-list:
-- 1
-- 2
-
+func TestSyntaxHighlight(t *testing.T) { + in := fixture(t, "highlight_input.html") + out := fixture(t, "highlight_output.html") -

-this is not even a lang
-
- `)) + got, _ := ioutil.ReadAll(SyntaxHighlight(in)) + expect, _ := ioutil.ReadAll(out) - r = SyntaxHighlight(r) - got, _ := ioutil.ReadAll(r) - expect, _ := ioutil.ReadFile("testdata/code.html") if string(got) != string(expect) { - t.Errorf("expected %s but got %s", string(expect), string(got)) - // ioutil.WriteFile("testdata/code.html", got, 0644) + t.Errorf("\nExpected:\n\n%s\n\nGot:\n\n%s", string(expect), string(got)) + // ioutil.WriteFile("testdata/highlight_output.html", got, 0644) } } diff --git a/testdata/code.html b/testdata/code.html deleted file mode 100644 index 4636877..0000000 --- a/testdata/code.html +++ /dev/null @@ -1,32 +0,0 @@ - - -
package main
-
-func main() {
-	fmt.Println("foo")
-}
-
- - - - - - -

-foo: bar
-list:
-- 1
-- 2
-
- - - - - - -
this is not even a lang
-
- - - - \ No newline at end of file diff --git a/testdata/highlight_input.html b/testdata/highlight_input.html new file mode 100644 index 0000000..b0533cf --- /dev/null +++ b/testdata/highlight_input.html @@ -0,0 +1,18 @@ +

+package main
+
+func main() {
+	fmt.Println("foo")
+}
+
+ +

+foo: bar
+list:
+- 1
+- 2
+
+ +

+this is not even a lang
+
diff --git a/testdata/highlight_output.html b/testdata/highlight_output.html new file mode 100644 index 0000000..86cba33 --- /dev/null +++ b/testdata/highlight_output.html @@ -0,0 +1,17 @@ +
package main
+
+func main() {
+	fmt.Println("foo")
+}
+
+ +

+foo: bar
+list:
+- 1
+- 2
+
+ +
this is not even a lang
+
+ \ No newline at end of file