Skip to content
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

Fix match_pattern{,_p} #297

Merged
merged 1 commit into from
Feb 5, 2022
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
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.6.2 2022-02-05

[#297](https://github.com/mbj/unparser/pull/297)

* Fix emit of of `match_pattern` vs `match_pattern_p`

# v0.6.3 2022-01-16

[#290](https://github.com/mbj/unparser/pull/290)
Expand Down
4 changes: 3 additions & 1 deletion config/mutant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ matcher:
ignore:
# API changed between ruby versions and each of them
# have a different minimal form
- 'Unparser::Concord#define_readers'
- 'Unparser::Builder#initialize'
- 'Unparser::CLI*'
- 'Unparser::Concord#define_readers'
- 'Unparser::Emitter#emit_comments'
- 'Unparser::Emitter#emit_comments_before'
- 'Unparser::Emitter#emit_eol_comments'
Expand All @@ -28,6 +28,8 @@ matcher:
- 'Unparser::Emitter::HashPattern#write_symbol_body'
- 'Unparser::Emitter::LocalVariableRoot*'
- 'Unparser::Emitter::LocalVariableRoot.included'
- 'Unparser::Emitter::MatchPattern#dispatch' # 2.7+ specific
- 'Unparser::Emitter::MatchPatternP#dispatch' # 3.0+ specific
- 'Unparser::Emitter::Module#local_variable_scope'
- 'Unparser::Emitter::Root#local_variable_scope'
- 'Unparser::Emitter::Send#writer'
Expand Down
1 change: 1 addition & 0 deletions lib/unparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def self.buffer(source, identification = '(string)')
require 'unparser/emitter/kwargs'
require 'unparser/emitter/pair'
require 'unparser/emitter/match_pattern'
require 'unparser/emitter/match_pattern_p'
require 'unparser/writer'
require 'unparser/writer/binary'
require 'unparser/writer/dynamic_string'
Expand Down
14 changes: 11 additions & 3 deletions lib/unparser/emitter/match_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ class Emitter
class MatchPattern < self

handle :match_pattern
handle :match_pattern_p

children :target, :pattern

# Modern ast format emits `match_pattern`
# node on single line pre 3.0, but 3.0+ uses `match_pattern_p`
SYMBOL =
if RUBY_VERSION < '3.0'
' in '
else
' => '
end

private

def dispatch
visit(target)
write(' in ')
write(SYMBOL)
visit(pattern)
end
end # InPattern
end # MatchPattern
end # Emitter
end # Unparser
20 changes: 20 additions & 0 deletions lib/unparser/emitter/match_pattern_p.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Unparser
class Emitter
class MatchPatternP < self

handle :match_pattern_p

children :target, :pattern

private

def dispatch
visit(target)
write(' in ')
visit(pattern)
end
end # MatchPatternP
end # Emitter
end # Unparser
8 changes: 8 additions & 0 deletions spec/unit/unparser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ def noop
let(:version_excludes) do
excludes = []

if RUBY_VERSION < '3.0.'
excludes.concat(
%w[
test/corpus/literal/since/30.rb
]
)
end

if RUBY_VERSION < '2.7.'
excludes.concat(
%w[
Expand Down
2 changes: 2 additions & 0 deletions test/corpus/literal/since/30.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 => [a]
1 => [*]