-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy pathprocess_client_server_test.rb
More file actions
86 lines (69 loc) · 2.11 KB
/
Copy pathprocess_client_server_test.rb
File metadata and controls
86 lines (69 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# typed: true
# frozen_string_literal: true
require "test_helper"
require "ruby_lsp/addon/process_client"
module RubyLsp
class Addon
class ProcessClientServerTest < Minitest::Test
class FakeClient < ProcessClient
def initialize(addon)
server_path = File.expand_path("../fake_process_server.rb", __FILE__)
super(addon, "bundle exec ruby #{server_path}")
end
def echo(message)
make_request("echo", { message: message })
end
def send_unknown_request
send_message("unknown_request")
end
def log_output(message)
# No-op for testing to reduce noise
end
private
def handle_initialize_response(response)
raise InitializationError, "Server not initialized" unless response[:initialized]
end
def register_exit_handler
# No-op for testing
end
end
def setup
@addon = create_fake_addon
@client = FakeClient.new(@addon)
end
def teardown
@client.shutdown
assert_predicate(@client, :stopped?, "Client should be stopped after shutdown")
RubyLsp::Addon.addons.clear
RubyLsp::Addon.addon_classes.clear
end
def test_client_server_communication
response = @client.echo("Hello, World!")
assert_equal({ echo_result: "Hello, World!" }, response)
end
def test_server_initialization
# The server is already initialized in setup, so we just need to verify it didn't raise an error
assert_instance_of(FakeClient, @client)
end
def test_server_ignores_unknown_request
@client.send_unknown_request
response = @client.echo("Hey!")
assert_equal({ echo_result: "Hey!" }, response)
end
private
def create_fake_addon
Class.new(Addon) do
def name
"FakeAddon"
end
def activate(global_state, outgoing_queue)
# No-op for testing
end
def deactivate
# No-op for testing
end
end.new
end
end
end
end