Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 1 | " Test for textobjects |
| 2 | |
| 3 | if !has('textobjects') |
| 4 | finish |
| 5 | endif |
| 6 | |
Bram Moolenaar | c3c766e | 2017-03-08 22:55:19 +0100 | [diff] [blame] | 7 | set belloff=all |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 8 | func CpoM(line, useM, expected) |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 9 | new |
| 10 | |
| 11 | if a:useM |
| 12 | set cpoptions+=M |
| 13 | else |
| 14 | set cpoptions-=M |
| 15 | endif |
| 16 | |
| 17 | call setline(1, a:line) |
| 18 | |
| 19 | call setreg('"', '') |
| 20 | normal! ggfrmavi)y |
| 21 | call assert_equal(getreg('"'), a:expected[0]) |
| 22 | |
| 23 | call setreg('"', '') |
| 24 | normal! `afbmavi)y |
| 25 | call assert_equal(getreg('"'), a:expected[1]) |
| 26 | |
| 27 | call setreg('"', '') |
| 28 | normal! `afgmavi)y |
| 29 | call assert_equal(getreg('"'), a:expected[2]) |
| 30 | |
| 31 | q! |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 32 | endfunc |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 33 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 34 | func Test_inner_block_without_cpo_M() |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 35 | call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', '']) |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 36 | endfunc |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 37 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 38 | func Test_inner_block_with_cpo_M_left_backslash() |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 39 | call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green']) |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 40 | endfunc |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 41 | |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 42 | func Test_inner_block_with_cpo_M_right_backslash() |
Bram Moolenaar | 00b24be | 2016-07-23 22:04:47 +0200 | [diff] [blame] | 43 | call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green']) |
Bram Moolenaar | c5e2b04 | 2017-06-05 16:37:07 +0200 | [diff] [blame] | 44 | endfunc |
| 45 | |
| 46 | func Test_quote_selection_selection_exclusive() |
| 47 | new |
| 48 | call setline(1, "a 'bcde' f") |
| 49 | set selection=exclusive |
| 50 | exe "norm! fdvhi'y" |
| 51 | call assert_equal('bcde', @") |
| 52 | set selection&vim |
| 53 | bw! |
| 54 | endfunc |
Bram Moolenaar | db51007 | 2017-09-28 21:52:17 +0200 | [diff] [blame^] | 55 | |
| 56 | " Tests for string and html text objects |
| 57 | func Test_string_html_objects() |
| 58 | enew! |
| 59 | |
| 60 | let t = '"wo\"rd\\" foo' |
| 61 | put =t |
| 62 | normal! da" |
| 63 | call assert_equal('foo', getline('.')) |
| 64 | |
| 65 | let t = "'foo' 'bar' 'piep'" |
| 66 | put =t |
| 67 | normal! 0va'a'rx |
| 68 | call assert_equal("xxxxxxxxxxxx'piep'", getline('.')) |
| 69 | |
| 70 | let t = "bla bla `quote` blah" |
| 71 | put =t |
| 72 | normal! 02f`da` |
| 73 | call assert_equal("bla bla blah", getline('.')) |
| 74 | |
| 75 | let t = 'out " in "noXno"' |
| 76 | put =t |
| 77 | normal! 0fXdi" |
| 78 | call assert_equal('out " in ""', getline('.')) |
| 79 | |
| 80 | let t = "\"'\" 'blah' rep 'buh'" |
| 81 | put =t |
| 82 | normal! 03f'vi'ry |
| 83 | call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.')) |
| 84 | |
| 85 | set quoteescape=+*- |
| 86 | let t = "bla `s*`d-`+++`l**` b`la" |
| 87 | put =t |
| 88 | normal! di` |
| 89 | call assert_equal("bla `` b`la", getline('.')) |
| 90 | |
| 91 | let t = 'voo "nah" sdf " asdf" sdf " sdf" sd' |
| 92 | put =t |
| 93 | normal! $F"va"oha"i"rz |
| 94 | call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.')) |
| 95 | |
| 96 | let t = "-<b>asdf<i>Xasdf</i>asdf</b>-" |
| 97 | put =t |
| 98 | normal! fXdit |
| 99 | call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.')) |
| 100 | |
| 101 | let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-" |
| 102 | put =t |
| 103 | normal! 0fXdit |
| 104 | call assert_equal('-<b></b>-', getline('.')) |
| 105 | |
| 106 | let t = "-<b>asdf<i>Xasdf</i>asdf</b>-" |
| 107 | put =t |
| 108 | normal! fXdat |
| 109 | call assert_equal('-<b>asdfasdf</b>-', getline('.')) |
| 110 | |
| 111 | let t = "-<b>asdX<i>as<b />df</i>asdf</b>-" |
| 112 | put =t |
| 113 | normal! 0fXdat |
| 114 | call assert_equal('--', getline('.')) |
| 115 | |
| 116 | let t = "-<b>\ninnertext object\n</b>" |
| 117 | put =t |
| 118 | normal! dit |
| 119 | call assert_equal('-<b></b>', getline('.')) |
| 120 | |
| 121 | set quoteescape& |
| 122 | enew! |
| 123 | endfunc |
| 124 | |
| 125 | " Tests for match() and matchstr() |
| 126 | func Test_match() |
| 127 | call assert_equal("b", matchstr("abcd", ".", 0, 2)) |
| 128 | call assert_equal("bc", matchstr("abcd", "..", 0, 2)) |
| 129 | call assert_equal("c", matchstr("abcd", ".", 2, 0)) |
| 130 | call assert_equal("a", matchstr("abcd", ".", 0, -1)) |
| 131 | call assert_equal(-1, match("abcd", ".", 0, 5)) |
| 132 | call assert_equal(0 , match("abcd", ".", 0, -1)) |
| 133 | call assert_equal(0 , match('abc', '.', 0, 1)) |
| 134 | call assert_equal(1 , match('abc', '.', 0, 2)) |
| 135 | call assert_equal(2 , match('abc', '.', 0, 3)) |
| 136 | call assert_equal(-1, match('abc', '.', 0, 4)) |
| 137 | call assert_equal(1 , match('abc', '.', 1, 1)) |
| 138 | call assert_equal(2 , match('abc', '.', 2, 1)) |
| 139 | call assert_equal(-1, match('abc', '.', 3, 1)) |
| 140 | call assert_equal(3 , match('abc', '$', 0, 1)) |
| 141 | call assert_equal(-1, match('abc', '$', 0, 2)) |
| 142 | call assert_equal(3 , match('abc', '$', 1, 1)) |
| 143 | call assert_equal(3 , match('abc', '$', 2, 1)) |
| 144 | call assert_equal(3 , match('abc', '$', 3, 1)) |
| 145 | call assert_equal(-1, match('abc', '$', 4, 1)) |
| 146 | call assert_equal(0 , match('abc', '\zs', 0, 1)) |
| 147 | call assert_equal(1 , match('abc', '\zs', 0, 2)) |
| 148 | call assert_equal(2 , match('abc', '\zs', 0, 3)) |
| 149 | call assert_equal(3 , match('abc', '\zs', 0, 4)) |
| 150 | call assert_equal(-1, match('abc', '\zs', 0, 5)) |
| 151 | call assert_equal(1 , match('abc', '\zs', 1, 1)) |
| 152 | call assert_equal(2 , match('abc', '\zs', 2, 1)) |
| 153 | call assert_equal(3 , match('abc', '\zs', 3, 1)) |
| 154 | call assert_equal(-1, match('abc', '\zs', 4, 1)) |
| 155 | endfunc |