github.com/aretext/aretext@v1.3.0/syntax/languages/gitrebase_test.go (about)

     1  package languages
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/aretext/aretext/syntax/parser"
     9  )
    10  
    11  func TestGitRebaseParseFunc(t *testing.T) {
    12  	testCases := []struct {
    13  		name     string
    14  		text     string
    15  		expected []TokenWithText
    16  	}{
    17  		{
    18  			name: "comment",
    19  			text: "# Rebase 5c828d6..bb41094 onto 5c828d6 (1 command)",
    20  			expected: []TokenWithText{
    21  				{
    22  					Text: "# Rebase 5c828d6..bb41094 onto 5c828d6 (1 command)",
    23  					Role: parser.TokenRoleComment,
    24  				},
    25  			},
    26  		},
    27  		{
    28  			name: "keyword at start of line",
    29  			text: "pick bc51064 Test commit",
    30  			expected: []TokenWithText{
    31  				{
    32  					Text: "pick",
    33  					Role: parser.TokenRoleKeyword,
    34  				},
    35  			},
    36  		},
    37  		{
    38  			name: "keyword past start of line",
    39  			text: "edit reword pick",
    40  			expected: []TokenWithText{
    41  				{
    42  					Text: "edit",
    43  					Role: parser.TokenRoleKeyword,
    44  				},
    45  			},
    46  		},
    47  		{
    48  			name:     "keyword prefix of another word",
    49  			text:     "pi",
    50  			expected: []TokenWithText{},
    51  		},
    52  		{
    53  			name: "keyword after newline",
    54  			text: "\nreword test",
    55  			expected: []TokenWithText{
    56  				{
    57  					Text: "reword",
    58  					Role: parser.TokenRoleKeyword,
    59  				},
    60  			},
    61  		},
    62  		{
    63  			name: "comment in commit message",
    64  			text: "pick insert # in file",
    65  			expected: []TokenWithText{
    66  				{
    67  					Text: "pick",
    68  					Role: parser.TokenRoleKeyword,
    69  				},
    70  			},
    71  		},
    72  	}
    73  
    74  	for _, tc := range testCases {
    75  		t.Run(tc.name, func(t *testing.T) {
    76  			tokens := ParseTokensWithText(GitRebaseParseFunc(), tc.text)
    77  			assert.Equal(t, tc.expected, tokens)
    78  		})
    79  	}
    80  }