Skip to content

Commit e897076

Browse files
authored
Merge pull request #500 from aycabta/percent-literal-with-original-sign
Fix % literal with the same sign of original
2 parents 1564f2f + d5b55f6 commit e897076

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/rdoc/ruby_lex.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ def identify_string(ltype, quoted = ltype, type = nil)
13251325
@ltype = ltype
13261326
@quoted = quoted
13271327

1328-
str = if ltype == quoted and %w[" ' / `].include? ltype then
1328+
str = if ltype == quoted and %w[" ' / `].include? ltype and type.nil? then
13291329
ltype.dup
13301330
else
13311331
"%#{type}#{PERCENT_PAREN_REV[quoted]||quoted}"

test/test_rdoc_ruby_lex.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,39 @@ def test_class_tokenize_percent_r
474474
assert_equal expected, tokens
475475
end
476476

477+
def test_class_tokenize_percent_r_with_slash
478+
tokens = RDoc::RubyLex.tokenize '%r/hi/', nil
479+
480+
expected = [
481+
@TK::TkREGEXP.new( 0, 1, 0, '%r/hi/'),
482+
@TK::TkNL .new( 6, 1, 6, "\n"),
483+
]
484+
485+
assert_equal expected, tokens
486+
end
487+
488+
def test_class_tokenize_percent_large_q
489+
tokens = RDoc::RubyLex.tokenize '%Q/hi/', nil
490+
491+
expected = [
492+
@TK::TkSTRING.new( 0, 1, 0, '%Q/hi/'),
493+
@TK::TkNL .new( 6, 1, 6, "\n"),
494+
]
495+
496+
assert_equal expected, tokens
497+
end
498+
499+
def test_class_tokenize_percent_large_q_with_double_quote
500+
tokens = RDoc::RubyLex.tokenize '%Q"hi"', nil
501+
502+
expected = [
503+
@TK::TkSTRING.new( 0, 1, 0, '%Q"hi"'),
504+
@TK::TkNL .new( 6, 1, 6, "\n"),
505+
]
506+
507+
assert_equal expected, tokens
508+
end
509+
477510
def test_class_tokenize_percent_w
478511
tokens = RDoc::RubyLex.tokenize '%w[hi]', nil
479512

0 commit comments

Comments
 (0)