|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
| 3 | +def pretty_value(value) |
| 4 | + value.nil? ? 'nil' : value.to_s |
| 5 | +end |
| 6 | + |
| 7 | +# Requires |
| 8 | +# :settings : A hashtable of the inbound settings |
| 9 | +# :setting_value : The value that will be set to |
| 10 | +RSpec.shared_examples "a client setting" do |method_name| |
| 11 | + [ |
| 12 | + { :from => false, :setting => nil, :expected_setting => false }, |
| 13 | + { :from => false, :setting => false, :expected_setting => false }, |
| 14 | + { :from => false, :setting => true, :expected_setting => true }, |
| 15 | + { :from => true, :setting => nil, :expected_setting => true }, |
| 16 | + { :from => true, :setting => false, :expected_setting => false }, |
| 17 | + { :from => true, :setting => true, :expected_setting => true }, |
| 18 | + ].each do |testcase| |
| 19 | + context "When it transitions from #{pretty_value(testcase[:from])} with a setting value of #{pretty_value(testcase[:setting])}" do |
| 20 | + let(:setting_value) { testcase[:setting] } |
| 21 | + |
| 22 | + before(:each) do |
| 23 | + subject.instance_variable_set("@#{method_name}".intern, testcase[:from]) |
| 24 | + end |
| 25 | + |
| 26 | + it "should have a cached value to #{testcase[:expected_setting]}" do |
| 27 | + expect(subject.send(method_name)).to eq(testcase[:from]) |
| 28 | + |
| 29 | + subject.parse_lsp_configuration_settings!(settings) |
| 30 | + expect(subject.send(method_name)).to eq(testcase[:expected_setting]) |
| 31 | + end |
| 32 | + end |
| 33 | + end |
| 34 | +end |
| 35 | + |
| 36 | +# Requires |
| 37 | +# :settings : A hashtable of the inbound settings |
| 38 | +# :setting_value : The value that will be set to |
| 39 | +RSpec.shared_examples "a setting with dynamic registrations" do |method_name, dynamic_reg, registration_method| |
| 40 | + [ |
| 41 | + { :from => false, :setting => nil, :noop => true }, |
| 42 | + { :from => false, :setting => false, :noop => true }, |
| 43 | + { :from => false, :setting => true, :register => true }, |
| 44 | + { :from => true, :setting => nil, :noop => true }, |
| 45 | + { :from => true, :setting => false, :unregister => true }, |
| 46 | + { :from => true, :setting => true, :noop => true }, |
| 47 | + ].each do |testcase| |
| 48 | + context "When it transitions from #{pretty_value(testcase[:from])} with a setting value of #{pretty_value(testcase[:setting])}" do |
| 49 | + let(:setting_value) { testcase[:setting] } |
| 50 | + |
| 51 | + before(:each) do |
| 52 | + subject.instance_variable_set("@#{method_name}".intern, testcase[:from]) |
| 53 | + end |
| 54 | + |
| 55 | + it 'should not call any capabilities', :if => testcase[:noop] do |
| 56 | + expect(subject).to receive(:client_capability).exactly(0).times |
| 57 | + expect(subject).to receive(:register_capability).exactly(0).times |
| 58 | + expect(subject).to receive(:unregister_capability).exactly(0).times |
| 59 | + |
| 60 | + subject.parse_lsp_configuration_settings!(settings) |
| 61 | + end |
| 62 | + |
| 63 | + context "when dynamic registration is not supported", :unless => testcase[:noop] do |
| 64 | + before(:each) do |
| 65 | + expect(subject).to receive(:client_capability).with(*dynamic_reg).and_return(false) |
| 66 | + end |
| 67 | + |
| 68 | + it 'should not call any registration or unregistrations' do |
| 69 | + expect(subject).to receive(:register_capability).exactly(0).times |
| 70 | + expect(subject).to receive(:unregister_capability).exactly(0).times |
| 71 | + |
| 72 | + subject.parse_lsp_configuration_settings!(settings) |
| 73 | + end |
| 74 | + end |
| 75 | + |
| 76 | + context "when dynamic registration is supported", :unless => testcase[:noop] do |
| 77 | + before(:each) do |
| 78 | + expect(subject).to receive(:client_capability).with(*dynamic_reg).and_return(true) |
| 79 | + end |
| 80 | + |
| 81 | + it "should register #{registration_method}", :if => testcase[:register] do |
| 82 | + expect(subject).to receive(:register_capability).with(registration_method, Object) |
| 83 | + expect(subject).to receive(:unregister_capability).exactly(0).times |
| 84 | + |
| 85 | + subject.parse_lsp_configuration_settings!(settings) |
| 86 | + end |
| 87 | + |
| 88 | + it "should unregister #{registration_method}", :if => testcase[:unregister] do |
| 89 | + expect(subject).to receive(:unregister_capability).with(registration_method) |
| 90 | + expect(subject).to receive(:register_capability).exactly(0).times |
| 91 | + |
| 92 | + subject.parse_lsp_configuration_settings!(settings) |
| 93 | + end |
| 94 | + end |
| 95 | + end |
| 96 | + end |
| 97 | +end |
| 98 | + |
3 | 99 | describe 'PuppetLanguageServer::LanguageClient' do |
4 | 100 | let(:json_rpc_handler) { MockJSONRPCHandler.new } |
5 | 101 | let(:message_router) { MockMessageRouter.new.tap { |i| i.json_rpc_handler = json_rpc_handler } } |
|
146 | 242 | allow(PuppetLanguageServer).to receive(:log_message) |
147 | 243 | end |
148 | 244 |
|
| 245 | + describe '#format_on_type' do |
| 246 | + it 'should be false by default' do |
| 247 | + expect(subject.format_on_type).to eq(false) |
| 248 | + end |
| 249 | + end |
| 250 | + |
149 | 251 | describe '#client_capability' do |
150 | 252 | before(:each) do |
151 | 253 | subject.parse_lsp_initialize!(initialize_params) |
|
181 | 283 | # end |
182 | 284 |
|
183 | 285 | describe '#parse_lsp_configuration_settings!' do |
184 | | - # TODO: Future use. |
| 286 | + describe 'puppet.editorService.formatOnType.enable' do |
| 287 | + let(:settings) do |
| 288 | + { 'puppet' => { |
| 289 | + 'editorService' => { |
| 290 | + 'formatOnType' => { |
| 291 | + 'enable' => setting_value |
| 292 | + } |
| 293 | + } |
| 294 | + } |
| 295 | + } |
| 296 | + end |
| 297 | + |
| 298 | + it_behaves_like 'a client setting', :format_on_type |
| 299 | + |
| 300 | + it_behaves_like 'a setting with dynamic registrations', |
| 301 | + :format_on_type, |
| 302 | + ['textDocument', 'onTypeFormatting', 'dynamicRegistration'], |
| 303 | + 'textDocument/onTypeFormatting' |
| 304 | + end |
185 | 305 | end |
186 | 306 |
|
187 | 307 | describe '#capability_registrations' do |
|
0 commit comments