diff options
author | Ghislain Rodrigues <git@ghislain-rodrigues.fr> | 2021-03-31 11:08:27 +0200 |
---|---|---|
committer | Mateusz CzapliĆski <czapkofan@gmail.com> | 2021-04-27 09:22:47 +0200 |
commit | 840f23c21d3e692661d6ee574490880d7524f761 (patch) | |
tree | a1f56eefbb9d9af07ea9ffdc3616bbf15fb0489d /up_test.go | |
parent | 88516fde4023aafa335f8da0a12a95bab0f8033a (diff) |
unix-word-rubout erases all the characters before the cursor
until finding either a space or a BOL.
Diffstat (limited to 'up_test.go')
-rw-r--r-- | up_test.go | 92 |
1 files changed, 92 insertions, 0 deletions
@@ -81,3 +81,95 @@ func Test_Editor_insert(t *testing.T) { } } } + +func Test_Editor_unix_word_rubout(t *testing.T) { + tests := []struct { + comment string + e Editor + wantValue []rune + wantKillspace []rune + }{ + { + comment: "unix-word-rubout at beginning of line", + e: Editor{ + value: []rune(`abc`), + cursor: 0, + }, + wantValue: []rune(`abc`), + wantKillspace: []rune(``), + }, + { + comment: "unix-word-rubout at soft beginning of line", + e: Editor{ + value: []rune(` abc`), + cursor: 1, + }, + wantValue: []rune(`abc`), + wantKillspace: []rune(` `), + }, + { + comment: "unix-word-rubout until soft beginning of line", + e: Editor{ + value: []rune(` abc`), + cursor: 2, + }, + wantValue: []rune(` bc`), + wantKillspace: []rune(`a`), + }, + { + comment: "unix-word-rubout until beginning of line", + e: Editor{ + value: []rune(`abc`), + cursor: 2, + }, + wantValue: []rune(`c`), + wantKillspace: []rune(`ab`), + }, + { + comment: "unix-word-rubout in middle of line", + e: Editor{ + value: []rune(`lorem ipsum dolor`), + cursor: 11, + }, + wantValue: []rune(`lorem dolor`), + wantKillspace: []rune(`ipsum`), + }, + { + comment: "unix-word-rubout cursor at beginning of word", + e: Editor{ + value: []rune(`lorem ipsum dolor`), + cursor: 12, + }, + wantValue: []rune(`lorem dolor`), + wantKillspace: []rune(`ipsum `), + }, + { + comment: "unix-word-rubout cursor between multiple spaces", + e: Editor{ + value: []rune(`a b c`), + cursor: 5, + }, + wantValue: []rune(`a c`), + wantKillspace: []rune(`b `), + }, + { + comment: "unix-word-rubout tab as space char (although is it a realistic case in the context of a command line instruction?)", + e: Editor{ + value: []rune(`a b c`), + cursor: 5, + }, + wantValue: []rune(`a c`), + wantKillspace: []rune(`b `), + }, + } + + for _, tt := range tests { + tt.e.unixWordRubout() + if string(tt.e.value) != string(tt.wantValue) { + t.Errorf("%q: bad value\nwant: %q\nhave: %q", tt.comment, tt.wantValue, tt.e.value) + } + if string(tt.e.killspace) != string(tt.wantKillspace) { + t.Errorf("%q: bad value in killspace\nwant: %q\nhave: %q", tt.comment, tt.wantKillspace, tt.e.value) + } + } +} |