Skip to content

Commit ed223c6

Browse files
Copilotkwerle
andcommitted
Add test case for mixed sibling (class and module)
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
1 parent e7b7e94 commit ed223c6

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

spec/lib/ruby_language_server/scope_parser_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,41 @@ class Baz
218218

219219
include_examples 'sibling scopes', 'class'
220220
end
221+
222+
describe 'mixed (class and module)' do
223+
let(:scope_parser) do
224+
RubyLanguageServer::ScopeParser.new(<<-RUBY)
225+
module Foo
226+
class Bar
227+
end
228+
module Baz
229+
end
230+
end
231+
RUBY
232+
end
233+
234+
it 'should place sibling class and module at the same level' do
235+
foo = scope_parser.root_scope.children.first
236+
assert_equal('Foo', foo.name)
237+
238+
# Both Bar (class) and Baz (module) should be children of Foo
239+
children = foo.children
240+
assert_equal(2, children.size, "Foo should have 2 children, but has #{children.size}")
241+
242+
bar = children.detect { |c| c.name == 'Bar' }
243+
baz = children.detect { |c| c.name == 'Baz' }
244+
245+
assert_not_nil(bar, "Bar should be a child of Foo")
246+
assert_not_nil(baz, "Baz should be a child of Foo")
247+
248+
# Verify types are different
249+
assert_equal(:class, bar.type, "Bar should be a class")
250+
assert_equal(:module, baz.type, "Baz should be a module")
251+
252+
# Verify Baz is not a child of Bar
253+
assert_equal(0, bar.children.size, "Bar should have no children, but has #{bar.children.size}")
254+
end
255+
end
221256
end
222257
end
223258
end

0 commit comments

Comments
 (0)