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

Add support for line numbers.

This commit is contained in:
Alec Thomas
2017-09-20 13:30:46 +10:00
parent feb78ed6f3
commit 3f230ec717
7 changed files with 298 additions and 171 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma/lexers"
"github.com/alecthomas/chroma/styles"
)
@ -27,3 +28,26 @@ func BenchmarkHTMLFormatter(b *testing.B) {
assert.NoError(b, err)
}
}
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)
}