mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-19 21:10:15 +02:00
Add test for EnsureNL.
This commit is contained in:
parent
27733ac753
commit
6326cbaeff
27
regexp_test.go
Normal file
27
regexp_test.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package chroma
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/alecthomas/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewlineAtEndOfFile(t *testing.T) {
|
||||||
|
l := Coalesce(MustNewLexer(&Config{EnsureNL: true}, Rules{
|
||||||
|
"root": {
|
||||||
|
{`(\w+)(\n)`, ByGroups(Keyword, Whitespace), nil},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
it, err := l.Tokenise(nil, `hello`)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []*Token{{Keyword, "hello"}, {Whitespace, "\n"}}, it.Tokens())
|
||||||
|
|
||||||
|
l = Coalesce(MustNewLexer(nil, Rules{
|
||||||
|
"root": {
|
||||||
|
{`(\w+)(\n)`, ByGroups(Keyword, Whitespace), nil},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
it, err = l.Tokenise(nil, `hello`)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []*Token{{Error, "hello"}}, it.Tokens())
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user