diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2022-01-09 22:48:29 +0000 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2022-02-05 13:16:34 +0000 |
commit | 22f0725aac300ed9b249f995df7889f6c203d1e0 (patch) | |
tree | f417e4a24d7e1dc5db1da23d087b65eba3a7f2e8 /src/nvim/testdir/test_random.vim | |
parent | 806a7c976d78da2bf7a46499452b4a3e30fae798 (diff) | |
download | rneovim-22f0725aac300ed9b249f995df7889f6c203d1e0.tar.gz rneovim-22f0725aac300ed9b249f995df7889f6c203d1e0.tar.bz2 rneovim-22f0725aac300ed9b249f995df7889f6c203d1e0.zip |
vim-patch:8.1.2342: random number generator in Vim script is slow
Problem: Random number generator in Vim script is slow.
Solution: Add rand() and srand(). (Yasuhiro Matsumoto, closes vim/vim#1277)
https://github.com/vim/vim/commit/06b0b4bc27077013e9b4b48fd1d9b33e543ccf99
Add missing method call usage to builtin.txt.
vim_time and test_settime is N/A.
Add a modeline to test_random.vim.
Use typval_T* over listitem_T* vars so we don't need to use TV_LIST_ITEM_TV all
over the place...
Remove NULL list checks (tv_list_len covers this).
Diffstat (limited to 'src/nvim/testdir/test_random.vim')
-rw-r--r-- | src/nvim/testdir/test_random.vim | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_random.vim b/src/nvim/testdir/test_random.vim new file mode 100644 index 0000000000..bde034a96c --- /dev/null +++ b/src/nvim/testdir/test_random.vim @@ -0,0 +1,31 @@ +" Tests for srand() and rand() + +func Test_Rand() + let r = srand(123456789) + call assert_equal([123456789, 362436069, 521288629, 88675123], r) + call assert_equal(3701687786, rand(r)) + call assert_equal(458299110, rand(r)) + call assert_equal(2500872618, rand(r)) + call assert_equal(3633119408, rand(r)) + call assert_equal(516391518, rand(r)) + + " Nvim does not support test_settime + " call test_settime(12341234) + " let s = srand() + " call assert_equal(s, srand()) + " call test_settime(12341235) + " call assert_notequal(s, srand()) + + call srand() + let v = rand() + call assert_notequal(v, rand()) + + call assert_fails('echo srand([1])', 'E745:') + call assert_fails('echo rand([1, 2, 3])', 'E475:') + call assert_fails('echo rand([[1], 2, 3, 4])', 'E475:') + call assert_fails('echo rand([1, [2], 3, 4])', 'E475:') + call assert_fails('echo rand([1, 2, [3], 4])', 'E475:') + call assert_fails('echo rand([1, 2, 3, [4]])', 'E475:') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab |