Skip to content
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: 2 additions & 0 deletions lib/prism/parse_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,8 @@ class InlineComment < Comment
#: () -> bool
def trailing?
!location.start_line_slice.strip.empty?
rescue ArgumentError # invalid bytes, never whitespace only
false
end

# Returns a string representation of this comment.
Expand Down
10 changes: 10 additions & 0 deletions test/prism/result/comments_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ def foo
)
end

def test_comment_trailing
comment = Prism.parse_comments("x # trailing")[0]
assert_predicate(comment, :trailing?)
end

def test_comment_syntax_invalid_bytes_trailing
comment = Prism.parse_comments("\xFF\xFE# not trailing")[0]
refute_predicate(comment, :trailing?)
end

def test___END__
result = Prism.parse(<<~RUBY)
__END__
Expand Down
Loading