d63ea569a174

cli: strip leading and trailing whitespace from whole comments
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 15 Jun 2010 18:39:20 -0400
parents deb8a96475a5
children d5280b38dd4c
branches/tags (none)
files review/extension_ui.py review/tests/test_comment.py review/tests/test_signoff.py

Changes

--- a/review/extension_ui.py	Tue Jun 15 18:27:09 2010 -0400
+++ b/review/extension_ui.py	Tue Jun 15 18:39:20 2010 -0400
@@ -43,7 +43,7 @@
 
 def _comment_command(ui, repo, *fnames, **opts):
     rev = opts.pop('rev')
-    message = opts.pop('message')
+    message = opts.pop('message').strip()
     lines = opts.pop('lines')
 
     rd = api.ReviewDatastore(ui, repo)
@@ -74,7 +74,7 @@
 def _signoff_command(ui, repo, **opts):
     rd = api.ReviewDatastore(ui, repo)
     rcset = rd[opts.pop('rev')]
-    message = opts.pop('message')
+    message = opts.pop('message').strip()
 
     if not message:
         raise util.Abort(messages.SIGNOFF_REQUIRES_MESSAGE)
--- a/review/tests/test_comment.py	Tue Jun 15 18:27:09 2010 -0400
+++ b/review/tests/test_comment.py	Tue Jun 15 18:39:20 2010 -0400
@@ -22,6 +22,33 @@
         assert messages.COMMENT_REQUIRES_MESSAGE in error
     else:
         assert False, 'The correct error message was not printed.'
+    try:
+        review(comment=True, message='    \t\t')
+    except hgutil.Abort, e:
+        error = str(e)
+        assert messages.COMMENT_REQUIRES_MESSAGE in error
+    else:
+        assert False, 'The correct error message was not printed.'
+
+@with_setup(setup_reviewed_sandbox, teardown_sandbox)
+def test_comment_formatting():
+    review(comment=True, message=' \tTest comment one.\t ')
+    output = review()
+
+    assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output
+    assert messages.REVIEW_LOG_COMMENT_LINE % ' \tTest comment one.' not in output
+    assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.\t ' not in output
+    assert messages.REVIEW_LOG_COMMENT_LINE % ' \tTest comment one.\t ' not in output
+    review(rev=0, comment=True,
+           message=' \tTest\n  indented\n\ttabindented\noutdented  \ndone\t ')
+    output = review(rev=0)
+
+    assert messages.REVIEW_LOG_COMMENT_LINE % 'Test' in output
+    assert messages.REVIEW_LOG_COMMENT_LINE % '  indented' in output
+    assert messages.REVIEW_LOG_COMMENT_LINE % '\ttabindented' in output
+    assert messages.REVIEW_LOG_COMMENT_LINE % 'outdented  ' in output
+    assert messages.REVIEW_LOG_COMMENT_LINE % 'done' in output
+
 
 @with_setup(setup_reviewed_sandbox, teardown_sandbox)
 def test_add_comments_to_parent_rev():
--- a/review/tests/test_signoff.py	Tue Jun 15 18:27:09 2010 -0400
+++ b/review/tests/test_signoff.py	Tue Jun 15 18:39:20 2010 -0400
@@ -24,6 +24,26 @@
         assert False, 'The correct error message was not printed.'
 
 @with_setup(setup_reviewed_sandbox, teardown_sandbox)
+def test_signoff_formatting():
+    review(signoff=True, message=' \tTest signoff one.\t ')
+    output = review()
+
+    assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.' in output
+    assert messages.REVIEW_LOG_SIGNOFF_LINE % ' \tTest signoff one.' not in output
+    assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.\t ' not in output
+    assert messages.REVIEW_LOG_SIGNOFF_LINE % ' \tTest signoff one.\t ' not in output
+    review(rev=0, signoff=True,
+           message=' \tTest\n  indented\n\ttabindented\noutdented  \ndone\t ')
+    output = review(rev=0)
+
+    assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test' in output
+    assert messages.REVIEW_LOG_SIGNOFF_LINE % '  indented' in output
+    assert messages.REVIEW_LOG_SIGNOFF_LINE % '\ttabindented' in output
+    assert messages.REVIEW_LOG_SIGNOFF_LINE % 'outdented  ' in output
+    assert messages.REVIEW_LOG_SIGNOFF_LINE % 'done' in output
+
+
+@with_setup(setup_reviewed_sandbox, teardown_sandbox)
 def test_signoff_on_parent_rev():
     review(signoff=True, message='Test signoff one.')