-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #836 from soutaro/resolve-types-in-node
Resolve type names from TypeAssertion and TypeApplication
- Loading branch information
Showing
5 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require_relative "../../test_helper" | ||
|
||
class AST__Node__TypeAssertionTest < Minitest::Test | ||
include TestHelper | ||
include FactoryHelper | ||
include SubtypingHelper | ||
|
||
def buffer(string) | ||
buffer = RBS::Buffer.new(name: "foo.rbs", content: string) | ||
RBS::Location.new(buffer, 0, string.size) | ||
end | ||
|
||
def test_type | ||
with_checker do | ||
loc = buffer(": String") | ||
|
||
assertion = Steep::AST::Node::TypeAssertion.parse(loc) | ||
|
||
assert_equal "String", assertion.type_str | ||
assert_predicate assertion, :type_syntax? | ||
|
||
type = assertion.type(nil, checker, []) | ||
assert_equal parse_type("::String"), type | ||
end | ||
end | ||
|
||
def test_relative_type | ||
with_checker(<<~RBS) do | ||
class Foo | ||
class Bar | ||
end | ||
end | ||
RBS | ||
loc = buffer(": Array[Bar]") | ||
|
||
assertion = Steep::AST::Node::TypeAssertion.parse(loc) | ||
|
||
assert_equal "Array[Bar]", assertion.type_str | ||
assert_predicate assertion, :type_syntax? | ||
|
||
type = assertion.type([nil, TypeName("::Foo")], checker, []) | ||
assert_equal parse_type("::Array[::Foo::Bar]"), type | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters