Bram Moolenaar | 08243d2 | 2017-01-10 16:12:29 +0100 | [diff] [blame] | 1 | " Tests for various functions. |
| 2 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 3 | func Test_empty() |
| 4 | call assert_equal(1, empty('')) |
| 5 | call assert_equal(0, empty('a')) |
| 6 | |
| 7 | call assert_equal(1, empty(0)) |
| 8 | call assert_equal(1, empty(-0)) |
| 9 | call assert_equal(0, empty(1)) |
| 10 | call assert_equal(0, empty(-1)) |
| 11 | |
| 12 | call assert_equal(1, empty(0.0)) |
| 13 | call assert_equal(1, empty(-0.0)) |
| 14 | call assert_equal(0, empty(1.0)) |
| 15 | call assert_equal(0, empty(-1.0)) |
| 16 | call assert_equal(0, empty(1.0/0.0)) |
| 17 | call assert_equal(0, empty(0.0/0.0)) |
| 18 | |
| 19 | call assert_equal(1, empty([])) |
| 20 | call assert_equal(0, empty(['a'])) |
| 21 | |
| 22 | call assert_equal(1, empty({})) |
| 23 | call assert_equal(0, empty({'a':1})) |
| 24 | |
| 25 | call assert_equal(1, empty(v:null)) |
| 26 | call assert_equal(1, empty(v:none)) |
| 27 | call assert_equal(1, empty(v:false)) |
| 28 | call assert_equal(0, empty(v:true)) |
| 29 | |
| 30 | call assert_equal(0, empty(function('Test_empty'))) |
| 31 | endfunc |
| 32 | |
| 33 | func Test_len() |
| 34 | call assert_equal(1, len(0)) |
| 35 | call assert_equal(2, len(12)) |
| 36 | |
| 37 | call assert_equal(0, len('')) |
| 38 | call assert_equal(2, len('ab')) |
| 39 | |
| 40 | call assert_equal(0, len([])) |
| 41 | call assert_equal(2, len([2, 1])) |
| 42 | |
| 43 | call assert_equal(0, len({})) |
| 44 | call assert_equal(2, len({'a': 1, 'b': 2})) |
| 45 | |
| 46 | call assert_fails('call len(v:none)', 'E701:') |
| 47 | call assert_fails('call len({-> 0})', 'E701:') |
| 48 | endfunc |
| 49 | |
| 50 | func Test_max() |
| 51 | call assert_equal(0, max([])) |
| 52 | call assert_equal(2, max([2])) |
| 53 | call assert_equal(2, max([1, 2])) |
| 54 | call assert_equal(2, max([1, 2, v:null])) |
| 55 | |
| 56 | call assert_equal(0, max({})) |
| 57 | call assert_equal(2, max({'a':1, 'b':2})) |
| 58 | |
| 59 | call assert_fails('call max(1)', 'E712:') |
| 60 | call assert_fails('call max(v:none)', 'E712:') |
| 61 | endfunc |
| 62 | |
| 63 | func Test_min() |
| 64 | call assert_equal(0, min([])) |
| 65 | call assert_equal(2, min([2])) |
| 66 | call assert_equal(1, min([1, 2])) |
| 67 | call assert_equal(0, min([1, 2, v:null])) |
| 68 | |
| 69 | call assert_equal(0, min({})) |
| 70 | call assert_equal(1, min({'a':1, 'b':2})) |
| 71 | |
| 72 | call assert_fails('call min(1)', 'E712:') |
| 73 | call assert_fails('call min(v:none)', 'E712:') |
| 74 | endfunc |
| 75 | |
Bram Moolenaar | 08243d2 | 2017-01-10 16:12:29 +0100 | [diff] [blame] | 76 | func Test_str2nr() |
| 77 | call assert_equal(0, str2nr('')) |
| 78 | call assert_equal(1, str2nr('1')) |
| 79 | call assert_equal(1, str2nr(' 1 ')) |
| 80 | |
| 81 | call assert_equal(1, str2nr('+1')) |
| 82 | call assert_equal(1, str2nr('+ 1')) |
| 83 | call assert_equal(1, str2nr(' + 1 ')) |
| 84 | |
| 85 | call assert_equal(-1, str2nr('-1')) |
| 86 | call assert_equal(-1, str2nr('- 1')) |
| 87 | call assert_equal(-1, str2nr(' - 1 ')) |
| 88 | |
| 89 | call assert_equal(123456789, str2nr('123456789')) |
| 90 | call assert_equal(-123456789, str2nr('-123456789')) |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 91 | |
| 92 | call assert_equal(5, str2nr('101', 2)) |
| 93 | call assert_equal(5, str2nr('0b101', 2)) |
| 94 | call assert_equal(5, str2nr('0B101', 2)) |
| 95 | call assert_equal(-5, str2nr('-101', 2)) |
| 96 | call assert_equal(-5, str2nr('-0b101', 2)) |
| 97 | call assert_equal(-5, str2nr('-0B101', 2)) |
| 98 | |
| 99 | call assert_equal(65, str2nr('101', 8)) |
| 100 | call assert_equal(65, str2nr('0101', 8)) |
| 101 | call assert_equal(-65, str2nr('-101', 8)) |
| 102 | call assert_equal(-65, str2nr('-0101', 8)) |
| 103 | |
| 104 | call assert_equal(11259375, str2nr('abcdef', 16)) |
| 105 | call assert_equal(11259375, str2nr('ABCDEF', 16)) |
| 106 | call assert_equal(-11259375, str2nr('-ABCDEF', 16)) |
| 107 | call assert_equal(11259375, str2nr('0xabcdef', 16)) |
| 108 | call assert_equal(11259375, str2nr('0Xabcdef', 16)) |
| 109 | call assert_equal(11259375, str2nr('0XABCDEF', 16)) |
| 110 | call assert_equal(-11259375, str2nr('-0xABCDEF', 16)) |
| 111 | |
| 112 | call assert_equal(0, str2nr('0x10')) |
| 113 | call assert_equal(0, str2nr('0b10')) |
| 114 | call assert_equal(1, str2nr('12', 2)) |
| 115 | call assert_equal(1, str2nr('18', 8)) |
| 116 | call assert_equal(1, str2nr('1g', 16)) |
| 117 | |
| 118 | call assert_equal(0, str2nr(v:null)) |
| 119 | call assert_equal(0, str2nr(v:none)) |
| 120 | |
| 121 | call assert_fails('call str2nr([])', 'E730:') |
| 122 | call assert_fails('call str2nr({->2})', 'E729:') |
| 123 | call assert_fails('call str2nr(1.2)', 'E806:') |
| 124 | call assert_fails('call str2nr(10, [])', 'E474:') |
| 125 | endfunc |
| 126 | |
| 127 | func Test_strftime() |
| 128 | if !exists('*strftime') |
| 129 | return |
| 130 | endif |
| 131 | " Format of strftime() depends on system. We assume |
| 132 | " that basic formats tested here are available and |
| 133 | " identical on all systems which support strftime(). |
| 134 | " |
| 135 | " The 2nd parameter of strftime() is a local time, so the output day |
| 136 | " of strftime() can be 17 or 18, depending on timezone. |
| 137 | call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512)) |
| 138 | " |
| 139 | call assert_match('^\d\d\d\d-\(0\d\|1[012]\)-\([012]\d\|3[01]\) \([01]\d\|2[0-3]\):[0-5]\d:\([0-5]\d\|60\)$', strftime('%Y-%m-%d %H:%M:%S')) |
| 140 | |
| 141 | call assert_fails('call strftime([])', 'E730:') |
| 142 | call assert_fails('call strftime("%Y", [])', 'E745:') |
| 143 | endfunc |
| 144 | |
| 145 | func Test_simplify() |
| 146 | call assert_equal('', simplify('')) |
| 147 | call assert_equal('/', simplify('/')) |
| 148 | call assert_equal('/', simplify('/.')) |
| 149 | call assert_equal('/', simplify('/..')) |
| 150 | call assert_equal('/...', simplify('/...')) |
| 151 | call assert_equal('./dir/file', simplify('./dir/file')) |
| 152 | call assert_equal('./dir/file', simplify('.///dir//file')) |
| 153 | call assert_equal('./dir/file', simplify('./dir/./file')) |
| 154 | call assert_equal('./file', simplify('./dir/../file')) |
| 155 | call assert_equal('../dir/file', simplify('dir/../../dir/file')) |
| 156 | call assert_equal('./file', simplify('dir/.././file')) |
| 157 | |
| 158 | call assert_fails('call simplify({->0})', 'E729:') |
| 159 | call assert_fails('call simplify([])', 'E730:') |
| 160 | call assert_fails('call simplify({})', 'E731:') |
| 161 | call assert_fails('call simplify(1.2)', 'E806:') |
Bram Moolenaar | 08243d2 | 2017-01-10 16:12:29 +0100 | [diff] [blame] | 162 | endfunc |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 163 | |
| 164 | func Test_tolower() |
| 165 | call assert_equal("", tolower("")) |
| 166 | |
| 167 | " Test with all printable ASCII characters. |
| 168 | call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~', |
| 169 | \ tolower(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) |
| 170 | |
| 171 | if !has('multi_byte') |
| 172 | return |
| 173 | endif |
| 174 | |
| 175 | " Test with a few uppercase diacritics. |
| 176 | call assert_equal("aàáâãäåāăąǎǟǡả", tolower("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) |
| 177 | call assert_equal("bḃḇ", tolower("BḂḆ")) |
| 178 | call assert_equal("cçćĉċč", tolower("CÇĆĈĊČ")) |
| 179 | call assert_equal("dďđḋḏḑ", tolower("DĎĐḊḎḐ")) |
| 180 | call assert_equal("eèéêëēĕėęěẻẽ", tolower("EÈÉÊËĒĔĖĘĚẺẼ")) |
| 181 | call assert_equal("fḟ ", tolower("FḞ ")) |
| 182 | call assert_equal("gĝğġģǥǧǵḡ", tolower("GĜĞĠĢǤǦǴḠ")) |
| 183 | call assert_equal("hĥħḣḧḩ", tolower("HĤĦḢḦḨ")) |
| 184 | call assert_equal("iìíîïĩīĭįiǐỉ", tolower("IÌÍÎÏĨĪĬĮİǏỈ")) |
| 185 | call assert_equal("jĵ", tolower("JĴ")) |
| 186 | call assert_equal("kķǩḱḵ", tolower("KĶǨḰḴ")) |
| 187 | call assert_equal("lĺļľŀłḻ", tolower("LĹĻĽĿŁḺ")) |
| 188 | call assert_equal("mḿṁ", tolower("MḾṀ")) |
| 189 | call assert_equal("nñńņňṅṉ", tolower("NÑŃŅŇṄṈ")) |
| 190 | call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) |
| 191 | call assert_equal("pṕṗ", tolower("PṔṖ")) |
| 192 | call assert_equal("q", tolower("Q")) |
| 193 | call assert_equal("rŕŗřṙṟ", tolower("RŔŖŘṘṞ")) |
| 194 | call assert_equal("sśŝşšṡ", tolower("SŚŜŞŠṠ")) |
| 195 | call assert_equal("tţťŧṫṯ", tolower("TŢŤŦṪṮ")) |
| 196 | call assert_equal("uùúûüũūŭůűųưǔủ", tolower("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) |
| 197 | call assert_equal("vṽ", tolower("VṼ")) |
| 198 | call assert_equal("wŵẁẃẅẇ", tolower("WŴẀẂẄẆ")) |
| 199 | call assert_equal("xẋẍ", tolower("XẊẌ")) |
| 200 | call assert_equal("yýŷÿẏỳỷỹ", tolower("YÝŶŸẎỲỶỸ")) |
| 201 | call assert_equal("zźżžƶẑẕ", tolower("ZŹŻŽƵẐẔ")) |
| 202 | |
| 203 | " Test with a few lowercase diacritics, which should remain unchanged. |
| 204 | call assert_equal("aàáâãäåāăąǎǟǡả", tolower("aàáâãäåāăąǎǟǡả")) |
| 205 | call assert_equal("bḃḇ", tolower("bḃḇ")) |
| 206 | call assert_equal("cçćĉċč", tolower("cçćĉċč")) |
| 207 | call assert_equal("dďđḋḏḑ", tolower("dďđḋḏḑ")) |
| 208 | call assert_equal("eèéêëēĕėęěẻẽ", tolower("eèéêëēĕėęěẻẽ")) |
| 209 | call assert_equal("fḟ", tolower("fḟ")) |
| 210 | call assert_equal("gĝğġģǥǧǵḡ", tolower("gĝğġģǥǧǵḡ")) |
| 211 | call assert_equal("hĥħḣḧḩẖ", tolower("hĥħḣḧḩẖ")) |
| 212 | call assert_equal("iìíîïĩīĭįǐỉ", tolower("iìíîïĩīĭįǐỉ")) |
| 213 | call assert_equal("jĵǰ", tolower("jĵǰ")) |
| 214 | call assert_equal("kķǩḱḵ", tolower("kķǩḱḵ")) |
| 215 | call assert_equal("lĺļľŀłḻ", tolower("lĺļľŀłḻ")) |
| 216 | call assert_equal("mḿṁ ", tolower("mḿṁ ")) |
| 217 | call assert_equal("nñńņňʼnṅṉ", tolower("nñńņňʼnṅṉ")) |
| 218 | call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("oòóôõöøōŏőơǒǫǭỏ")) |
| 219 | call assert_equal("pṕṗ", tolower("pṕṗ")) |
| 220 | call assert_equal("q", tolower("q")) |
| 221 | call assert_equal("rŕŗřṙṟ", tolower("rŕŗřṙṟ")) |
| 222 | call assert_equal("sśŝşšṡ", tolower("sśŝşšṡ")) |
| 223 | call assert_equal("tţťŧṫṯẗ", tolower("tţťŧṫṯẗ")) |
| 224 | call assert_equal("uùúûüũūŭůűųưǔủ", tolower("uùúûüũūŭůűųưǔủ")) |
| 225 | call assert_equal("vṽ", tolower("vṽ")) |
| 226 | call assert_equal("wŵẁẃẅẇẘ", tolower("wŵẁẃẅẇẘ")) |
| 227 | call assert_equal("ẋẍ", tolower("ẋẍ")) |
| 228 | call assert_equal("yýÿŷẏẙỳỷỹ", tolower("yýÿŷẏẙỳỷỹ")) |
| 229 | call assert_equal("zźżžƶẑẕ", tolower("zźżžƶẑẕ")) |
| 230 | |
| 231 | " According to https://twitter.com/jifa/status/625776454479970304 |
| 232 | " Ⱥ (U+023A) and Ⱦ (U+023E) are the *only* code points to increase |
| 233 | " in length (2 to 3 bytes) when lowercased. So let's test them. |
| 234 | call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ")) |
| 235 | endfunc |
| 236 | |
| 237 | func Test_toupper() |
| 238 | call assert_equal("", toupper("")) |
| 239 | |
| 240 | " Test with all printable ASCII characters. |
| 241 | call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~', |
| 242 | \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) |
| 243 | |
| 244 | if !has('multi_byte') |
| 245 | return |
| 246 | endif |
| 247 | |
| 248 | " Test with a few lowercase diacritics. |
| 249 | call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("aàáâãäåāăąǎǟǡả")) |
| 250 | call assert_equal("BḂḆ", toupper("bḃḇ")) |
| 251 | call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč")) |
| 252 | call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ")) |
| 253 | call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("eèéêëēĕėęěẻẽ")) |
| 254 | call assert_equal("FḞ", toupper("fḟ")) |
| 255 | call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("gĝğġģǥǧǵḡ")) |
| 256 | call assert_equal("HĤĦḢḦḨẖ", toupper("hĥħḣḧḩẖ")) |
| 257 | call assert_equal("IÌÍÎÏĨĪĬĮǏỈ", toupper("iìíîïĩīĭįǐỉ")) |
| 258 | call assert_equal("JĴǰ", toupper("jĵǰ")) |
| 259 | call assert_equal("KĶǨḰḴ", toupper("kķǩḱḵ")) |
| 260 | call assert_equal("LĹĻĽĿŁḺ", toupper("lĺļľŀłḻ")) |
| 261 | call assert_equal("MḾṀ ", toupper("mḿṁ ")) |
| 262 | call assert_equal("NÑŃŅŇʼnṄṈ", toupper("nñńņňʼnṅṉ")) |
| 263 | call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("oòóôõöøōŏőơǒǫǭỏ")) |
| 264 | call assert_equal("PṔṖ", toupper("pṕṗ")) |
| 265 | call assert_equal("Q", toupper("q")) |
| 266 | call assert_equal("RŔŖŘṘṞ", toupper("rŕŗřṙṟ")) |
| 267 | call assert_equal("SŚŜŞŠṠ", toupper("sśŝşšṡ")) |
| 268 | call assert_equal("TŢŤŦṪṮẗ", toupper("tţťŧṫṯẗ")) |
| 269 | call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("uùúûüũūŭůűųưǔủ")) |
| 270 | call assert_equal("VṼ", toupper("vṽ")) |
| 271 | call assert_equal("WŴẀẂẄẆẘ", toupper("wŵẁẃẅẇẘ")) |
| 272 | call assert_equal("ẊẌ", toupper("ẋẍ")) |
| 273 | call assert_equal("YÝŸŶẎẙỲỶỸ", toupper("yýÿŷẏẙỳỷỹ")) |
| 274 | call assert_equal("ZŹŻŽƵẐẔ", toupper("zźżžƶẑẕ")) |
| 275 | |
| 276 | " Test that uppercase diacritics, which should remain unchanged. |
| 277 | call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) |
| 278 | call assert_equal("BḂḆ", toupper("BḂḆ")) |
| 279 | call assert_equal("CÇĆĈĊČ", toupper("CÇĆĈĊČ")) |
| 280 | call assert_equal("DĎĐḊḎḐ", toupper("DĎĐḊḎḐ")) |
| 281 | call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("EÈÉÊËĒĔĖĘĚẺẼ")) |
| 282 | call assert_equal("FḞ ", toupper("FḞ ")) |
| 283 | call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("GĜĞĠĢǤǦǴḠ")) |
| 284 | call assert_equal("HĤĦḢḦḨ", toupper("HĤĦḢḦḨ")) |
| 285 | call assert_equal("IÌÍÎÏĨĪĬĮİǏỈ", toupper("IÌÍÎÏĨĪĬĮİǏỈ")) |
| 286 | call assert_equal("JĴ", toupper("JĴ")) |
| 287 | call assert_equal("KĶǨḰḴ", toupper("KĶǨḰḴ")) |
| 288 | call assert_equal("LĹĻĽĿŁḺ", toupper("LĹĻĽĿŁḺ")) |
| 289 | call assert_equal("MḾṀ", toupper("MḾṀ")) |
| 290 | call assert_equal("NÑŃŅŇṄṈ", toupper("NÑŃŅŇṄṈ")) |
| 291 | call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) |
| 292 | call assert_equal("PṔṖ", toupper("PṔṖ")) |
| 293 | call assert_equal("Q", toupper("Q")) |
| 294 | call assert_equal("RŔŖŘṘṞ", toupper("RŔŖŘṘṞ")) |
| 295 | call assert_equal("SŚŜŞŠṠ", toupper("SŚŜŞŠṠ")) |
| 296 | call assert_equal("TŢŤŦṪṮ", toupper("TŢŤŦṪṮ")) |
| 297 | call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) |
| 298 | call assert_equal("VṼ", toupper("VṼ")) |
| 299 | call assert_equal("WŴẀẂẄẆ", toupper("WŴẀẂẄẆ")) |
| 300 | call assert_equal("XẊẌ", toupper("XẊẌ")) |
| 301 | call assert_equal("YÝŶŸẎỲỶỸ", toupper("YÝŶŸẎỲỶỸ")) |
| 302 | call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ")) |
| 303 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 304 | call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ")) |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 305 | endfunc |
| 306 | |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 307 | " Tests for the mode() function |
| 308 | let current_modes = '' |
| 309 | func! Save_mode() |
| 310 | let g:current_modes = mode(0) . '-' . mode(1) |
| 311 | return '' |
| 312 | endfunc |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 313 | |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 314 | func! Test_mode() |
| 315 | new |
| 316 | call append(0, ["Blue Ball Black", "Brown Band Bowl", ""]) |
| 317 | |
| 318 | inoremap <F2> <C-R>=Save_mode()<CR> |
| 319 | |
| 320 | normal! 3G |
| 321 | exe "normal i\<F2>\<Esc>" |
| 322 | call assert_equal('i-i', g:current_modes) |
| 323 | exe "normal i\<C-G>uBa\<C-P>\<F2>\<Esc>u" |
| 324 | call assert_equal('i-ic', g:current_modes) |
| 325 | exe "normal iBro\<C-P>\<F2>\<Esc>u" |
| 326 | call assert_equal('i-ic', g:current_modes) |
| 327 | exe "normal iBa\<C-X>\<F2>\<Esc>u" |
| 328 | call assert_equal('i-ix', g:current_modes) |
| 329 | exe "normal iBa\<C-X>\<C-P>\<F2>\<Esc>u" |
| 330 | call assert_equal('i-ic', g:current_modes) |
| 331 | exe "normal iBro\<C-X>\<C-P>\<F2>\<Esc>u" |
| 332 | call assert_equal('i-ic', g:current_modes) |
| 333 | exe "normal iBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u" |
| 334 | call assert_equal('i-ic', g:current_modes) |
| 335 | exe "normal iCom\<C-P>\<F2>\<Esc>u" |
| 336 | call assert_equal('i-ic', g:current_modes) |
| 337 | exe "normal iCom\<C-X>\<C-P>\<F2>\<Esc>u" |
| 338 | call assert_equal('i-ic', g:current_modes) |
| 339 | |
| 340 | exe "normal RBa\<C-P>\<F2>\<Esc>u" |
| 341 | call assert_equal('R-Rc', g:current_modes) |
| 342 | exe "normal RBro\<C-P>\<F2>\<Esc>u" |
| 343 | call assert_equal('R-Rc', g:current_modes) |
| 344 | exe "normal RBa\<C-X>\<F2>\<Esc>u" |
| 345 | call assert_equal('R-Rx', g:current_modes) |
| 346 | exe "normal RBa\<C-X>\<C-P>\<F2>\<Esc>u" |
| 347 | call assert_equal('R-Rc', g:current_modes) |
| 348 | exe "normal RBro\<C-X>\<C-P>\<F2>\<Esc>u" |
| 349 | call assert_equal('R-Rc', g:current_modes) |
| 350 | exe "normal RBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u" |
| 351 | call assert_equal('R-Rc', g:current_modes) |
| 352 | exe "normal RCom\<C-P>\<F2>\<Esc>u" |
| 353 | call assert_equal('R-Rc', g:current_modes) |
| 354 | exe "normal RCom\<C-X>\<C-P>\<F2>\<Esc>u" |
| 355 | call assert_equal('R-Rc', g:current_modes) |
| 356 | |
| 357 | call assert_equal('n', mode(0)) |
| 358 | call assert_equal('n', mode(1)) |
| 359 | |
| 360 | " How to test operator-pending mode? |
| 361 | |
| 362 | call feedkeys("v", 'xt') |
| 363 | call assert_equal('v', mode()) |
| 364 | call assert_equal('v', mode(1)) |
| 365 | call feedkeys("\<Esc>V", 'xt') |
| 366 | call assert_equal('V', mode()) |
| 367 | call assert_equal('V', mode(1)) |
| 368 | call feedkeys("\<Esc>\<C-V>", 'xt') |
| 369 | call assert_equal("\<C-V>", mode()) |
| 370 | call assert_equal("\<C-V>", mode(1)) |
| 371 | call feedkeys("\<Esc>", 'xt') |
| 372 | |
| 373 | call feedkeys("gh", 'xt') |
| 374 | call assert_equal('s', mode()) |
| 375 | call assert_equal('s', mode(1)) |
| 376 | call feedkeys("\<Esc>gH", 'xt') |
| 377 | call assert_equal('S', mode()) |
| 378 | call assert_equal('S', mode(1)) |
| 379 | call feedkeys("\<Esc>g\<C-H>", 'xt') |
| 380 | call assert_equal("\<C-S>", mode()) |
| 381 | call assert_equal("\<C-S>", mode(1)) |
| 382 | call feedkeys("\<Esc>", 'xt') |
| 383 | |
| 384 | call feedkeys(":echo \<C-R>=Save_mode()\<C-U>\<CR>", 'xt') |
| 385 | call assert_equal('c-c', g:current_modes) |
| 386 | call feedkeys("gQecho \<C-R>=Save_mode()\<CR>\<CR>vi\<CR>", 'xt') |
| 387 | call assert_equal('c-cv', g:current_modes) |
| 388 | " How to test Ex mode? |
| 389 | |
| 390 | bwipe! |
| 391 | iunmap <F2> |
| 392 | endfunc |