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

Fixed a fundamental bug where ^ would always match.

The engine was always passing a string sliced to the current position,
resulting in ^ always matching. Switched to use
FindRunesMatchStartingAt.

Fixes #242.
This commit is contained in:
Alec Thomas
2019-06-09 21:43:16 +10:00
parent 6e1e5df187
commit ea14dd8660
7 changed files with 130 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import (
"testing"
"github.com/alecthomas/assert"
"github.com/stretchr/testify/require"
)
func TestNewlineAtEndOfFile(t *testing.T) {
@ -25,3 +26,21 @@ func TestNewlineAtEndOfFile(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, []Token{{Error, "hello"}}, it.Tokens())
}
func TestMatchingAtStart(t *testing.T) {
l := Coalesce(MustNewLexer(&Config{}, Rules{
"root": {
{`\s+`, Whitespace, nil},
{`^-`, Punctuation, Push("directive")},
{`->`, Operator, nil},
},
"directive": {
{"module", NameEntity, Pop(1)},
},
}))
it, err := l.Tokenise(nil, `-module ->`)
assert.NoError(t, err)
require.Equal(t,
[]Token{{Punctuation, "-"}, {NameEntity, "module"}, {Whitespace, " "}, {Operator, "->"}},
it.Tokens())
}