github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/readline/vimdelete_test.go (about)

     1  package readline
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/test/count"
     7  )
     8  
     9  // TestViDeleteByAdjustLogicNoPanic just tests that viDeleteByAdjust() doesn't cause
    10  // a panic:
    11  // https://github.com/lmorg/murex/issues/341
    12  
    13  type TestViDeleteByAdjustT struct {
    14  	Line   string
    15  	Pos    int
    16  	Adjust int
    17  }
    18  
    19  func TestViDeleteByAdjustLogicNoPanic(t *testing.T) {
    20  
    21  	tests := []TestViDeleteByAdjustT{
    22  		{
    23  			Line:   "The quick brown fox",
    24  			Pos:    0,
    25  			Adjust: -1,
    26  		},
    27  		{
    28  			Line:   "The quick brown fox",
    29  			Pos:    1,
    30  			Adjust: -1,
    31  		},
    32  		{
    33  			Line:   "The quick brown fox",
    34  			Pos:    1,
    35  			Adjust: -2,
    36  		},
    37  		{
    38  			Line:   "The quick brown fox",
    39  			Pos:    2,
    40  			Adjust: -2,
    41  		},
    42  		{
    43  			Line:   "The quick brown fox",
    44  			Pos:    5,
    45  			Adjust: -1,
    46  		},
    47  		{
    48  			Line:   "The quick brown fox",
    49  			Pos:    5,
    50  			Adjust: 1,
    51  		},
    52  		{
    53  			Line:   "The quick brown fox",
    54  			Pos:    5,
    55  			Adjust: 100,
    56  		},
    57  	}
    58  
    59  	count.Tests(t, len(tests))
    60  
    61  	for _, test := range tests {
    62  		rl := NewInstance()
    63  		rl.line.Set(rl, []rune(test.Line))
    64  		rl.line.SetRunePos(test.Pos)
    65  		rl.viDeleteByAdjustLogic(&test.Adjust)
    66  	}
    67  }