1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-07-01 00:35:06 +02:00

Switch to an Iterator interface.

This is to solve an issue where writers returned by the Formatter
were often stateful, but this fact was not obvious to the API consumer,
and failed in interesting ways.
This commit is contained in:
Alec Thomas
2017-09-20 22:19:36 +10:00
parent 36ead7258a
commit cc0e4a59ab
20 changed files with 215 additions and 129 deletions

View File

@ -20,11 +20,11 @@ func TestCompressStyle(t *testing.T) {
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)
it, err := lexers.Go.Tokenise(nil, "package main\nfunc main()\n{\nprintln(`hello world`)\n}\n")
assert.NoError(b, err)
err = formatter.Format(ioutil.Discard, styles.Fallback, it)
assert.NoError(b, err)
}
}
@ -33,7 +33,6 @@ 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{
@ -45,7 +44,6 @@ func TestSplitTokensIntoLines(t *testing.T) {
},
[]*chroma.Token{
{Type: chroma.NameKeyword},
{Type: chroma.EOF},
},
}
actual := splitTokensIntoLines(in)