@@ -167,5 +167,91 @@ def some_method
167167 assert_equal ( 'item' , scope_parser . root_scope . self_and_descendants . last . variables . first . name )
168168 end
169169 end
170+
171+ describe 'sibling modules' do
172+ before do
173+ @parser = RubyLanguageServer ::ScopeParser . new ( <<-RUBY )
174+ module Foo
175+ module Bar
176+ end
177+ module Baz
178+ end
179+ end
180+ RUBY
181+ end
182+
183+ it 'places sibling modules at the same level' do
184+ foo = @parser . root_scope . children . first
185+ assert_equal ( 'Foo' , foo . name )
186+
187+ children = foo . children
188+ assert_equal ( 2 , children . size , "Foo should have 2 children, but has #{ children . size } " )
189+
190+ bar = children . detect { |c | c . name == 'Bar' }
191+ baz = children . detect { |c | c . name == 'Baz' }
192+
193+ refute_nil ( bar , "Bar should be a child of Foo" )
194+ refute_nil ( baz , "Baz should be a child of Foo" )
195+ assert_equal ( 0 , bar . children . size , "Bar should have no children" )
196+ end
197+ end
198+
199+ describe 'sibling classes' do
200+ before do
201+ @parser = RubyLanguageServer ::ScopeParser . new ( <<-RUBY )
202+ module Foo
203+ class Bar
204+ end
205+ class Baz
206+ end
207+ end
208+ RUBY
209+ end
210+
211+ it 'places sibling classes at the same level' do
212+ foo = @parser . root_scope . children . first
213+ assert_equal ( 'Foo' , foo . name )
214+
215+ children = foo . children
216+ assert_equal ( 2 , children . size , "Foo should have 2 children, but has #{ children . size } " )
217+
218+ bar = children . detect { |c | c . name == 'Bar' }
219+ baz = children . detect { |c | c . name == 'Baz' }
220+
221+ refute_nil ( bar , "Bar should be a child of Foo" )
222+ refute_nil ( baz , "Baz should be a child of Foo" )
223+ assert_equal ( 0 , bar . children . size , "Bar should have no children" )
224+ end
225+ end
226+
227+ describe 'mixed siblings' do
228+ before do
229+ @parser = RubyLanguageServer ::ScopeParser . new ( <<-RUBY )
230+ module Foo
231+ class Bar
232+ end
233+ module Baz
234+ end
235+ end
236+ RUBY
237+ end
238+
239+ it 'places sibling class and module at the same level' do
240+ foo = @parser . root_scope . children . first
241+ assert_equal ( 'Foo' , foo . name )
242+
243+ children = foo . children
244+ assert_equal ( 2 , children . size , "Foo should have 2 children, but has #{ children . size } " )
245+
246+ bar = children . detect { |c | c . name == 'Bar' }
247+ baz = children . detect { |c | c . name == 'Baz' }
248+
249+ refute_nil ( bar , "Bar should be a child of Foo" )
250+ refute_nil ( baz , "Baz should be a child of Foo" )
251+ assert_equal ( :class , bar . type , "Bar should be a class" )
252+ assert_equal ( :module , baz . type , "Baz should be a module" )
253+ assert_equal ( 0 , bar . children . size , "Bar should have no children" )
254+ end
255+ end
170256 end
171257end
0 commit comments