Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Includes exclamation mark in first sentence again #2

Closed
Closed
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
11 changes: 9 additions & 2 deletions lib/rake/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,17 @@ def transform_comments(separator, &block)
private :transform_comments

# Get the first sentence in a string. The sentence is terminated
# by the first period, exclamation mark, or the end of the line.
# by the first period or the end of the line.
# Decimal points do not count as periods.
def first_sentence(string)
string.split(/(?<=\w)(\.|!)[ \t]|(\.$|!)|\n/).first
# string.split(/(?<=\w)(\.|!)[ \t]|(\.$|!)|\n/).first
# string.split(/(?<=\w)(\.|!)[ \t]|(\.$|!)|\n/).first
# string.split(/(?<=\w)(\.)[ \t]|(\.$)|\n/).first
# string.slice(/[^\n]+/)
# string.slice(/^.*?[\.!\?](?:\s|$)/)
# string.slice(/^.*?[.!?](?:\s|$)(?!.*\))/).strip
# string.slice(/\A.*?[.!?](?=\s[A-Z]|\s?$)(?!.*\))/).slice(/\A(.*?)[\.]?$/, 1) # Passed!
# string.slice(/\A.*?[.!?](?=\s[A-Z]|\s?$)(?!.*\))/)
end
private :first_sentence

Expand Down
15 changes: 14 additions & 1 deletion test/test_rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ def test_comment_setting
assert_equal "A Comment", t.comment
end

def test_comments_with_empty
omit
desc ""
t = task(:t, :name, :rev)
assert_equal "", t.comment
end

def test_comments_with_sentences_period
desc "Comment 1. Comment 2."
t = task(:t, :name, :rev)
Expand All @@ -409,7 +416,13 @@ def test_comments_with_sentences_period
def test_comments_with_sentences_exclamation_mark
desc "An exclamation mark! Comment."
t = task(:t, :name, :rev)
assert_equal "An exclamation mark", t.comment
assert_equal "An exclamation mark!", t.comment
end

def test_comments_with_sentences_exclamation_mark_for_alert
desc "Overwrite files; dangerous!! Attention!"
t = task(:t, :name, :rev)
assert_equal "Overwrite files; dangerous!!", t.comment
end

def test_comments_with_many_periods
Expand Down