@@ -167,5 +167,69 @@ 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+ let ( :sibling_modules_source ) do
173+ <<-RUBY
174+ module Foo
175+ module Bar
176+ end
177+ module Baz
178+ end
179+ end
180+ RUBY
181+ end
182+ let ( :scope_parser ) { RubyLanguageServer ::ScopeParser . new ( sibling_modules_source ) }
183+
184+ it 'should place sibling modules at the same level' do
185+ foo = scope_parser . root_scope . children . first
186+ assert_equal ( 'Foo' , foo . name )
187+
188+ # Both Bar and Baz should be children of Foo, not Bar containing Baz
189+ children = foo . children
190+ assert_equal ( 2 , children . size , "Foo should have 2 children, but has #{ children . size } " )
191+
192+ bar = children . detect { |c | c . name == 'Bar' }
193+ baz = children . detect { |c | c . name == 'Baz' }
194+
195+ assert_not_nil ( bar , "Bar should be a child of Foo" )
196+ assert_not_nil ( baz , "Baz should be a child of Foo" )
197+
198+ # Verify Baz is not a child of Bar
199+ assert_equal ( 0 , bar . children . size , "Bar should have no children, but has #{ bar . children . size } " )
200+ end
201+ end
202+
203+ describe 'sibling classes' do
204+ let ( :sibling_classes_source ) do
205+ <<-RUBY
206+ module Foo
207+ class Bar
208+ end
209+ class Baz
210+ end
211+ end
212+ RUBY
213+ end
214+ let ( :scope_parser ) { RubyLanguageServer ::ScopeParser . new ( sibling_classes_source ) }
215+
216+ it 'should place sibling classes at the same level' do
217+ foo = scope_parser . root_scope . children . first
218+ assert_equal ( 'Foo' , foo . name )
219+
220+ # Both Bar and Baz should be children of Foo, not Bar containing Baz
221+ children = foo . children
222+ assert_equal ( 2 , children . size , "Foo should have 2 children, but has #{ children . size } " )
223+
224+ bar = children . detect { |c | c . name == 'Bar' }
225+ baz = children . detect { |c | c . name == 'Baz' }
226+
227+ assert_not_nil ( bar , "Bar should be a child of Foo" )
228+ assert_not_nil ( baz , "Baz should be a child of Foo" )
229+
230+ # Verify Baz is not a child of Bar
231+ assert_equal ( 0 , bar . children . size , "Bar should have no children, but has #{ bar . children . size } " )
232+ end
233+ end
170234 end
171235end
0 commit comments