8000 Fix module typename resolving by ksss · Pull Request #94 · ksss/orthoses · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix module typename resolving #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/orthoses/content/header_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def build(entry:, name_hint: nil)

def build_module(entry:, name_hint: nil)
primary = entry.primary
full_name = name_hint || primary.decl.name.relative!
context = build_context(entry: primary)
full_name = name_hint || @resolver.resolve(primary.decl.name, context: context) || primary.decl.name.relative!

self_types =
if primary.decl.self_types.empty?
Expand Down
36 changes: 34 additions & 2 deletions lib/orthoses/content/header_builder_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
begin
require 'test_helper'
rescue LoadError
end

module HeaderBuilderTest
def test_module(t)
env = Orthoses::Utils.rbs_environment(collection: false, cache: false)
_, _, decls = RBS::Parser.parse_signature(<<~RBS)
module Foo
module Bar
module Baz
end
end
end
RBS

decls.each { env << _1 }
header_builder = Orthoses::Content::HeaderBuilder.new(env: env)

[
["Foo", "module ::Foo"],
["Foo::Bar", "module ::Foo::Bar"],
["Foo::Bar::Baz", "module ::Foo::Bar::Baz"],
].each do |input_name, expect_header|
entry = env.class_decls[TypeName(input_name).absolute!] or raise "#{input_name} not found"
output_header = header_builder.build(entry: entry)
unless expect_header == output_header
t.error("expect=#{expect_header}, but got #{output_header}")
end
end
end

def test_class(t)
env = Orthoses::Utils.rbs_environment(collection: false)
env = Orthoses::Utils.rbs_environment(collection: false, cache: false)
_, _, decls = RBS::Parser.parse_signature(<<~RBS)
class Foo
end
Expand Down Expand Up @@ -51,7 +83,7 @@ class SuperIsClassAlias < ClassAlias
end

def test_interface(t)
env = Orthoses::Utils.rbs_environment(collection: false)
env = Orthoses::Utils.rbs_environment(collection: false, cache: false)
_, _, decls = RBS::Parser.parse_signature(<<~RBS)
module Mod
interface _Foo
Expand Down
20 changes: 16 additions & 4 deletions lib/orthoses/exclude_rbs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def test_exclude_rbs(t)
store = Orthoses::ExcludeRBS.new(
-> {
Orthoses::Utils.new_store.tap do |s|
c = s["ExcludeRBSTest"]
c.header = "module ExcludeRBSTest"
c << "def known_method_outer: () -> void"
c << "def unknown_method_outer: () -> void"
c << "KNOWN_CONST_OUTER: 1"
c << "UNKNOWN_CONST_OUTER: 1"

c = s["ExcludeRBSTest::M1"]
c.header = "module ExcludeRBSTest::M1"
c << "def known_method: () -> void"
Expand All @@ -19,15 +26,20 @@ def test_exclude_rbs(t)
end
},
rbs: <<~RBS
module ExcludeRBSTest::M1
def known_method: () -> void
KNOWN_CONST: 1
module ExcludeRBSTest
def known_method_outer: () -> void
KNOWN_CONST_OUTER: 1

module M1
def known_method: () -> void
KNOWN_CONST: 1
end
end
RBS
).call

expect = <<~RBS
module ExcludeRBSTest::M1
module ::ExcludeRBSTest::M1
def unknown_method: () -> void

UNKNOWN_CONST: 1
Expand Down
Loading
0