comparison src/testdir/test_functions.vim @ 18017:988e5a868b60 v8.1.2004

patch 8.1.2004: more functions can be used as methods Commit: https://github.com/vim/vim/commit/f6ed61e1489e40eada55a4f1782e1ed82bcad7d9 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 7 19:05:09 2019 +0200 patch 8.1.2004: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make various functions usable as a method.
author Bram Moolenaar <Bram@vim.org>
date Sat, 07 Sep 2019 19:15:04 +0200
parents 7a19c8d6bb9e
children 11dca9732a48
comparison
equal deleted inserted replaced
18016:834b7854aa3c 18017:988e5a868b60
136 136
137 call assert_equal(123456789, str2nr('123456789')) 137 call assert_equal(123456789, str2nr('123456789'))
138 call assert_equal(-123456789, str2nr('-123456789')) 138 call assert_equal(-123456789, str2nr('-123456789'))
139 139
140 call assert_equal(5, str2nr('101', 2)) 140 call assert_equal(5, str2nr('101', 2))
141 call assert_equal(5, str2nr('0b101', 2)) 141 call assert_equal(5, '0b101'->str2nr(2))
142 call assert_equal(5, str2nr('0B101', 2)) 142 call assert_equal(5, str2nr('0B101', 2))
143 call assert_equal(-5, str2nr('-101', 2)) 143 call assert_equal(-5, str2nr('-101', 2))
144 call assert_equal(-5, str2nr('-0b101', 2)) 144 call assert_equal(-5, str2nr('-0b101', 2))
145 call assert_equal(-5, str2nr('-0B101', 2)) 145 call assert_equal(-5, str2nr('-0B101', 2))
146 146
182 " 182 "
183 " The 2nd parameter of strftime() is a local time, so the output day 183 " The 2nd parameter of strftime() is a local time, so the output day
184 " of strftime() can be 17 or 18, depending on timezone. 184 " of strftime() can be 17 or 18, depending on timezone.
185 call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512)) 185 call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512))
186 " 186 "
187 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')) 187 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\)$', '%Y-%m-%d %H:%M:%S'->strftime())
188 188
189 call assert_fails('call strftime([])', 'E730:') 189 call assert_fails('call strftime([])', 'E730:')
190 call assert_fails('call strftime("%Y", [])', 'E745:') 190 call assert_fails('call strftime("%Y", [])', 'E745:')
191 191
192 " Check that the time changes after we change the timezone 192 " Check that the time changes after we change the timezone
413 endfunc 413 endfunc
414 414
415 func Test_strpart() 415 func Test_strpart()
416 call assert_equal('de', strpart('abcdefg', 3, 2)) 416 call assert_equal('de', strpart('abcdefg', 3, 2))
417 call assert_equal('ab', strpart('abcdefg', -2, 4)) 417 call assert_equal('ab', strpart('abcdefg', -2, 4))
418 call assert_equal('abcdefg', strpart('abcdefg', -2)) 418 call assert_equal('abcdefg', 'abcdefg'->strpart(-2))
419 call assert_equal('fg', strpart('abcdefg', 5, 4)) 419 call assert_equal('fg', strpart('abcdefg', 5, 4))
420 call assert_equal('defg', strpart('abcdefg', 3)) 420 call assert_equal('defg', strpart('abcdefg', 3))
421 421
422 call assert_equal('lép', strpart('éléphant', 2, 4)) 422 call assert_equal('lép', strpart('éléphant', 2, 4))
423 call assert_equal('léphant', strpart('éléphant', 2)) 423 call assert_equal('léphant', strpart('éléphant', 2))
761 endfunc 761 endfunc
762 762
763 func Test_stridx() 763 func Test_stridx()
764 call assert_equal(-1, stridx('', 'l')) 764 call assert_equal(-1, stridx('', 'l'))
765 call assert_equal(0, stridx('', '')) 765 call assert_equal(0, stridx('', ''))
766 call assert_equal(0, stridx('hello', '')) 766 call assert_equal(0, 'hello'->stridx(''))
767 call assert_equal(-1, stridx('hello', 'L')) 767 call assert_equal(-1, stridx('hello', 'L'))
768 call assert_equal(2, stridx('hello', 'l', -1)) 768 call assert_equal(2, stridx('hello', 'l', -1))
769 call assert_equal(2, stridx('hello', 'l', 0)) 769 call assert_equal(2, stridx('hello', 'l', 0))
770 call assert_equal(2, stridx('hello', 'l', 1)) 770 call assert_equal(2, 'hello'->stridx('l', 1))
771 call assert_equal(3, stridx('hello', 'l', 3)) 771 call assert_equal(3, stridx('hello', 'l', 3))
772 call assert_equal(-1, stridx('hello', 'l', 4)) 772 call assert_equal(-1, stridx('hello', 'l', 4))
773 call assert_equal(-1, stridx('hello', 'l', 10)) 773 call assert_equal(-1, stridx('hello', 'l', 10))
774 call assert_equal(2, stridx('hello', 'll')) 774 call assert_equal(2, stridx('hello', 'll'))
775 call assert_equal(-1, stridx('hello', 'hello world')) 775 call assert_equal(-1, stridx('hello', 'hello world'))
778 func Test_strridx() 778 func Test_strridx()
779 call assert_equal(-1, strridx('', 'l')) 779 call assert_equal(-1, strridx('', 'l'))
780 call assert_equal(0, strridx('', '')) 780 call assert_equal(0, strridx('', ''))
781 call assert_equal(5, strridx('hello', '')) 781 call assert_equal(5, strridx('hello', ''))
782 call assert_equal(-1, strridx('hello', 'L')) 782 call assert_equal(-1, strridx('hello', 'L'))
783 call assert_equal(3, strridx('hello', 'l')) 783 call assert_equal(3, 'hello'->strridx('l'))
784 call assert_equal(3, strridx('hello', 'l', 10)) 784 call assert_equal(3, strridx('hello', 'l', 10))
785 call assert_equal(3, strridx('hello', 'l', 3)) 785 call assert_equal(3, strridx('hello', 'l', 3))
786 call assert_equal(2, strridx('hello', 'l', 2)) 786 call assert_equal(2, strridx('hello', 'l', 2))
787 call assert_equal(-1, strridx('hello', 'l', 1)) 787 call assert_equal(-1, strridx('hello', 'l', 1))
788 call assert_equal(-1, strridx('hello', 'l', 0)) 788 call assert_equal(-1, strridx('hello', 'l', 0))