neovim 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ require "helper"
2
+ require "socket"
3
+ require "msgpack"
4
+ require "fileutils"
5
+
6
+ module Neovim
7
+ RSpec.describe EventLoop do
8
+ shared_context "socket behaviors" do
9
+ it "sends and receives data" do
10
+ messages = []
11
+
12
+ srv_thr = Thread.new do
13
+ client = server.accept
14
+ messages << client.read_nonblock(1024)
15
+
16
+ client.write("from server")
17
+ client.close
18
+ server.close
19
+ end
20
+
21
+ event_loop.send("data").run do |msg|
22
+ expect(msg).to eq("from server")
23
+ event_loop.shutdown
24
+ end
25
+
26
+ srv_thr.join
27
+ expect(messages).to eq(["data"])
28
+ end
29
+ end
30
+
31
+ context "tcp" do
32
+ let!(:server) { TCPServer.new("0.0.0.0", 0) }
33
+ let!(:event_loop) { EventLoop.tcp("0.0.0.0", server.addr[1]) }
34
+
35
+ include_context "socket behaviors"
36
+ end
37
+
38
+ context "unix" do
39
+ before { FileUtils.rm_f("/tmp/#$$.sock") }
40
+ let!(:server) { UNIXServer.new("/tmp/#$$.sock") }
41
+ let!(:event_loop) { EventLoop.unix("/tmp/#$$.sock") }
42
+
43
+ include_context "socket behaviors"
44
+ end
45
+
46
+ context "child" do
47
+ it "sends and receives data" do
48
+ event_loop = EventLoop.child(["-n", "-u", "NONE"])
49
+ message = MessagePack.pack([0, 0, :vim_strwidth, ["hi"]])
50
+
51
+ event_loop.send(message).run do |msg|
52
+ expect(msg).to eq(MessagePack.pack([1, 0, nil, 2]))
53
+ event_loop.shutdown
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,29 @@
1
+ require "socket"
2
+ require "helper"
3
+
4
+ module Neovim
5
+ RSpec.describe MsgpackStream do
6
+ it "sends and receives msgpack" do
7
+ server = TCPServer.new("0.0.0.0", 0)
8
+ event_loop = EventLoop.tcp("0.0.0.0", server.addr[1])
9
+ stream = MsgpackStream.new(event_loop)
10
+ messages = []
11
+
12
+ srv_thr = Thread.new do
13
+ client = server.accept
14
+ messages << client.read_nonblock(1024)
15
+
16
+ client.write(MessagePack.pack([2]))
17
+ client.close
18
+ server.close
19
+ end
20
+
21
+ stream.send([1]).run do |msg|
22
+ expect(msg).to eq([2])
23
+ stream.shutdown
24
+ end
25
+
26
+ expect(messages).to eq([MessagePack.pack([1])])
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require "helper"
2
+
3
+ module Neovim
4
+ RSpec.describe Session do
5
+ let(:session) do
6
+ event_loop = EventLoop.child(["-n", "-u", "NONE"])
7
+ stream = MsgpackStream.new(event_loop)
8
+ async = AsyncSession.new(stream)
9
+ Session.new(async)
10
+ end
11
+
12
+ it "exposes a synchronous API" do
13
+ expect(session.request(:vim_strwidth, "foobar")).to eq(6)
14
+ end
15
+
16
+ it "raises an exception when there are errors" do
17
+ expect {
18
+ session.request(:vim_strwidth, "too", "many")
19
+ }.to raise_error("Wrong number of arguments: expecting 1 but got 2")
20
+ end
21
+
22
+ describe "#api_methods_for_prefix" do
23
+ it "returns relevant functions without a prefix" do
24
+ methods = session.api_methods_for_prefix("vim_")
25
+ expect(methods).to include(:strwidth)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ require "helper"
2
+
3
+ module Neovim
4
+ RSpec.describe Tabpage do
5
+ let(:tabpage) { Neovim.attach_child(["-n", "-u", "NONE"]).current.tabpage }
6
+
7
+ describe "#respond_to?" do
8
+ it "returns true for Tabpage functions" do
9
+ expect(tabpage).to respond_to(:is_valid)
10
+ end
11
+
12
+ it "returns true for Ruby functions" do
13
+ expect(tabpage).to respond_to(:inspect)
14
+ end
15
+
16
+ it "returns false otherwise" do
17
+ expect(tabpage).not_to respond_to(:foobar)
18
+ end
19
+ end
20
+
21
+ describe "#method_missing" do
22
+ it "enables tabpage_* function calls" do
23
+ expect(tabpage.is_valid).to be(true)
24
+ end
25
+ end
26
+
27
+ describe "#methods" do
28
+ it "returns builtin methods" do
29
+ expect(tabpage.methods).to include(:inspect)
30
+ end
31
+
32
+ it "returns api methods" do
33
+ expect(tabpage.methods).to include(:get_windows)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ require "helper"
2
+
3
+ module Neovim
4
+ RSpec.describe Window do
5
+ let(:window) { Neovim.attach_child(["-n", "-u", "NONE"]).current.window }
6
+
7
+ describe "#respond_to?" do
8
+ it "returns true for Window functions" do
9
+ expect(window).to respond_to(:get_cursor)
10
+ end
11
+
12
+ it "returns true for Ruby functions" do
13
+ expect(window).to respond_to(:inspect)
14
+ end
15
+
16
+ it "returns false otherwise" do
17
+ expect(window).not_to respond_to(:foobar)
18
+ end
19
+ end
20
+
21
+ describe "#method_missing" do
22
+ it "enables window_* function calls" do
23
+ expect(window.get_cursor).to eq([1, 0])
24
+ end
25
+ end
26
+
27
+ describe "#methods" do
28
+ it "returns builtin methods" do
29
+ expect(window.methods).to include(:inspect)
30
+ end
31
+
32
+ it "returns api methods" do
33
+ expect(window.methods).to include(:get_height)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,54 @@
1
+ require "helper"
2
+ require "fileutils"
3
+
4
+ RSpec.describe Neovim do
5
+ let(:nvim_exe) { ENV.fetch("NVIM_EXECUTABLE") }
6
+ let(:nvim_argv) { %w(--headless -u NONE -i NONE -N -n) }
7
+
8
+ describe ".attach_tcp" do
9
+ it "attaches to a TCP socket" do
10
+ srv = TCPServer.new("0.0.0.0", 0)
11
+ port = srv.addr[1]
12
+ srv.close
13
+
14
+ env = {"NVIM_LISTEN_ADDRESS" => "0.0.0.0:#{port}"}
15
+ pid = Process.spawn(env, nvim_exe, *nvim_argv, [:out, :err] => "/dev/null")
16
+
17
+ begin
18
+ wait_socket = TCPSocket.open("0.0.0.0", port)
19
+ rescue Errno::ECONNREFUSED
20
+ retry
21
+ end
22
+ wait_socket.close
23
+
24
+ begin
25
+ expect(Neovim.attach_tcp("0.0.0.0", port).strwidth("hi")).to eq(2)
26
+ ensure
27
+ Process.kill(:TERM, pid)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe ".attach_unix" do
33
+ it "attaches to a UNIX socket" do
34
+ FileUtils.rm_f("/tmp/#$$.sock")
35
+ env = {"NVIM_LISTEN_ADDRESS" => "/tmp/#$$.sock"}
36
+ pid = Process.spawn(env, nvim_exe, *nvim_argv, [:out, :err] => "/dev/null")
37
+
38
+ loop { break if File.exists?("/tmp/#$$.sock") }
39
+
40
+ begin
41
+ expect(Neovim.attach_unix("/tmp/#$$.sock").strwidth("hi")).to eq(2)
42
+ ensure
43
+ Process.kill(:TERM, pid)
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "attach_child" do
49
+ it "spawns and attaches to a child process" do
50
+ nvim = Neovim.attach_child(nvim_argv)
51
+ expect(nvim.strwidth("hi")).to eq(2)
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neovim
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Genco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: msgpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.0dev1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.7.0dev1
27
+ - !ruby/object:Gem::Dependency
28
+ name: eventmachine
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.7.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.7.2
97
+ description:
98
+ email:
99
+ - alexgenco@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".coveralls.yml"
105
+ - ".gitignore"
106
+ - ".gitmodules"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - lib/neovim.rb
113
+ - lib/neovim/api_info.rb
114
+ - lib/neovim/async_session.rb
115
+ - lib/neovim/client.rb
116
+ - lib/neovim/current.rb
117
+ - lib/neovim/event_loop.rb
118
+ - lib/neovim/msgpack_stream.rb
119
+ - lib/neovim/object.rb
120
+ - lib/neovim/session.rb
121
+ - lib/neovim/version.rb
122
+ - neovim.gemspec
123
+ - spec/helper.rb
124
+ - spec/neovim/async_session_spec.rb
125
+ - spec/neovim/buffer_spec.rb
126
+ - spec/neovim/client_spec.rb
127
+ - spec/neovim/current_spec.rb
128
+ - spec/neovim/event_loop_spec.rb
129
+ - spec/neovim/msgpack_stream_spec.rb
130
+ - spec/neovim/session_spec.rb
131
+ - spec/neovim/tabpage_spec.rb
132
+ - spec/neovim/window_spec.rb
133
+ - spec/neovim_spec.rb
134
+ homepage: https://github.com/alexgenco/neovim-ruby
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.6
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: A Ruby client for Neovim
158
+ test_files:
159
+ - spec/helper.rb
160
+ - spec/neovim/async_session_spec.rb
161
+ - spec/neovim/buffer_spec.rb
162
+ - spec/neovim/client_spec.rb
163
+ - spec/neovim/current_spec.rb
164
+ - spec/neovim/event_loop_spec.rb
165
+ - spec/neovim/msgpack_stream_spec.rb
166
+ - spec/neovim/session_spec.rb
167
+ - spec/neovim/tabpage_spec.rb
168
+ - spec/neovim/window_spec.rb
169
+ - spec/neovim_spec.rb