neovim 0.6.2 → 0.9.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/docs.yml +36 -0
  3. data/.github/workflows/linter.yml +32 -0
  4. data/.github/workflows/tests.yml +62 -0
  5. data/.gitignore +5 -1
  6. data/.rubocop.yml +149 -0
  7. data/CHANGELOG.md +56 -0
  8. data/CODE_OF_CONDUCT.md +3 -3
  9. data/Gemfile +0 -11
  10. data/README.md +22 -23
  11. data/Rakefile +47 -15
  12. data/VimFlavor +1 -0
  13. data/exe/neovim-ruby-host +5 -0
  14. data/lib/neovim.rb +15 -6
  15. data/lib/neovim/api.rb +2 -1
  16. data/lib/neovim/buffer.rb +81 -53
  17. data/lib/neovim/client.rb +226 -41
  18. data/lib/neovim/client_info.rb +46 -0
  19. data/lib/neovim/connection.rb +73 -0
  20. data/lib/neovim/event_loop.rb +41 -37
  21. data/lib/neovim/executable.rb +1 -0
  22. data/lib/neovim/host.rb +50 -51
  23. data/lib/neovim/host/cli.rb +41 -0
  24. data/lib/neovim/host/loader.rb +1 -4
  25. data/lib/neovim/line_range.rb +16 -16
  26. data/lib/neovim/logging.rb +18 -18
  27. data/lib/neovim/message.rb +70 -0
  28. data/lib/neovim/plugin.rb +7 -5
  29. data/lib/neovim/plugin/dsl.rb +10 -4
  30. data/lib/neovim/plugin/handler.rb +8 -8
  31. data/lib/neovim/remote_object.rb +8 -5
  32. data/lib/neovim/ruby_provider.rb +52 -26
  33. data/lib/neovim/ruby_provider/buffer_ext.rb +1 -0
  34. data/lib/neovim/ruby_provider/object_ext.rb +5 -0
  35. data/lib/neovim/ruby_provider/vim.rb +19 -6
  36. data/lib/neovim/ruby_provider/window_ext.rb +1 -0
  37. data/lib/neovim/session.rb +45 -50
  38. data/lib/neovim/tabpage.rb +8 -15
  39. data/lib/neovim/version.rb +1 -1
  40. data/lib/neovim/window.rb +39 -36
  41. data/neovim.gemspec +11 -6
  42. data/script/ci/download_nvim.sh +40 -0
  43. data/script/{dump_api → dump_api.rb} +1 -1
  44. data/script/{generate_docs → generate_docs.rb} +6 -7
  45. data/script/{j2mp → j2mp.rb} +0 -0
  46. data/script/{mp2j → mp2j.rb} +0 -0
  47. data/script/run_acceptance.rb +39 -0
  48. data/spec/acceptance/client_info_spec.vim +42 -0
  49. data/spec/acceptance/rplugin_autocmd_spec.vim +20 -10
  50. data/spec/acceptance/rplugin_command_spec.vim +54 -56
  51. data/spec/acceptance/rplugin_function_spec.vim +28 -22
  52. data/spec/acceptance/ruby_spec.vim +52 -53
  53. data/spec/acceptance/rubydo_spec.vim +49 -52
  54. data/spec/acceptance/rubyeval_spec.vim +22 -0
  55. data/spec/acceptance/rubyfile/curbuf_ivar_get.rb +1 -1
  56. data/spec/acceptance/rubyfile/curbuf_ivar_set.rb +1 -1
  57. data/spec/acceptance/rubyfile/define_foo.rb +1 -1
  58. data/spec/acceptance/rubyfile/nested.rb +1 -1
  59. data/spec/acceptance/rubyfile/nested_inner.rb +1 -1
  60. data/spec/acceptance/rubyfile/set_pwd_after.rb +1 -1
  61. data/spec/acceptance/rubyfile/set_pwd_before.rb +1 -1
  62. data/spec/acceptance/rubyfile_spec.vim +60 -66
  63. data/spec/acceptance/runtime/init.vim +5 -4
  64. data/spec/acceptance/runtime/rplugin/ruby/autocmds.rb +7 -3
  65. data/spec/acceptance/runtime/rplugin/ruby/commands.rb +18 -17
  66. data/spec/acceptance/runtime/rplugin/ruby/functions.rb +9 -9
  67. data/spec/helper.rb +38 -9
  68. data/spec/neovim/api_spec.rb +2 -2
  69. data/spec/neovim/buffer_spec.rb +10 -6
  70. data/spec/neovim/client_info_spec.rb +77 -0
  71. data/spec/neovim/client_spec.rb +19 -12
  72. data/spec/neovim/connection_spec.rb +106 -0
  73. data/spec/neovim/current_spec.rb +13 -14
  74. data/spec/neovim/event_loop_spec.rb +48 -46
  75. data/spec/neovim/executable_spec.rb +2 -2
  76. data/spec/neovim/host/cli_spec.rb +94 -0
  77. data/spec/neovim/host/loader_spec.rb +18 -11
  78. data/spec/neovim/host_spec.rb +84 -92
  79. data/spec/neovim/line_range_spec.rb +17 -19
  80. data/spec/neovim/logging_spec.rb +3 -3
  81. data/spec/neovim/message_spec.rb +119 -0
  82. data/spec/neovim/plugin_spec.rb +34 -34
  83. data/spec/neovim/remote_object_spec.rb +1 -2
  84. data/spec/neovim/ruby_provider/buffer_ext_spec.rb +8 -9
  85. data/spec/neovim/ruby_provider/object_ext_spec.rb +10 -0
  86. data/spec/neovim/ruby_provider/vim_spec.rb +5 -5
  87. data/spec/neovim/ruby_provider/window_ext_spec.rb +12 -15
  88. data/spec/neovim/session_spec.rb +20 -47
  89. data/spec/neovim/window_spec.rb +1 -2
  90. data/spec/neovim_spec.rb +28 -51
  91. data/spec/support.rb +27 -1
  92. metadata +83 -48
  93. data/.coveralls.yml +0 -1
  94. data/.gitmodules +0 -3
  95. data/.rspec +0 -1
  96. data/.travis.yml +0 -23
  97. data/appveyor.yml +0 -21
  98. data/bin/neovim-ruby-host +0 -18
  99. data/lib/neovim/event_loop/connection.rb +0 -78
  100. data/lib/neovim/event_loop/message_builder.rb +0 -127
  101. data/lib/neovim/event_loop/serializer.rb +0 -37
  102. data/spec/acceptance/runtime/rplugin.vim +0 -37
  103. data/spec/acceptance/runtime/vader.vim/autoload/vader.vim +0 -348
  104. data/spec/acceptance/runtime/vader.vim/autoload/vader/assert.vim +0 -116
  105. data/spec/acceptance/runtime/vader.vim/autoload/vader/helper.vim +0 -43
  106. data/spec/acceptance/runtime/vader.vim/autoload/vader/parser.vim +0 -179
  107. data/spec/acceptance/runtime/vader.vim/autoload/vader/syntax.vim +0 -73
  108. data/spec/acceptance/runtime/vader.vim/autoload/vader/window.vim +0 -205
  109. data/spec/acceptance/runtime/vader.vim/plugin/vader.vim +0 -37
  110. data/spec/acceptance_spec.rb +0 -82
  111. data/spec/neovim/event_loop/connection_spec.rb +0 -89
  112. data/spec/neovim/event_loop/message_builder_spec.rb +0 -105
  113. data/spec/neovim/event_loop/serializer_spec.rb +0 -63
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -eu
4
+
5
+ : ${RUNNER_OS:?} ${BUILD:?}
6
+
7
+ case "$BUILD" in
8
+ latest)
9
+ URL_PART="latest/download"
10
+ ;;
11
+ nightly)
12
+ URL_PART="download/nightly"
13
+ ;;
14
+ *)
15
+ echo "BUILD must be 'latest' or 'nightly'." >&2
16
+ exit 1
17
+ ;;
18
+ esac
19
+
20
+ case "$(echo "$RUNNER_OS" | tr "[:upper:]" "[:lower:]")" in
21
+ macos)
22
+ wget -nv -P /tmp \
23
+ "https://github.com/neovim/neovim/releases/$URL_PART/nvim-macos.tar.gz"
24
+ tar -C /tmp -xzf /tmp/nvim-macos.tar.gz
25
+ mv /tmp/nvim-osx64 ./_nvim
26
+ ;;
27
+ linux)
28
+ mkdir -p _nvim/bin
29
+ wget -nv -O _nvim/bin/nvim \
30
+ "https://github.com/neovim/neovim/releases/$URL_PART/nvim.appimage"
31
+ ;;
32
+ *)
33
+ echo "Unrecognized \$RUNNER_OS" >&2
34
+ exit 1
35
+ ;;
36
+ esac
37
+
38
+ chmod u+x _nvim/bin/nvim
39
+
40
+ _nvim/bin/nvim --version
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift File.expand_path("../../lib", __FILE__)
3
+ $:.unshift File.expand_path("../lib", __dir__)
4
4
 
5
5
  require "neovim"
6
6
  require "json"
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift File.expand_path("../../lib", __FILE__)
3
+ $:.unshift File.expand_path("../lib", __dir__)
4
4
 
5
5
  require "neovim"
6
6
  require "pathname"
@@ -19,10 +19,6 @@ buffer_defs = Neovim::Buffer.instance_methods(false)
19
19
  tabpage_defs = Neovim::Tabpage.instance_methods(false)
20
20
  window_defs = Neovim::Window.instance_methods(false)
21
21
 
22
- def add_method(docs, defs, method_name)
23
- return if defs.include?(method_name.to_s)
24
- end
25
-
26
22
  session.request(:nvim_get_api_info)[1]["functions"].each do |func|
27
23
  func_name = func["name"]
28
24
  params = func["parameters"]
@@ -30,16 +26,18 @@ session.request(:nvim_get_api_info)[1]["functions"].each do |func|
30
26
  case func_name
31
27
  when /^nvim_buf_(.+)/
32
28
  method_name = $1
29
+ params.shift
33
30
  next if buffer_defs.include?(method_name.to_sym)
34
31
  when /^nvim_win_(.+)/
35
32
  method_name = $1
33
+ params.shift
36
34
  next if window_defs.include?(method_name.to_sym)
37
35
  when /^nvim_tabpage_(.+)/
38
36
  method_name = $1
37
+ params.shift
39
38
  next if tabpage_defs.include?(method_name.to_sym)
40
39
  when /^nvim_(.+)/
41
40
  method_name = $1
42
- params.shift
43
41
  next if nvim_defs.include?(method_name.to_sym)
44
42
  else
45
43
  next
@@ -72,7 +70,8 @@ session.request(:nvim_get_api_info)[1]["functions"].each do |func|
72
70
  end
73
71
  end
74
72
 
75
- lib_dir = Pathname.new(File.expand_path("../../lib/neovim", __FILE__))
73
+ lib_dir = Pathname.new(File.expand_path("../lib/neovim", __dir__))
74
+
76
75
  {
77
76
  "client.rb" => nvim_docs,
78
77
  "buffer.rb" => buffer_docs,
File without changes
File without changes
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "fileutils"
4
+
5
+ ENV.delete("VIM")
6
+ ENV.delete("VIMRUNTIME")
7
+
8
+ root = File.expand_path("..", __dir__)
9
+ acceptance_root = File.join(root, "spec/acceptance")
10
+ themis_rtp = File.join(acceptance_root, "runtime")
11
+ themis_home = File.join(themis_rtp, "flavors/thinca_vim-themis")
12
+ manifest = File.join(themis_rtp, "rplugin_manifest.vim")
13
+ vimrc = File.join(themis_rtp, "init.vim")
14
+ nvim = ENV.fetch("NVIM_EXECUTABLE", "nvim")
15
+
16
+ themis_exe = Gem.win_platform? ?
17
+ File.join(themis_home, "bin/themis.bat") :
18
+ File.join(themis_home, "bin/themis")
19
+
20
+ env = {
21
+ "NVIM_RPLUGIN_MANIFEST" => manifest,
22
+ "THEMIS_VIM" => nvim,
23
+ "THEMIS_HOME" => themis_home,
24
+ "THEMIS_ARGS" => "-e -s --headless -u #{vimrc}"
25
+ }
26
+
27
+ FileUtils.rm_f(manifest)
28
+
29
+ Dir.chdir(root) do
30
+ system(
31
+ env,
32
+ nvim,
33
+ "-e", "-s", "--headless",
34
+ "-u", vimrc,
35
+ "+UpdateRemotePlugins", "+qa!"
36
+ )
37
+
38
+ exec(env, themis_exe, *ARGV)
39
+ end
@@ -0,0 +1,42 @@
1
+ let s:suite = themis#suite("Client info")
2
+ let s:expect = themis#helper("expect")
3
+
4
+ function! s:suite.before_each() abort
5
+ call RPluginFunctionArgs(1, 2)
6
+
7
+ let s:client_chans = map(
8
+ \ filter(nvim_list_chans(), "has_key(v:val, 'client')"),
9
+ \ "v:val.client")
10
+ endfunction
11
+
12
+ function! s:suite.get_script_host_client_info() abort
13
+ let client_info = s:client_chans[1]
14
+
15
+ call s:expect(sort(keys(client_info))).to_equal(
16
+ \ ["attributes", "methods", "name", "type", "version"])
17
+
18
+ call s:expect(client_info.attributes).to_be_dict()
19
+ call s:expect(client_info.methods).to_equal({"specs": {"nargs": 1}, "poll": {}})
20
+ call s:expect(client_info.name).to_equal("ruby-script-host")
21
+ call s:expect(client_info.type).to_equal("host")
22
+
23
+ call s:expect(client_info.version.major).to_be_number()
24
+ call s:expect(client_info.version.minor).to_be_number()
25
+ call s:expect(client_info.version.patch).to_be_number()
26
+ endfunction
27
+
28
+ function! s:suite.get_rplugin_client_info() abort
29
+ let client_info = s:client_chans[0]
30
+
31
+ call s:expect(sort(keys(client_info))).to_equal(
32
+ \ ["attributes", "methods", "name", "type", "version"])
33
+
34
+ call s:expect(client_info.attributes).to_be_dict()
35
+ call s:expect(client_info.methods).to_equal({"specs": {"nargs": 1}, "poll": {}})
36
+ call s:expect(client_info.name).to_equal("ruby-rplugin-host")
37
+ call s:expect(client_info.type).to_equal("host")
38
+
39
+ call s:expect(client_info.version.major).to_be_number()
40
+ call s:expect(client_info.version.minor).to_be_number()
41
+ call s:expect(client_info.version.patch).to_be_number()
42
+ endfunction
@@ -1,18 +1,28 @@
1
- Before (Generate rplugin manifest):
2
- silent UpdateRemotePlugins
1
+ let s:suite = themis#suite("Remote plugin autocmd")
2
+ let s:expect = themis#helper("expect")
3
3
 
4
- Execute (Trigger event for matching patterns):
4
+ function! s:suite.has_nvim() abort
5
+ call s:expect(has("nvim")).to_equal(1)
6
+ endfunction
7
+
8
+ function! s:suite.triggers_for_matched_pattern() abort
5
9
  silent split file.rb
6
- sleep 50m
7
- AssertEqual v:true, b:rplugin_autocmd_BufEnter
10
+ call s:expect(b:rplugin_autocmd_BufEnter).to_equal(v:true)
11
+ endfunction
8
12
 
9
- Execute (Don't trigger event for non-matching patterns):
13
+ function! s:suite.doesnt_trigger_for_unmatched_pattern() abort
10
14
  silent split file.py
11
- sleep 50m
12
- AssertEqual 0, exists("b:rplugin_autocmd_BufEnter")
15
+ call s:expect(exists('b:rplugin_autocmd_BufEnter')).to_equal(0)
16
+ endfunction
13
17
 
14
- Execute (Trigger event with eval):
18
+ function! s:suite.supports_eval() abort
15
19
  let g:to_eval = {'a': 42}
16
20
  silent split file.c
21
+ call s:expect(g:rplugin_autocmd_BufEnter_eval).to_equal({'a': 42, 'b': 43})
22
+ endfunction
23
+
24
+ function! s:suite.supports_async() abort
25
+ silent split file.async
17
26
  sleep 50m
18
- AssertEqual {'a': 42, 'b': 43}, g:rplugin_autocmd_BufEnter_eval
27
+ call s:expect(g:rplugin_autocmd_BufEnter_async).to_equal(v:true)
28
+ endfunction
@@ -1,7 +1,17 @@
1
- Before (Generate rplugin manifest):
2
- silent UpdateRemotePlugins
1
+ let s:suite = themis#suite("Remote plugin command")
2
+ let s:expect = themis#helper("expect")
3
3
 
4
- Execute (Call rplugin commands with arguments):
4
+ function! s:suite.before_each() abort
5
+ 1,$delete
6
+ call append(0, ["one", "two", "three"])
7
+ normal gg
8
+ endfunction
9
+
10
+ function! s:suite.has_nvim() abort
11
+ call s:expect(has("nvim")).to_equal(1)
12
+ endfunction
13
+
14
+ function! s:suite.supports_arguments() abort
5
15
  RPluginCommandNargs0
6
16
  RPluginCommandNargs1 1
7
17
  RPluginCommandNargsN
@@ -11,91 +21,79 @@ Execute (Call rplugin commands with arguments):
11
21
  RPluginCommandNargsQ 1
12
22
  RPluginCommandNargsP 1
13
23
  RPluginCommandNargsP 1 2
14
- sleep 100m
15
-
16
- Then:
17
- AssertEqual v:true, g:rplugin_command_nargs_0
18
- AssertEqual "1", g:rplugin_command_nargs_1
19
- AssertEqual ["1", "2"], g:rplugin_command_nargs_n
20
- AssertEqual "1", g:rplugin_command_nargs_q
21
- AssertEqual ["1", "2"], g:rplugin_command_nargs_p
22
24
 
23
- Given:
24
- one
25
- two
26
- three
25
+ call s:expect(g:rplugin_command_nargs_0).to_equal(v:true)
26
+ call s:expect(g:rplugin_command_nargs_1).to_equal("1")
27
+ call s:expect(g:rplugin_command_nargs_n).to_equal(["1", "2"])
28
+ call s:expect(g:rplugin_command_nargs_q).to_equal("1")
29
+ call s:expect(g:rplugin_command_nargs_p).to_equal(["1", "2"])
30
+ endfunction
27
31
 
28
- Execute (Call rplugin commands with a range):
32
+ function! s:suite.supports_line_range() abort
29
33
  RPluginCommandRange
30
- sleep 50m
31
- AssertEqual [1, 1], g:rplugin_command_range
34
+ call s:expect(g:rplugin_command_range).to_equal([1, 1])
32
35
 
33
36
  1,2RPluginCommandRange
34
- sleep 50m
35
- AssertEqual [1, 2], g:rplugin_command_range
37
+ call s:expect(g:rplugin_command_range).to_equal([1, 2])
36
38
 
37
39
  %RPluginCommandRange
38
- sleep 50m
39
- AssertEqual [1, 3], g:rplugin_command_range
40
+ call s:expect(g:rplugin_command_range).to_equal([1, 4])
40
41
 
41
42
  RPluginCommandRangeP
42
- sleep 50m
43
- AssertEqual [1, 3], g:rplugin_command_range_p
43
+ call s:expect(g:rplugin_command_range_p).to_equal([1, 4])
44
44
 
45
45
  1,2RPluginCommandRangeP
46
- sleep 50m
47
- AssertEqual [1, 2], g:rplugin_command_range_p
46
+ call s:expect(g:rplugin_command_range_p).to_equal([1, 2])
48
47
 
49
48
  %RPluginCommandRangeP
50
- sleep 50m
51
- AssertEqual [1, 3], g:rplugin_command_range_p
49
+ call s:expect(g:rplugin_command_range_p).to_equal([1, 4])
52
50
 
53
51
  RPluginCommandRangeN
54
- sleep 50m
55
- AssertEqual [1], g:rplugin_command_range_n
52
+ call s:expect(g:rplugin_command_range_n).to_equal([1])
56
53
 
57
54
  2RPluginCommandRangeN
58
- sleep 50m
59
- AssertEqual [2], g:rplugin_command_range_n
55
+ call s:expect(g:rplugin_command_range_n).to_equal([2])
56
+ endfunction
60
57
 
61
- Execute (Call rplugin commands with a count):
58
+ function! s:suite.supports_count() abort
62
59
  RPluginCommandCountN
63
- sleep 50m
64
- AssertEqual [1], g:rplugin_command_count_n
60
+ call s:expect(g:rplugin_command_count_n).to_equal([1])
65
61
 
66
62
  2RPluginCommandCountN
67
- sleep 50m
68
- AssertEqual [2], g:rplugin_command_count_n
63
+ call s:expect(g:rplugin_command_count_n).to_equal([2])
64
+ endfunction
69
65
 
70
- Execute (Call rplugin commands with a bang):
66
+ function! s:suite.supports_bang() abort
71
67
  RPluginCommandBang
72
- sleep 50m
73
- AssertEqual 0, g:rplugin_command_bang
68
+ call s:expect(g:rplugin_command_bang).to_equal(0)
74
69
 
75
70
  RPluginCommandBang!
76
- sleep 50m
77
- AssertEqual 1, g:rplugin_command_bang
71
+ call s:expect(g:rplugin_command_bang).to_equal(1)
72
+ endfunction
78
73
 
79
- Execute (Call rplugin commands with a register):
74
+ function! s:suite.supports_register() abort
80
75
  RPluginCommandRegister a
81
- sleep 50m
82
- AssertEqual "a", g:rplugin_command_register
76
+ call s:expect(g:rplugin_command_register).to_equal("a")
77
+ endfunction
83
78
 
84
- Execute (Call rplugin commands with completion):
79
+ function! s:suite.supports_completion() abort
85
80
  RPluginCommandCompletion
86
- sleep 50m
87
- AssertEqual "buffer", g:rplugin_command_completion
81
+ call s:expect(g:rplugin_command_completion).to_equal("buffer")
82
+ endfunction
88
83
 
89
- Execute (Call rplugin commands with eval):
84
+ function! s:suite.supports_eval() abort
90
85
  let g:to_eval = {'a': 42}
91
86
  RPluginCommandEval
92
- sleep 50m
93
- AssertEqual {'a': 42, 'b': 43}, g:rplugin_command_eval
87
+ call s:expect(g:rplugin_command_eval).to_equal({'a': 42, 'b': 43})
88
+ endfunction
94
89
 
95
- Execute (Call synchronous rplugin commands):
96
- RPluginCommandSync
97
- AssertEqual v:true, g:rplugin_command_sync
90
+ function! s:suite.supports_asynchronous_commands() abort
91
+ RPluginCommandAsync
92
+ sleep 50m
93
+ call s:expect(g:rplugin_command_async).to_equal(v:true)
94
+ endfunction
98
95
 
99
- Execute (Call recursive rplugin commands):
96
+ function! s:suite.supports_recursion() abort
100
97
  RPluginCommandRecursive 0
101
- AssertEqual "10", g:rplugin_command_recursive
98
+ call s:expect(g:rplugin_command_recursive).to_equal("10")
99
+ endfunction
@@ -1,29 +1,35 @@
1
- Before (Generate rplugin manifest):
2
- silent UpdateRemotePlugins
1
+ let s:suite = themis#suite("Remote plugin function")
2
+ let s:expect = themis#helper("expect")
3
3
 
4
- Execute (Call rplugin functions with arguments):
5
- call RPluginFunctionArgs(1, 2)
6
- sleep 50m
7
- AssertEqual [1, 2], g:rplugin_function_args
4
+ function! s:suite.before_each() abort
5
+ 1,$delete
6
+ call append(0, ["one", "two", "three"])
7
+ endfunction
8
8
 
9
- Given:
10
- one
11
- two
12
- three
9
+ function! s:suite.has_nvim() abort
10
+ call s:expect(has("nvim")).to_equal(1)
11
+ endfunction
13
12
 
14
- Execute (Call rplugin functions with a range):
15
- 1,2call RPluginFunctionRange()
16
- sleep 50m
17
- AssertEqual [1, 2], g:rplugin_function_range
13
+ function! s:suite.supports_arguments() abort
14
+ call s:expect(RPluginFunctionArgs(1, 2)).to_equal([1, 2])
15
+ endfunction
16
+
17
+ function! s:suite.supports_line_range() abort
18
+ 3,4call RPluginFunctionRange()
19
+ call s:expect(g:rplugin_function_range).to_equal([3, 4])
20
+ endfunction
18
21
 
19
- Execute (Call rplugin functions with eval):
22
+ function! s:suite.supports_eval() abort
20
23
  let g:to_eval = {'a': 42}
21
- call RPluginFunctionEval()
22
- sleep 50m
23
- AssertEqual {'a': 42, 'b': 43}, g:rplugin_function_eval
24
+ call s:expect(RPluginFunctionEval()).to_equal({"a": 42, "b": 43})
25
+ endfunction
24
26
 
25
- Execute (Call synchronous rplugin functions):
26
- AssertEqual v:true, RPluginFunctionSync()
27
+ function! s:suite.supports_asynchronous_functions() abort
28
+ call RPluginFunctionAsync()
29
+ sleep 50m
30
+ call s:expect(g:rplugin_function_async).to_equal(v:true)
31
+ endfunction
27
32
 
28
- Execute (Call recursive rplugin functions):
29
- AssertEqual 10, RPluginFunctionRecursive(0)
33
+ function! s:suite.supports_recursion() abort
34
+ call s:expect(RPluginFunctionRecursive(0)).to_equal(10)
35
+ endfunction
@@ -1,92 +1,91 @@
1
- Execute (Set nvim_version):
2
- if has('nvim')
3
- let g:nvim_version = api_info()['version']
4
- else
5
- let g:nvim_version = {'major': 99, 'minor': 99, 'patch': 99}
6
- endif
7
-
8
- Given:
9
- one
10
- two
11
-
12
- Execute (Define a Ruby method):
13
- ruby def foo; Vim.command("let g:called = 1"); end
14
-
15
- Execute (Call a Ruby method):
1
+ let s:suite = themis#suite(":ruby")
2
+ let s:expect = themis#helper("expect")
3
+
4
+ function! s:suite.before_each() abort
5
+ let s:pwd = getcwd()
6
+ 1,$delete
7
+ call append(0, ["one", "two"])
8
+ unlet! s:var
9
+ endfunction
10
+
11
+ function! s:suite.after_each() abort
12
+ execute("cd " . s:pwd)
13
+ endfunction
14
+
15
+ function! s:suite.has_nvim() abort
16
+ call s:expect(has("nvim")).to_equal(1)
17
+ endfunction
18
+
19
+ function! s:suite.defines_a_ruby_method() abort
20
+ ruby def foo; Vim.command("let s:var = 1"); end
16
21
  ruby foo
17
22
 
18
- Then:
19
- AssertEqual 1, g:called
23
+ call s:expect(s:var).to_equal(1)
24
+ endfunction
20
25
 
21
- Execute (Update instance state on `$curbuf`):
26
+ function! s:suite.persists_curbuf_state() abort
22
27
  ruby $curbuf.instance_variable_set(:@foo, 123)
23
- ruby Vim.command("let g:foo = #{$curbuf.instance_variable_get(:@foo)}")
28
+ ruby Vim.command("let s:var = #{$curbuf.instance_variable_get(:@foo)}")
24
29
 
25
- Then:
26
- AssertEqual 123, g:foo
30
+ call s:expect(s:var).to_equal(123)
31
+ endfunction
27
32
 
28
- Execute (Change the working directory explicitly):
33
+ function! s:suite.updates_working_directory() abort
29
34
  cd /
30
- ruby Vim.command("let g:ruby_pwd = '#{Dir.pwd.sub(/^C:/, '')}'")
35
+ ruby Vim.command("let s:var = '#{Dir.pwd.sub(/^[A-Z]:/, "")}'")
31
36
  cd -
32
37
 
33
- Then:
34
- if g:nvim_version['major'] > 0 || g:nvim_version['minor'] >= 2
35
- AssertEqual "/", g:ruby_pwd
36
- endif
38
+ call s:expect(s:var).to_equal("/")
39
+ endfunction
37
40
 
38
- Execute (Change the working directory implicitly):
41
+ function! s:suite.updates_working_directory_implicitly() abort
39
42
  split | lcd /
40
- ruby Vim.command("let g:before_pwd = '#{Dir.pwd}'")
43
+ ruby Vim.command("let s:var = ['#{Dir.pwd}']")
41
44
  wincmd p
42
- ruby Vim.command("let g:after_pwd = '#{Dir.pwd}'")
45
+ ruby Vim.command("call add(s:var, '#{Dir.pwd}')")
43
46
  wincmd p | lcd -
44
47
 
45
- Then:
46
- if g:nvim_version['major'] > 0 || g:nvim_version['minor'] >= 2
47
- AssertNotEqual g:before_pwd, g:after_pwd
48
- endif
48
+ call s:expect(len(s:var)).to_equal(2)
49
+ call s:expect(s:var[0]).not.to_equal(s:var[1])
50
+ endfunction
49
51
 
50
- Execute (Run nested Ruby commands):
51
- ruby Vim.command("ruby Vim.command('let g:ruby_nested = 123')")
52
+ function! s:suite.supports_nesting() abort
53
+ ruby Vim.command("ruby Vim.command('let s:var = 123')")
52
54
 
53
- Then:
54
- AssertEqual 123, g:ruby_nested
55
+ call s:expect(s:var).to_equal(123)
56
+ endfunction
55
57
 
56
- Execute (Raise a Ruby standard error):
58
+ function! s:suite.handles_standard_error() abort
57
59
  try
58
60
  ruby raise "BOOM"
59
61
  throw "Nothing raised"
60
62
  catch /BOOM/
61
63
  endtry
62
64
 
63
- ruby $curbuf[1] = "still works"
65
+ call s:suite.defines_a_ruby_method()
66
+ endfunction
64
67
 
65
- Expect:
66
- still works
67
- two
68
-
69
- Execute (Raise a Ruby syntax error):
68
+ function! s:suite.handles_syntax_error() abort
70
69
  try
71
70
  ruby puts[
72
71
  throw "Nothing raised"
73
72
  catch /SyntaxError/
74
73
  endtry
75
74
 
76
- ruby $curbuf[1] = "still works"
77
-
78
- Expect:
79
- still works
80
- two
75
+ call s:suite.defines_a_ruby_method()
76
+ endfunction
81
77
 
82
- Execute (Access Vim interface):
78
+ function! s:suite.exposes_Vim() abort
83
79
  ruby expect(Vim).to eq(VIM)
84
80
  ruby expect(Vim.strwidth("hi")).to eq(2)
81
+ endfunction
85
82
 
86
- Execute (Access Vim::Buffer interface):
83
+ function! s:suite.exposes_Buffer() abort
87
84
  ruby expect($curbuf).to be_a(Neovim::Buffer)
88
85
  ruby expect(Vim::Buffer.current).to eq($curbuf)
86
+ endfunction
89
87
 
90
- Execute (Access Vim::Window interface):
88
+ function! s:suite.exposes_Window() abort
91
89
  ruby expect($curwin).to be_a(Neovim::Window)
92
90
  ruby expect(Vim::Window.current).to eq($curwin)
91
+ endfunction