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

- lexer.rl: accept tabs before closing heredoc delimiter #990

Merged
merged 1 commit into from
Jan 12, 2024
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
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