Skip to content

Commit

Permalink
fix highlight tests from previous change
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jan 25, 2018
1 parent 1ca9b5b commit 514a3ad
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 56 deletions.
41 changes: 17 additions & 24 deletions html_highlight_test.go
Original file line number Diff line number Diff line change
@@ -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(`
<pre><code>
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
}
</code></pre>

<pre><code class="language-yaml">
foo: bar
list:
- 1
- 2
</code></pre>
func TestSyntaxHighlight(t *testing.T) {
in := fixture(t, "highlight_input.html")
out := fixture(t, "highlight_output.html")

<pre><code>
this is not even a lang
</code></pre>
`))
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)
}
}
32 changes: 0 additions & 32 deletions testdata/code.html

This file was deleted.

18 changes: 18 additions & 0 deletions testdata/highlight_input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<pre><code>
package main

func main() {
fmt.Println("foo")
}
</code></pre>

<pre><code class="language-yaml">
foo: bar
list:
- 1
- 2
</code></pre>

<pre><code>
this is not even a lang
</code></pre>
17 changes: 17 additions & 0 deletions testdata/highlight_output.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html><head></head><body><pre class="chroma"><span class="kn">package</span> <span class="nx">main</span>

<span class="kd">func</span> <span class="nx">main</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">&#34;foo&#34;</span><span class="p">)</span>
<span class="p">}</span>
</pre>

<pre class="chroma"><span class="w">
</span><span class="w"></span>foo<span class="p">:</span><span class="w"> </span>bar<span class="w">
</span><span class="w"></span>list<span class="p">:</span><span class="w">
</span><span class="w"></span>-<span class="w"> </span><span class="m">1</span><span class="w">
</span><span class="w"></span>-<span class="w"> </span><span class="m">2</span><span class="w">
</span><span class="w"></span></pre>

<pre class="chroma">this is not even a lang
</pre>
</body></html>

0 comments on commit 514a3ad

Please sign in to comment.