...

Source file src/github.com/alecthomas/chroma/remap_test.go

Documentation: github.com/alecthomas/chroma

     1  package chroma
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestRemappingLexer(t *testing.T) {
    10  	var lexer Lexer = MustNewLexer(nil, Rules{ // nolint: forbidigo
    11  		"root": {
    12  			{`\s+`, Whitespace, nil},
    13  			{`\w+`, Name, nil},
    14  		},
    15  	})
    16  	lexer = TypeRemappingLexer(lexer, TypeMapping{
    17  		{Name, Keyword, []string{"if", "else"}},
    18  	})
    19  
    20  	it, err := lexer.Tokenise(nil, `if true then print else end`)
    21  	assert.NoError(t, err)
    22  	expected := []Token{
    23  		{Keyword, "if"}, {TextWhitespace, " "}, {Name, "true"}, {TextWhitespace, " "}, {Name, "then"},
    24  		{TextWhitespace, " "}, {Name, "print"}, {TextWhitespace, " "}, {Keyword, "else"},
    25  		{TextWhitespace, " "}, {Name, "end"},
    26  	}
    27  	actual := it.Tokens()
    28  	assert.Equal(t, expected, actual)
    29  }
    30  

View as plain text