github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/cmds/elvish/edit/completion/complete_command_test.go (about)

     1  package completion
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/u-root/u-root/cmds/elvish/parse"
     7  )
     8  
     9  func TestFindCommandComplContext(t *testing.T) {
    10  	testComplContextFinder(t, "findCommandComplContext", findCommandComplContext, []complContextFinderTest{
    11  		// Very beginning, empty seed
    12  		{"", &commandComplContext{
    13  			complContextCommon{"", quotingForEmptySeed, 0, 0}}},
    14  		// Very beginning, nonempty seed
    15  		{"a", &commandComplContext{
    16  			complContextCommon{"a", parse.Bareword, 0, 1}}},
    17  		// Very beginning, nonempty seed with quoting
    18  		{`"a"`, &commandComplContext{
    19  			complContextCommon{"a", parse.DoubleQuoted, 0, 3}}},
    20  		// Very beginning, nonempty seed with partial quoting
    21  		{`"a`, &commandComplContext{
    22  			complContextCommon{"a", parse.DoubleQuoted, 0, 2}}},
    23  
    24  		// Beginning of output capture, empty seed
    25  		{"a (", &commandComplContext{
    26  			complContextCommon{"", quotingForEmptySeed, 3, 3}}},
    27  		// Beginning of output capture, nonempty seed
    28  		{"a (b", &commandComplContext{
    29  			complContextCommon{"b", parse.Bareword, 3, 4}}},
    30  
    31  		// Beginning of exception capture, empty seed
    32  		{"a ?(", &commandComplContext{
    33  			complContextCommon{"", quotingForEmptySeed, 4, 4}}},
    34  		// Beginning of exception capture, nonempty seed
    35  		{"a ?(b", &commandComplContext{
    36  			complContextCommon{"b", parse.Bareword, 4, 5}}},
    37  
    38  		// Beginning of lambda, empty seed
    39  		{"a { ", &commandComplContext{
    40  			complContextCommon{"", quotingForEmptySeed, 4, 4}}},
    41  		// Beginning of lambda, nonempty seed
    42  		{"a { b", &commandComplContext{
    43  			complContextCommon{"b", parse.Bareword, 4, 5}}},
    44  
    45  		// After another command and pipe, empty seed
    46  		{"a|", &commandComplContext{
    47  			complContextCommon{"", quotingForEmptySeed, 2, 2}}},
    48  		// After another command and pipe, nonempty seed
    49  		{"a|b", &commandComplContext{
    50  			complContextCommon{"b", parse.Bareword, 2, 3}}},
    51  
    52  		// After another pipeline, empty seed
    53  		{"a\n", &commandComplContext{
    54  			complContextCommon{"", quotingForEmptySeed, 2, 2}}},
    55  		// After another pipeline, nonempty seed
    56  		{"a\nb", &commandComplContext{
    57  			complContextCommon{"b", parse.Bareword, 2, 3}}},
    58  	})
    59  }