Skip to content

Commit

Permalink
Fixed parsing of def self.&() end. Fixes ruby#148
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Nov 19, 2012
1 parent 640e6d7 commit 8b25c18
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
2 changes: 2 additions & 0 deletions History.rdoc
Expand Up @@ -95,6 +95,8 @@
Noria.
* Add license to gem spec. Issue #144 by pivotalcommon
* Fixed comment selection for classes. Pull request #146 by pioz
* Fixed parsing of <code>def self.&() end</code>. Issue #148 by Michael
Lucy

=== 3.12 / 2011-12-15

Expand Down
1 change: 1 addition & 0 deletions Manifest.txt
Expand Up @@ -267,6 +267,7 @@ test/test_rdoc_require.rb
test/test_rdoc_ri_driver.rb
test/test_rdoc_ri_paths.rb
test/test_rdoc_ruby_lex.rb
test/test_rdoc_ruby_token.rb
test/test_rdoc_rubygems_hook.rb
test/test_rdoc_servlet.rb
test/test_rdoc_single_class.rb
Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/ruby_token.rb
Expand Up @@ -370,13 +370,13 @@ def Token(token, value = nil)
[:TkfLPAREN, Token, "("], # func( #
[:TkfLBRACK, Token, "["], # func[ #
[:TkfLBRACE, Token, "{"], # func{ #
[:TkSTAR, Token, "*"], # *arg
[:TkAMPER, Token, "&"], # &arg #
[:TkSYMBEG, Token, ":"], # :SYMBOL

[:TkAMPER, TkOp, "&"],
[:TkGT, TkOp, ">"],
[:TkLT, TkOp, "<"],
[:TkPLUS, TkOp, "+"],
[:TkSTAR, TkOp, "*"],
[:TkMINUS, TkOp, "-"],
[:TkMULT, TkOp, "*"],
[:TkDIV, TkOp, "/"],
Expand Down
32 changes: 31 additions & 1 deletion test/test_rdoc_parser_ruby.rb
Expand Up @@ -1339,6 +1339,21 @@ def test_parse_method_alias
assert klass.aliases.empty?
end

def test_parse_method_ampersand
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level

util_parser "def self.&\nend"

tk = @parser.get_tk

@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment

ampersand = klass.method_list.first
assert_equal '&', ampersand.name
assert ampersand.singleton
end

def test_parse_method_false
util_parser "def false.foo() :bar end"

Expand All @@ -1362,7 +1377,7 @@ def test_parse_method_funky

@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment

assert klass.method_list.empty?
assert_empty klass.method_list
end

def test_parse_method_gvar
Expand Down Expand Up @@ -1470,6 +1485,21 @@ def test_parse_method_parameters_comment_continue
assert_equal '(arg1, arg2, arg3)', foo.params
end

def test_parse_method_star
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level

util_parser "def self.*\nend"

tk = @parser.get_tk

@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment

ampersand = klass.method_list.first
assert_equal '*', ampersand.name
assert ampersand.singleton
end

def test_parse_method_stopdoc
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
Expand Down
19 changes: 19 additions & 0 deletions test/test_rdoc_ruby_token.rb
@@ -0,0 +1,19 @@
require 'rdoc/test_case'

class TestRDocRubyToken < RDoc::TestCase

def test_Token_text
token = RDoc::RubyToken::Token.new 0, 0, 0, 'text'

assert_equal 'text', token.text
end

def test_TkOp_name
token = RDoc::RubyToken::TkOp.new 0, 0, 0, '&'

assert_equal '&', token.text
assert_equal '&', token.name
end

end

0 comments on commit 8b25c18

Please sign in to comment.