annotate src/testdir/test_ruby.vim @ 32936:c517845bd10e v9.0.1776

patch 9.0.1776: No support for stable Python 3 ABI Commit: https://github.com/vim/vim/commit/c13b3d1350b60b94fe87f0761ea31c0e7fb6ebf3 Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Sun Aug 20 21:18:38 2023 +0200 patch 9.0.1776: No support for stable Python 3 ABI Problem: No support for stable Python 3 ABI Solution: Support Python 3 stable ABI Commits: 1) Support Python 3 stable ABI to allow mixed version interoperatbility Vim currently supports embedding Python for use with plugins, and the "dynamic" linking option allows the user to specify a locally installed version of Python by setting `pythonthreedll`. However, one caveat is that the Python 3 libs are not binary compatible across minor versions, and mixing versions can potentially be dangerous (e.g. let's say Vim was linked against the Python 3.10 SDK, but the user sets `pythonthreedll` to a 3.11 lib). Usually, nothing bad happens, but in theory this could lead to crashes, memory corruption, and other unpredictable behaviors. It's also difficult for the user to tell something is wrong because Vim has no way of reporting what Python 3 version Vim was linked with. For Vim installed via a package manager, this usually isn't an issue because all the dependencies would already be figured out. For prebuilt Vim binaries like MacVim (my motivation for working on this), AppImage, and Win32 installer this could potentially be an issue as usually a single binary is distributed. This is more tricky when a new Python version is released, as there's a chicken-and-egg issue with deciding what Python version to build against and hard to keep in sync when a new Python version just drops and we have a mix of users of different Python versions, and a user just blindly upgrading to a new Python could lead to bad interactions with Vim. Python 3 does have a solution for this problem: stable ABI / limited API (see https://docs.python.org/3/c-api/stable.html). The C SDK limits the API to a set of functions that are promised to be stable across versions. This pull request adds an ifdef config that allows us to turn it on when building Vim. Vim binaries built with this option should be safe to freely link with any Python 3 libraies without having the constraint of having to use the same minor version. Note: Python 2 has no such concept and this doesn't change how Python 2 integration works (not that there is going to be a new version of Python 2 that would cause compatibility issues in the future anyway). --- Technical details: ====== The stable ABI can be accessed when we compile with the Python 3 limited API (by defining `Py_LIMITED_API`). The Python 3 code (in `if_python3.c` and `if_py_both.h`) would now handle this and switch to limited API mode. Without it set, Vim will still use the full API as before so this is an opt-in change. The main difference is that `PyType_Object` is now an opaque struct that we can't directly create "static types" out of, and we have to create type objects as "heap types" instead. This is because the struct is not stable and changes from version to version (e.g. 3.8 added a `tp_vectorcall` field to it). I had to change all the types to be allocated on the heap instead with just a pointer to them. Other functions are also simply missing in limited API, or they are introduced too late (e.g. `PyUnicode_AsUTF8AndSize` in 3.10) to it that we need some other ways to do the same thing, so I had to abstract a few things into macros, and sometimes re-implement functions like `PyObject_NEW`. One caveat is that in limited API, `OutputType` (used for replacing `sys.stdout`) no longer inherits from `PyStdPrinter_Type` which I don't think has any real issue other than minor differences in how they convert to a string and missing a couple functions like `mode()` and `fileno()`. Also fixed an existing bug where `tp_basicsize` was set incorrectly for `BufferObject`, `TabListObject, `WinListObject`. Technically, there could be a small performance drop, there is a little more indirection with accessing type objects, and some APIs like `PyUnicode_AsUTF8AndSize` are missing, but in practice I didn't see any difference, and any well-written Python plugin should try to avoid excessing callbacks to the `vim` module in Python anyway. I only tested limited API mode down to Python 3.7, which seemes to compile and work fine. I haven't tried earlier Python versions. 2) Fix PyIter_Check on older Python vers / type##Ptr unused warning For PyIter_Check, older versions exposed them as either macros (used in full API), or a function (for use in limited API). A previous change exposed PyIter_Check to the dynamic build because Python just moved it to function-only in 3.10 anyway. Because of that, just make sure we always grab the function in dynamic builds in earlier versions since that's what Python eventually did anyway. 3) Move Py_LIMITED_API define to configure script Can now use --with-python-stable-abi flag to customize what stable ABI version to target. Can also use an env var to do so as well. 4) Show +python/dyn-stable in :version, and allow has() feature query Not sure if the "/dyn-stable" suffix would break things, or whether we should do it another way. Or just don't show it in version and rely on has() feature checking. 5) Documentation first draft. Still need to implement v:python3_version 6) Fix PyIter_Check build breaks when compiling against Python 3.8 7) Add CI coverage stable ABI on Linux/Windows / make configurable on Windows This adds configurable options for Windows make files (both MinGW and MSVC). CI will also now exercise both traditional full API and stable ABI for Linux and Windows in the matrix for coverage. Also added a "dynamic" option to Linux matrix as a drive-by change to make other scripting languages like Ruby / Perl testable under both static and dynamic builds. 8) Fix inaccuracy in Windows docs Python's own docs are confusing but you don't actually want to use `python3.dll` for the dynamic linkage. 9) Add generated autoconf file 10) Add v:python3_version support This variable indicates the version of Python3 that Vim was built against (PY_VERSION_HEX), and will be useful to check whether the Python library you are loading in dynamically actually fits it. When built with stable ABI, it will be the limited ABI version instead (`Py_LIMITED_API`), which indicates the minimum version of Python 3 the user should have, rather than the exact match. When stable ABI is used, we won't be exposing PY_VERSION_HEX in this var because it just doesn't seem necessary to do so (the whole point of stable ABI is the promise that it will work across versions), and I don't want to confuse the user with too many variables. Also, cleaned up some documentation, and added help tags. 11) Fix Python 3.7 compat issues Fix a couple issues when using limited API < 3.8 - Crash on exit: In Python 3.7, if a heap-allocated type is destroyed before all instances are, it would cause a crash later. This happens when we destroyed `OptionsType` before calling `Py_Finalize` when using the limited API. To make it worse, later versions changed the semantics and now each instance has a strong reference to its own type and the recommendation has changed to have each instance de-ref its own type and have its type in GC traversal. To avoid dealing with these cross-version variations, we just don't free the heap type. They are static types in non-limited-API anyway and are designed to last through the entirety of the app, and we also don't restart the Python runtime and therefore do not need it to have absolutely 0 leaks. See: - https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-c-api - https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-c-api - PyIter_Check: This function is not provided in limited APIs older than 3.8. Previously I was trying to mock it out using manual PyType_GetSlot() but it was brittle and also does not actually work properly for static types (it will generate a Python error). Just return false. It does mean using limited API < 3.8 is not recommended as you lose the functionality to handle iterators, but from playing with plugins I couldn't find it to be an issue. - Fix loading of PyIter_Check so it will be done when limited API < 3.8. Otherwise loading a 3.7 Python lib will fail even if limited API was specified to use it. 12) Make sure to only load `PyUnicode_AsUTF8AndSize` in needed in limited API We don't use this function unless limited API >= 3.10, but we were loading it regardless. Usually it's ok in Unix-like systems where Python just has a single lib that we load from, but in Windows where there is a separate python3.dll this would not work as the symbol would not have been exposed in this more limited DLL file. This makes it much clearer under what condition is this function needed. closes: #12032 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Sun, 20 Aug 2023 21:30:04 +0200
parents 029c59bf78f1
children dbe616160092
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9338
f23feeba7549 commit https://github.com/vim/vim/commit/85babd6db65afb0eb06a7a9a0778d692248c5c2b
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for ruby interface
f23feeba7549 commit https://github.com/vim/vim/commit/85babd6db65afb0eb06a7a9a0778d692248c5c2b
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
17089
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
3 source check.vim
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
4 CheckFeature ruby
9338
f23feeba7549 commit https://github.com/vim/vim/commit/85babd6db65afb0eb06a7a9a0778d692248c5c2b
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5
f23feeba7549 commit https://github.com/vim/vim/commit/85babd6db65afb0eb06a7a9a0778d692248c5c2b
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 func Test_ruby_change_buffer()
f23feeba7549 commit https://github.com/vim/vim/commit/85babd6db65afb0eb06a7a9a0778d692248c5c2b
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 call setline(line('$'), ['1 line 1'])
f23feeba7549 commit https://github.com/vim/vim/commit/85babd6db65afb0eb06a7a9a0778d692248c5c2b
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 ruby Vim.command("normal /^1\n")
f23feeba7549 commit https://github.com/vim/vim/commit/85babd6db65afb0eb06a7a9a0778d692248c5c2b
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 ruby $curbuf.line = "1 changed line 1"
f23feeba7549 commit https://github.com/vim/vim/commit/85babd6db65afb0eb06a7a9a0778d692248c5c2b
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 call assert_equal('1 changed line 1', getline('$'))
f23feeba7549 commit https://github.com/vim/vim/commit/85babd6db65afb0eb06a7a9a0778d692248c5c2b
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 endfunc
f23feeba7549 commit https://github.com/vim/vim/commit/85babd6db65afb0eb06a7a9a0778d692248c5c2b
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12
10761
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
13 func Test_rubydo()
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
14 " Check deleting lines does not trigger ml_get error.
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
15 new
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
16 call setline(1, ['one', 'two', 'three'])
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
17 rubydo Vim.command("%d_")
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
18 bwipe!
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
19
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
20 " Check switching to another buffer does not trigger ml_get error.
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
21 new
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
22 let wincount = winnr('$')
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
23 call setline(1, ['one', 'two', 'three'])
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
24 rubydo Vim.command("new")
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
25 call assert_equal(wincount + 1, winnr('$'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
26 %bwipe!
10761
721af7a9b4b4 patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9338
diff changeset
27 endfunc
13148
f06a0a75d5b1 patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents: 10761
diff changeset
28
20939
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
29 func Test_rubydo_dollar_underscore()
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
30 new
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
31 call setline(1, ['one', 'two', 'three', 'four'])
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
32 2,3rubydo $_ = '[' + $_ + ']'
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
33 call assert_equal(['one', '[two]', '[three]', 'four'], getline(1, '$'))
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
34 bwipe!
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
35
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
36 call assert_fails('rubydo $_ = 0', 'E265:')
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
37 call assert_fails('rubydo (')
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
38 bwipe!
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
39 endfunc
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
40
13148
f06a0a75d5b1 patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents: 10761
diff changeset
41 func Test_rubyfile()
f06a0a75d5b1 patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents: 10761
diff changeset
42 " Check :rubyfile does not SEGV with Ruby level exception but just fails
f06a0a75d5b1 patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents: 10761
diff changeset
43 let tempfile = tempname() . '.rb'
f06a0a75d5b1 patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents: 10761
diff changeset
44 call writefile(['raise "vim!"'], tempfile)
f06a0a75d5b1 patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents: 10761
diff changeset
45 call assert_fails('rubyfile ' . tempfile)
f06a0a75d5b1 patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents: 10761
diff changeset
46 call delete(tempfile)
f06a0a75d5b1 patch 8.0.1448: segfault with exception inside :rubyfile command
Christian Brabandt <cb@256bit.org>
parents: 10761
diff changeset
47 endfunc
14395
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
48
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
49 func Test_ruby_set_cursor()
14395
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
50 " Check that setting the cursor position works.
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
51 new
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
52 call setline(1, ['first line', 'second line'])
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
53 normal gg
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
54 rubydo $curwin.cursor = [1, 5]
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
55 call assert_equal([1, 6], [line('.'), col('.')])
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
56 call assert_equal([1, 5], rubyeval('$curwin.cursor'))
14395
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
57
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
58 " Check that movement after setting cursor position keeps current column.
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
59 normal j
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
60 call assert_equal([2, 6], [line('.'), col('.')])
18344
69db186daf4c patch 8.1.2166: rubyeval() not tested as a method
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
61 call assert_equal([2, 5], '$curwin.cursor'->rubyeval())
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
62
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
63 call assert_fails('ruby $curwin.cursor = [1]',
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
64 \ 'ArgumentError: array length must be 2')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
65 bwipe!
14395
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 13148
diff changeset
66 endfunc
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
67
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
68 " Test buffer.count and buffer.length (number of lines in buffer)
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
69 func Test_ruby_buffer_count()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
70 new
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
71 call setline(1, ['one', 'two', 'three'])
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
72 call assert_equal(3, rubyeval('$curbuf.count'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
73 call assert_equal(3, rubyeval('$curbuf.length'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
74 bwipe!
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
75 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
76
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
77 " Test buffer.name (buffer name)
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
78 func Test_ruby_buffer_name()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
79 new Xfoo
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
80 call assert_equal(expand('%:p'), rubyeval('$curbuf.name'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
81 bwipe
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
82 call assert_equal(v:null, rubyeval('$curbuf.name'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
83 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
84
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
85 " Test buffer.number (number of the buffer).
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
86 func Test_ruby_buffer_number()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
87 new
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
88 call assert_equal(bufnr('%'), rubyeval('$curbuf.number'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
89 new
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
90 call assert_equal(bufnr('%'), rubyeval('$curbuf.number'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
91
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
92 %bwipe
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
93 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
94
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
95 " Test buffer.delete({n}) (delete line {n})
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
96 func Test_ruby_buffer_delete()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
97 new
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
98 call setline(1, ['one', 'two', 'three'])
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
99 ruby $curbuf.delete(2)
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
100 call assert_equal(['one', 'three'], getline(1, '$'))
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
101
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
102 call assert_fails('ruby $curbuf.delete(0)', 'IndexError: line number 0 out of range')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
103 call assert_fails('ruby $curbuf.delete(3)', 'IndexError: line number 3 out of range')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
104
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
105 bwipe!
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
106 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
107
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
108 " Test buffer.append({str}, str) (append line {str} after line {n})
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
109 func Test_ruby_buffer_append()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
110 new
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
111 ruby $curbuf.append(0, 'one')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
112 ruby $curbuf.append(1, 'three')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
113 ruby $curbuf.append(1, 'two')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
114 ruby $curbuf.append(4, 'four')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
115
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
116 call assert_equal(['one', 'two', 'three', '', 'four'], getline(1, '$'))
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
117
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
118 call assert_fails('ruby $curbuf.append(-1, "x")',
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
119 \ 'IndexError: line number -1 out of range')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
120 call assert_fails('ruby $curbuf.append(6, "x")',
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
121 \ 'IndexError: line number 6 out of range')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
122
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
123 bwipe!
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
124 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
125
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
126 " Test buffer.line (get or set the current line)
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
127 func Test_ruby_buffer_line()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
128 new
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
129 call setline(1, ['one', 'two', 'three'])
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
130 2
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
131 call assert_equal('two', rubyeval('$curbuf.line'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
132
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
133 ruby $curbuf.line = 'TWO'
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
134 call assert_equal(['one', 'TWO', 'three'], getline(1, '$'))
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
135
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
136 bwipe!
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
137 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
138
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
139 " Test buffer.line_number (get current line number)
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
140 func Test_ruby_buffer_line_number()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
141 new
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
142 call setline(1, ['one', 'two', 'three'])
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
143 2
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
144 call assert_equal(2, rubyeval('$curbuf.line_number'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
145
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
146 bwipe!
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
147 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
148
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
149 func Test_ruby_buffer_get()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
150 new
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
151 call setline(1, ['one', 'two'])
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
152 call assert_equal('one', rubyeval('$curbuf[1]'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
153 call assert_equal('two', rubyeval('$curbuf[2]'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
154
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
155 call assert_fails('ruby $curbuf[0]',
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
156 \ 'IndexError: line number 0 out of range')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
157 call assert_fails('ruby $curbuf[3]',
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
158 \ 'IndexError: line number 3 out of range')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
159
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
160 bwipe!
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
161 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
162
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
163 func Test_ruby_buffer_set()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
164 new
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
165 call setline(1, ['one', 'two'])
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
166 ruby $curbuf[2] = 'TWO'
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
167 ruby $curbuf[1] = 'ONE'
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
168
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
169 call assert_fails('ruby $curbuf[0] = "ZERO"',
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
170 \ 'IndexError: line number 0 out of range')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
171 call assert_fails('ruby $curbuf[3] = "THREE"',
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
172 \ 'IndexError: line number 3 out of range')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
173 bwipe!
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
174 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
175
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
176 " Test window.width (get or set window height).
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
177 func Test_ruby_window_height()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
178 new
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
179
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
180 " Test setting window height
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
181 ruby $curwin.height = 2
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
182 call assert_equal(2, winheight(0))
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
183
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
184 " Test getting window height
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
185 call assert_equal(2, rubyeval('$curwin.height'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
186
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
187 bwipe
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
188 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
189
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
190 " Test window.width (get or set window width).
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
191 func Test_ruby_window_width()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
192 vnew
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
193
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
194 " Test setting window width
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
195 ruby $curwin.width = 2
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
196 call assert_equal(2, winwidth(0))
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
197
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
198 " Test getting window width
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
199 call assert_equal(2, rubyeval('$curwin.width'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
200
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
201 bwipe
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
202 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
203
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
204 " Test window.buffer (get buffer object of a window object).
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
205 func Test_ruby_window_buffer()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
206 new Xfoo1
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
207 new Xfoo2
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
208 ruby $b2 = $curwin.buffer
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
209 ruby $w2 = $curwin
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
210 wincmd j
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
211 ruby $b1 = $curwin.buffer
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
212 ruby $w1 = $curwin
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
213
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
214 call assert_equal(rubyeval('$b1'), rubyeval('$w1.buffer'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
215 call assert_equal(rubyeval('$b2'), rubyeval('$w2.buffer'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
216 call assert_equal(bufnr('Xfoo1'), rubyeval('$w1.buffer.number'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
217 call assert_equal(bufnr('Xfoo2'), rubyeval('$w2.buffer.number'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
218
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
219 ruby $b1, $w1, $b2, $w2 = nil
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
220 %bwipe
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
221 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
222
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
223 " Test Vim::Window.current (get current window object)
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
224 func Test_ruby_Vim_window_current()
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
225 let cw = rubyeval('$curwin')
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
226 call assert_equal(cw, rubyeval('Vim::Window.current'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
227 call assert_match('^#<Vim::Window:0x\x\+>$', cw)
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
228 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
229
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
230 " Test Vim::Window.count (number of windows)
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
231 func Test_ruby_Vim_window_count()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
232 new Xfoo1
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
233 new Xfoo2
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
234 split
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
235 call assert_equal(4, rubyeval('Vim::Window.count'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
236 %bwipe
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
237 call assert_equal(1, rubyeval('Vim::Window.count'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
238 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
239
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
240 " Test Vim::Window[n] (get window object of window n)
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
241 func Test_ruby_Vim_window_get()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
242 new Xfoo1
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
243 new Xfoo2
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
244 call assert_match('Xfoo2$', rubyeval('Vim::Window[0].buffer.name'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
245 wincmd j
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
246 call assert_match('Xfoo1$', rubyeval('Vim::Window[1].buffer.name'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
247 wincmd j
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
248 call assert_equal(v:null, rubyeval('Vim::Window[2].buffer.name'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
249 %bwipe
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
250 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
251
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
252 " Test Vim::Buffer.current (return the buffer object of current buffer)
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
253 func Test_ruby_Vim_buffer_current()
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
254 let cb = rubyeval('$curbuf')
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
255 call assert_equal(cb, rubyeval('Vim::Buffer.current'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
256 call assert_match('^#<Vim::Buffer:0x\x\+>$', cb)
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
257 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
258
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
259 " Test Vim::Buffer:.count (return the number of buffers)
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
260 func Test_ruby_Vim_buffer_count()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
261 new Xfoo1
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
262 new Xfoo2
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
263 call assert_equal(3, rubyeval('Vim::Buffer.count'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
264 %bwipe
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
265 call assert_equal(1, rubyeval('Vim::Buffer.count'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
266 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
267
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
268 " Test Vim::buffer[n] (return the buffer object of buffer number n)
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
269 func Test_ruby_Vim_buffer_get()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
270 new Xfoo1
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
271 new Xfoo2
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
272
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
273 " Index of Vim::Buffer[n] goes from 0 to the number of buffers.
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
274 call assert_equal(v:null, rubyeval('Vim::Buffer[0].name'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
275 call assert_match('Xfoo1$', rubyeval('Vim::Buffer[1].name'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
276 call assert_match('Xfoo2$', rubyeval('Vim::Buffer[2].name'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
277 call assert_fails('ruby print Vim::Buffer[3].name',
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
278 \ "NoMethodError: undefined method `name' for nil:NilClass")
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
279 %bwipe
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
280 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
281
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
282 " Test Vim::command({cmd}) (execute a Ex command))
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
283 " Test Vim::command({cmd})
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
284 func Test_ruby_Vim_command()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
285 new
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
286 call setline(1, ['one', 'two', 'three', 'four'])
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
287 ruby Vim::command('2,3d')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
288 call assert_equal(['one', 'four'], getline(1, '$'))
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
289 bwipe!
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
290 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
291
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
292 " Test Vim::set_option (set a vim option)
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
293 func Test_ruby_Vim_set_option()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
294 call assert_equal(0, &number)
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
295 ruby Vim::set_option('number')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
296 call assert_equal(1, &number)
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
297 ruby Vim::set_option('nonumber')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
298 call assert_equal(0, &number)
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
299 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
300
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
301 func Test_ruby_Vim_evaluate()
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
302 call assert_equal(123, rubyeval('Vim::evaluate("123")'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
303 " Vim::evaluate("123").class gives Integer or Fixnum depending
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
304 " on versions of Ruby.
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
305 call assert_match('^Integer\|Fixnum$', rubyeval('Vim::evaluate("123").class'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
306
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 20939
diff changeset
307 call assert_equal(1.23, rubyeval('Vim::evaluate("1.23")'))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 20939
diff changeset
308 call assert_equal('Float', rubyeval('Vim::evaluate("1.23").class'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
309
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
310 call assert_equal('foo', rubyeval('Vim::evaluate("\"foo\"")'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
311 call assert_equal('String', rubyeval('Vim::evaluate("\"foo\"").class'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
312
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
313 call assert_equal(["\x01\xAB"], rubyeval('Vim::evaluate("0z01ab").unpack("M")'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
314 call assert_equal('String', rubyeval('Vim::evaluate("0z01ab").class'))
15943
e5f82e8b3c06 patch 8.1.0977: blob not tested with Ruby
Bram Moolenaar <Bram@vim.org>
parents: 14511
diff changeset
315
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
316 call assert_equal([1, 2], rubyeval('Vim::evaluate("[1, 2]")'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
317 call assert_equal('Array', rubyeval('Vim::evaluate("[1, 2]").class'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
318
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
319 call assert_equal({'1': 2}, rubyeval('Vim::evaluate("{1:2}")'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
320 call assert_equal('Hash', rubyeval('Vim::evaluate("{1:2}").class'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
321
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
322 call assert_equal(v:null, rubyeval('Vim::evaluate("v:null")'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
323 call assert_equal('NilClass', rubyeval('Vim::evaluate("v:null").class'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
324
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
325 call assert_equal(v:null, rubyeval('Vim::evaluate("v:none")'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
326 call assert_equal('NilClass', rubyeval('Vim::evaluate("v:none").class'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
327
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
328 call assert_equal(v:true, rubyeval('Vim::evaluate("v:true")'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
329 call assert_equal('TrueClass', rubyeval('Vim::evaluate("v:true").class'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
330 call assert_equal(v:false, rubyeval('Vim::evaluate("v:false")'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
331 call assert_equal('FalseClass',rubyeval('Vim::evaluate("v:false").class'))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
332 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
333
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
334 func Test_ruby_Vim_blob()
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
335 call assert_equal('0z', rubyeval('Vim::blob("")'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
336 call assert_equal('0z31326162', rubyeval('Vim::blob("12ab")'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
337 call assert_equal('0z00010203', rubyeval('Vim::blob("\x00\x01\x02\x03")'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
338 call assert_equal('0z8081FEFF', rubyeval('Vim::blob("\x80\x81\xfe\xff")'))
15943
e5f82e8b3c06 patch 8.1.0977: blob not tested with Ruby
Bram Moolenaar <Bram@vim.org>
parents: 14511
diff changeset
339 endfunc
e5f82e8b3c06 patch 8.1.0977: blob not tested with Ruby
Bram Moolenaar <Bram@vim.org>
parents: 14511
diff changeset
340
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
341 func Test_ruby_Vim_evaluate_list()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
342 call setline(line('$'), ['2 line 2'])
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
343 ruby Vim.command("normal /^2\n")
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
344 let l = ["abc", "def"]
20045
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
345 ruby << trim EOF
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
346 curline = $curbuf.line_number
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
347 l = Vim.evaluate("l");
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
348 $curbuf.append(curline, l.join("\n"))
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
349 EOF
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
350 normal j
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
351 .rubydo $_ = $_.gsub(/\n/, '/')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
352 call assert_equal('abc/def', getline('$'))
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
353 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
354
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
355 func Test_ruby_Vim_evaluate_dict()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
356 let d = {'a': 'foo', 'b': 123}
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
357 redir => l:out
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
358 ruby d = Vim.evaluate("d"); print d
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
359 redir END
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
360 call assert_equal(['{"a"=>"foo", "b"=>123}'], split(l:out, "\n"))
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
361 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
362
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
363 " Test Vim::message({msg}) (display message {msg})
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
364 func Test_ruby_Vim_message()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
365 ruby Vim::message('A message')
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
366 let messages = split(execute('message'), "\n")
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
367 call assert_equal('A message', messages[-1])
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
368 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
369
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
370 func Test_ruby_print()
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
371 func RubyPrint(expr)
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
372 return trim(execute('ruby print ' . a:expr))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
373 endfunc
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
374
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
375 call assert_equal('123', RubyPrint('123'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
376 call assert_equal('1.23', RubyPrint('1.23'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
377 call assert_equal('Hello World!', RubyPrint('"Hello World!"'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
378 call assert_equal('[1, 2]', RubyPrint('[1, 2]'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
379 call assert_equal('{"k1"=>"v1", "k2"=>"v2"}', RubyPrint('({"k1" => "v1", "k2" => "v2"})'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
380 call assert_equal('true', RubyPrint('true'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
381 call assert_equal('false', RubyPrint('false'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
382 call assert_equal('', RubyPrint('nil'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
383 call assert_match('Vim', RubyPrint('Vim'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
384 call assert_match('Module', RubyPrint('Vim.class'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
385
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
386 delfunc RubyPrint
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
387 endfunc
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
388
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18344
diff changeset
389 func Test_ruby_p()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
390 ruby p 'Just a test'
20221
ec0ace1ddc20 patch 8.2.0666: Ruby test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
391 let messages = GetMessages()
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
392 call assert_equal('"Just a test"', messages[-1])
14511
e6ad77cf13e0 patch 8.1.0269: Ruby Kernel.#p method always returns nil
Christian Brabandt <cb@256bit.org>
parents: 14413
diff changeset
393
e6ad77cf13e0 patch 8.1.0269: Ruby Kernel.#p method always returns nil
Christian Brabandt <cb@256bit.org>
parents: 14413
diff changeset
394 " Check return values of p method
e6ad77cf13e0 patch 8.1.0269: Ruby Kernel.#p method always returns nil
Christian Brabandt <cb@256bit.org>
parents: 14413
diff changeset
395
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
396 call assert_equal(123, rubyeval('p(123)'))
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
397 call assert_equal([1, 2, 3], rubyeval('p(1, 2, 3)'))
14511
e6ad77cf13e0 patch 8.1.0269: Ruby Kernel.#p method always returns nil
Christian Brabandt <cb@256bit.org>
parents: 14413
diff changeset
398
e6ad77cf13e0 patch 8.1.0269: Ruby Kernel.#p method always returns nil
Christian Brabandt <cb@256bit.org>
parents: 14413
diff changeset
399 " Avoid the "message maintainer" line.
e6ad77cf13e0 patch 8.1.0269: Ruby Kernel.#p method always returns nil
Christian Brabandt <cb@256bit.org>
parents: 14413
diff changeset
400 let $LANG = ''
e6ad77cf13e0 patch 8.1.0269: Ruby Kernel.#p method always returns nil
Christian Brabandt <cb@256bit.org>
parents: 14413
diff changeset
401 messages clear
16103
518f44125207 patch 8.1.1056: no eval function for Ruby
Bram Moolenaar <Bram@vim.org>
parents: 15943
diff changeset
402 call assert_equal(v:true, rubyeval('p() == nil'))
14511
e6ad77cf13e0 patch 8.1.0269: Ruby Kernel.#p method always returns nil
Christian Brabandt <cb@256bit.org>
parents: 14413
diff changeset
403
20221
ec0ace1ddc20 patch 8.2.0666: Ruby test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
404 let messages = GetMessages()
14511
e6ad77cf13e0 patch 8.1.0269: Ruby Kernel.#p method always returns nil
Christian Brabandt <cb@256bit.org>
parents: 14413
diff changeset
405 call assert_equal(0, len(messages))
14413
c3b62844ee4e patch 8.1.0221: not enough testing for the Ruby interface
Christian Brabandt <cb@256bit.org>
parents: 14411
diff changeset
406 endfunc
20045
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
407
20939
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
408 func Test_rubyeval_error()
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
409 " On Linux or Windows the error matches:
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
410 " "syntax error, unexpected end-of-input"
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
411 " whereas on macOS in CI, the error message makes less sense:
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
412 " "SyntaxError: array length must be 2"
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
413 " Unclear why. The test does not check the error message.
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
414 call assert_fails('call rubyeval("(")')
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
415 endfunc
b7b074a8d737 patch 8.2.1021: Ruby interface not tested enough
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
416
20045
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
417 " Test for various heredoc syntax
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
418 func Test_ruby_heredoc()
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
419 ruby << END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
420 Vim.command('let s = "A"')
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
421 END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
422 ruby <<
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
423 Vim.command('let s ..= "B"')
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
424 .
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
425 ruby << trim END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
426 Vim.command('let s ..= "C"')
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
427 END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
428 ruby << trim
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
429 Vim.command('let s ..= "D"')
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
430 .
20233
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20221
diff changeset
431 ruby << trim eof
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20221
diff changeset
432 Vim.command('let s ..= "E"')
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20221
diff changeset
433 eof
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20221
diff changeset
434 call assert_equal('ABCDE', s)
20045
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
435 endfunc
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
436
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
437 " vim: shiftwidth=2 sts=2 expandtab