diff --git a/CHANGELOG.md b/CHANGELOG.md index 00600be..2067229 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [Unreleased] +- Support Hash type https://github.com/euglena1215/rbs_inline_data/pull/1 + ## [0.1.0] - 2024-06-09 - Initial release diff --git a/lib/rbs_inline_data/parser.rb b/lib/rbs_inline_data/parser.rb index 5d31696..775cbb2 100644 --- a/lib/rbs_inline_data/parser.rb +++ b/lib/rbs_inline_data/parser.rb @@ -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"] diff --git a/test/rbs_inline_data/parser_test.rb b/test/rbs_inline_data/parser_test.rb index 2b70a46..ff4a355 100644 --- a/test/rbs_inline_data/parser_test.rb +++ b/test/rbs_inline_data/parser_test.rb @@ -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