|
22 | 22 | end |
23 | 23 | end |
24 | 24 |
|
| 25 | +RSpec::Matchers.define :be_symbol_information do |name, kind| |
| 26 | + match do |actual| |
| 27 | + actual.name == name && |
| 28 | + actual.kind == kind |
| 29 | + end |
| 30 | + |
| 31 | + failure_message do |actual| |
| 32 | + "expected that symbol called '#{actual.name}' of type '#{actual.kind}' would be " + |
| 33 | + "a symbol called '#{name}', of type '#{kind}'" |
| 34 | + end |
| 35 | + |
| 36 | + description do |
| 37 | + "be a document symbol called '#{name}' of type #{kind} located at #{start_line}, #{start_char}, #{end_line}, #{end_char}" |
| 38 | + end |
| 39 | +end |
| 40 | + |
25 | 41 | describe 'PuppetLanguageServer::Manifest::DocumentSymbolProvider' do |
26 | 42 | let(:subject) { PuppetLanguageServer::Manifest::DocumentSymbolProvider } |
27 | 43 |
|
| 44 | + describe '#workspace_symbols' do |
| 45 | + let(:cache) { PuppetLanguageServer::PuppetHelper::Cache.new } |
| 46 | + |
| 47 | + before(:each) do |
| 48 | + # Add test objects |
| 49 | + origin = :default |
| 50 | + cache.import_sidecar_list!([random_sidecar_puppet_class(:class1)], :class, origin) |
| 51 | + cache.import_sidecar_list!([random_sidecar_puppet_function(:func1)], :function, origin) |
| 52 | + cache.import_sidecar_list!([random_sidecar_puppet_type(:type1)], :type, origin) |
| 53 | + end |
| 54 | + |
| 55 | + it 'should emit all known objects for an empty query' do |
| 56 | + result = subject.workspace_symbols(nil, cache) |
| 57 | + |
| 58 | + expect(result[0]).to be_symbol_information('class1', LSP::SymbolKind::CLASS) |
| 59 | + expect(result[1]).to be_symbol_information('func1', LSP::SymbolKind::FUNCTION) |
| 60 | + expect(result[2]).to be_symbol_information('type1', LSP::SymbolKind::METHOD) |
| 61 | + |
| 62 | + all_cache_names = [] |
| 63 | + cache.all_objects { |key, _| all_cache_names << key.to_s } |
| 64 | + expect(result.count).to eq(all_cache_names.count) |
| 65 | + end |
| 66 | + |
| 67 | + it 'should only emit objects that match a simple text query' do |
| 68 | + result = subject.workspace_symbols('func', cache) |
| 69 | + |
| 70 | + expect(result.count).to eq(1) |
| 71 | + expect(result[0]).to be_symbol_information('func1', LSP::SymbolKind::FUNCTION) |
| 72 | + end |
| 73 | + end |
| 74 | + |
28 | 75 | context 'with Puppet 4.0 and below', :if => Gem::Version.new(Puppet.version) < Gem::Version.new('5.0.0') do |
29 | 76 | describe '#extract_document_symbols' do |
30 | 77 | it 'should always return an empty array' do |
|
0 commit comments