Skip to content

Commit

Permalink
- lexer.rl: accept tabs before closing heredoc delimiter (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
iliabylich authored Jan 12, 2024
1 parent 717b38c commit c61f13c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/parser/lexer/literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Parser
class Lexer::Literal
DELIMITERS = { '(' => ')', '[' => ']', '{' => '}', '<' => '>' }
SPACE = ' '.ord
TAB = "\t".ord

TYPES = {
# type start token interpolate?
Expand Down Expand Up @@ -247,7 +248,7 @@ def delimiter?(delimiter)
# E
# because there are not enough leading spaces in the closing delimiter.
delimiter.end_with?(@end_delim) &&
delimiter.sub(/#{Regexp.escape(@end_delim)}\z/, '').bytes.all? { |c| c == SPACE }
delimiter.sub(/#{Regexp.escape(@end_delim)}\z/, '').bytes.all? { |c| c == SPACE || c == TAB }
elsif @indent
@end_delim == delimiter.lstrip
else
Expand Down
8 changes: 8 additions & 0 deletions test/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11488,4 +11488,12 @@ def test_anonymous_params_in_nested_scopes
'def b(**) ->(**) {c()} end',
SINCE_3_3)
end

def test_parser_bug_989
assert_parses(
s(:str, "\t\tcontent\n"),
"\t<<-HERE\n\t\tcontent\n\tHERE",
%q{},
ALL_VERSIONS)
end
end
6 changes: 3 additions & 3 deletions test/test_runner_rewrite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

class TestRunnerRewrite < Minitest::Test
def assert_rewriter_output(path, args, input: 'input.rb', output: 'output.rb', expected_output: '', expected_error: '')
@ruby_rewrite = BASE_DIR.expand_path + '../bin/ruby-rewrite'
@test_dir = BASE_DIR + path
@ruby_rewrite = ::BASE_DIR.expand_path + '../bin/ruby-rewrite'
@test_dir = ::BASE_DIR + path
@fixtures_dir = @test_dir + 'fixtures'

Dir.mktmpdir("parser", BASE_DIR.expand_path.to_s) do |tmp_dir|
Dir.mktmpdir("parser", ::BASE_DIR.expand_path.to_s) do |tmp_dir|
tmp_dir = Pathname.new(tmp_dir)
sample_file = tmp_dir + "#{path}.rb"
sample_file_expanded = sample_file.expand_path
Expand Down

0 comments on commit c61f13c

Please sign in to comment.