Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Support Hash type
Browse files Browse the repository at this point in the history
  • Loading branch information
euglena1215 committed Jun 11, 2024
1 parent 277d5bf commit 53fdc77
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [Unreleased]

- Support Hash type

## [0.1.0] - 2024-06-09

- Initial release
2 changes: 1 addition & 1 deletion lib/rbs_inline_data/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def extract_definition(node)

fields = field_text.split("\n").map(&:strip).reject(&:empty?).map do |str|
case str
when /:(\w+),? #:: ([\w\:\[\]]+)/
when /:(\w+),? #:: ([\w\:\[\], ]+)/
[::Regexp.last_match(1), ::Regexp.last_match(2)]
when /:(\w+),?/
[::Regexp.last_match(1), "untyped"]
Expand Down
16 changes: 16 additions & 0 deletions test/rbs_inline_data/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,21 @@ class C; end
Parser::TypedField.new(field_name: "y", type: "Array[A::B::C]"),
])
end

def test_hash_type
definitions = Parser.parse(parse_ruby(<<~RUBY))
class A
B = Data.define(
:x, #:: Hash[Symbol, String]
)
end
RUBY

assert_equal definitions[0], Parser::TypedDefinition.new(
class_name: "A::B",
fields: [
Parser::TypedField.new(field_name: "x", type: "Hash[Symbol, String]"),
])
end
end
end

0 comments on commit 53fdc77

Please sign in to comment.