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 seek position #465

Merged
merged 1 commit into from
Jul 25, 2017
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
2 changes: 1 addition & 1 deletion lib/rdoc/ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def token

if TkSYMBEG === tk then
tk1 = token
set_token_position tk.line_no, tk.char_no
set_token_position tk.seek, tk.line_no, tk.char_no

case tk1
when TkId, TkOp, TkSTRING, TkDSTRING, TkSTAR, TkAMPER then
Expand Down
3 changes: 2 additions & 1 deletion lib/rdoc/ruby_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module RDoc::RubyToken
Symbol = Integer
end

def set_token_position(line, char)
def set_token_position(seek, line, char)
@prev_seek = seek
@prev_line_no = line
@prev_char_no = char
end
Expand Down
25 changes: 25 additions & 0 deletions test/test_rdoc_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ def setup
@TK = RDoc::RubyToken
end

def test_token_position
tokens = RDoc::RubyLex.tokenize '[ 1, :a, nil ]', nil

assert_equal '[', tokens[0].text
assert_equal 0, tokens[0].seek
assert_equal 1, tokens[0].line_no
assert_equal 0, tokens[0].char_no
assert_equal '1', tokens[2].text
assert_equal 2, tokens[2].seek
assert_equal 1, tokens[2].line_no
assert_equal 2, tokens[2].char_no
assert_equal ':a', tokens[5].text
assert_equal 5, tokens[5].seek
assert_equal 1, tokens[5].line_no
assert_equal 5, tokens[5].char_no
assert_equal 'nil', tokens[8].text
assert_equal 9, tokens[8].seek
assert_equal 1, tokens[8].line_no
assert_equal 9, tokens[8].char_no
assert_equal ']', tokens[10].text
assert_equal 13, tokens[10].seek
assert_equal 1, tokens[10].line_no
assert_equal 13, tokens[10].char_no
end

def test_class_tokenize
tokens = RDoc::RubyLex.tokenize "def x() end", nil

Expand Down