2017-07-19 23:51:16 -07:00
|
|
|
package html
|
|
|
|
|
|
|
|
import (
|
2017-09-19 23:04:10 +10:00
|
|
|
"io/ioutil"
|
2017-07-19 23:51:16 -07:00
|
|
|
"testing"
|
|
|
|
|
2017-09-19 23:04:10 +10:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2017-09-20 13:30:46 +10:00
|
|
|
"github.com/alecthomas/chroma"
|
2017-09-19 23:04:10 +10:00
|
|
|
"github.com/alecthomas/chroma/lexers"
|
|
|
|
"github.com/alecthomas/chroma/styles"
|
2017-07-19 23:51:16 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCompressStyle(t *testing.T) {
|
2017-09-18 14:19:59 +10:00
|
|
|
style := "color: #888888; background-color: #faffff"
|
2017-07-19 23:51:16 -07:00
|
|
|
actual := compressStyle(style)
|
2017-09-18 14:19:59 +10:00
|
|
|
expected := "color:#888;background-color:#faffff"
|
2017-09-19 23:04:10 +10:00
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkHTMLFormatter(b *testing.B) {
|
|
|
|
formatter := New()
|
|
|
|
writer, err := formatter.Format(ioutil.Discard, styles.Fallback)
|
|
|
|
assert.NoError(b, err)
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
err = lexers.Go.Tokenise(nil, "package main\nfunc main()\n{\nprintln(`hello world`)\n}\n", writer)
|
|
|
|
assert.NoError(b, err)
|
|
|
|
}
|
2017-07-19 23:51:16 -07:00
|
|
|
}
|
2017-09-20 13:30:46 +10:00
|
|
|
|
|
|
|
func TestSplitTokensIntoLines(t *testing.T) {
|
|
|
|
in := []*chroma.Token{
|
|
|
|
{Value: "hello", Type: chroma.NameKeyword},
|
|
|
|
{Value: " world\nwhat?\n", Type: chroma.NameKeyword},
|
|
|
|
{Type: chroma.EOF},
|
|
|
|
}
|
|
|
|
expected := [][]*chroma.Token{
|
|
|
|
[]*chroma.Token{
|
|
|
|
{Type: chroma.NameKeyword, Value: "hello"},
|
|
|
|
{Type: chroma.NameKeyword, Value: " world\n"},
|
|
|
|
},
|
|
|
|
[]*chroma.Token{
|
|
|
|
{Type: chroma.NameKeyword, Value: "what?\n"},
|
|
|
|
},
|
|
|
|
[]*chroma.Token{
|
|
|
|
{Type: chroma.NameKeyword},
|
|
|
|
{Type: chroma.EOF},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
actual := splitTokensIntoLines(in)
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|