|
| 1 | +function! s:set_text(lines) |
| 2 | + % delete _ |
| 3 | + put =a:lines |
| 4 | + execute 'normal ggdd' |
| 5 | +endfunction |
| 6 | + |
| 7 | +function! s:get_text() |
| 8 | + return lsp#utils#buffer#_get_lines(bufnr('$')) |
| 9 | +endfunction |
| 10 | + |
| 11 | +Describe lsp#utils#text_edit |
| 12 | + |
| 13 | + Before all |
| 14 | + let s:endofline_backup = &endofline |
| 15 | + set endofline |
| 16 | + End |
| 17 | + |
| 18 | + After all |
| 19 | + let &endofline = s:endofline_backup |
| 20 | + End |
| 21 | + |
| 22 | + Before each |
| 23 | + enew! |
| 24 | + End |
| 25 | + |
| 26 | + Describe lsp#utils#text_edit#apply_text_edits |
| 27 | + It insert newText |
| 28 | + call s:set_text(['foo', 'bar']) |
| 29 | + |
| 30 | + call lsp#utils#text_edit#apply_text_edits( |
| 31 | + \ expand('%'), |
| 32 | + \ [{ |
| 33 | + \ 'range': { |
| 34 | + \ 'start': { |
| 35 | + \ 'line': 1, |
| 36 | + \ 'character': 1 |
| 37 | + \ }, |
| 38 | + \ 'end': { |
| 39 | + \ 'line': 1, |
| 40 | + \ 'character': 1 |
| 41 | + \ } |
| 42 | + \ }, |
| 43 | + \ 'newText': 'baz' |
| 44 | + \ }]) |
| 45 | + |
| 46 | + let l:buffer_text = s:get_text() |
| 47 | + Assert Equals(l:buffer_text, ['foo', 'bbazar', '']) |
| 48 | + End |
| 49 | + |
| 50 | + It insert empty newText |
| 51 | + call s:set_text(['foo', 'bar']) |
| 52 | + |
| 53 | + call lsp#utils#text_edit#apply_text_edits( |
| 54 | + \ expand('%'), |
| 55 | + \ [{ |
| 56 | + \ 'range': { |
| 57 | + \ 'start': { |
| 58 | + \ 'line': 1, |
| 59 | + \ 'character': 1 |
| 60 | + \ }, |
| 61 | + \ 'end': { |
| 62 | + \ 'line': 1, |
| 63 | + \ 'character': 1 |
| 64 | + \ } |
| 65 | + \ }, |
| 66 | + \ 'newText': '' |
| 67 | + \ }]) |
| 68 | + |
| 69 | + let l:buffer_text = s:get_text() |
| 70 | + Assert Equals(l:buffer_text, ['foo', 'bar', '']) |
| 71 | + End |
| 72 | + |
| 73 | + It replace range string to newText |
| 74 | + call s:set_text(['foo', 'bar']) |
| 75 | + |
| 76 | + call lsp#utils#text_edit#apply_text_edits( |
| 77 | + \ expand('%'), |
| 78 | + \ [{ |
| 79 | + \ 'range': { |
| 80 | + \ 'start': { |
| 81 | + \ 'line': 1, |
| 82 | + \ 'character': 0 |
| 83 | + \ }, |
| 84 | + \ 'end': { |
| 85 | + \ 'line': 1, |
| 86 | + \ 'character': 1 |
| 87 | + \ } |
| 88 | + \ }, |
| 89 | + \ 'newText': 'replaced' |
| 90 | + \ }]) |
| 91 | + |
| 92 | + let l:buffer_text = s:get_text() |
| 93 | + Assert Equals(l:buffer_text, ['foo', 'replacedar', '']) |
| 94 | + End |
| 95 | + |
| 96 | + It delete range string |
| 97 | + call s:set_text(['foo', 'bar']) |
| 98 | + |
| 99 | + call lsp#utils#text_edit#apply_text_edits( |
| 100 | + \ expand('%'), |
| 101 | + \ [{ |
| 102 | + \ 'range': { |
| 103 | + \ 'start': { |
| 104 | + \ 'line': 1, |
| 105 | + \ 'character': 0 |
| 106 | + \ }, |
| 107 | + \ 'end': { |
| 108 | + \ 'line': 1, |
| 109 | + \ 'character': 1 |
| 110 | + \ } |
| 111 | + \ }, |
| 112 | + \ 'newText': '' |
| 113 | + \ }]) |
| 114 | + |
| 115 | + let l:buffer_text = s:get_text() |
| 116 | + Assert Equals(l:buffer_text, ['foo', 'ar', '']) |
| 117 | + End |
| 118 | + End |
| 119 | +End |
| 120 | + |
0 commit comments