Revision: 50885b213733
Branch:   default
Author:   Pekka Klärck
Date:     Fri Dec 14 02:20:30 2012
Log:      Preserve all comment characters.

Update issue 1306
Status: Done
Fixed parsing. Also needed to fix writers afterwards not to add unnecessary comment characters.
http://code.google.com/p/robotframework/source/detail?r=50885b213733

Modified:
 /atest/testdata/tidy/documentation.txt
 /atest/testdata/tidy/documentation_expected.html
 /atest/testdata/tidy/documentation_expected.tsv
 /atest/testdata/tidy/documentation_expected.txt
 /src/robot/parsing/comments.py
 /src/robot/parsing/datarow.py
 /src/robot/writer/rowsplitter.py
 /utest/parsing/test_populator.py

=======================================
--- /atest/testdata/tidy/documentation.txt      Tue Nov 27 01:27:32 2012
+++ /atest/testdata/tidy/documentation.txt      Fri Dec 14 02:20:30 2012
@@ -22,8 +22,8 @@
     No Operation
 Comments
     [Documentation]    First line    # First comment
-    ...    Middle line               # Middle comment
-    ...    Last line    # Last comment
+    ...    Middle line               #Middle comment
+    ...    Last line    ###Last comment###

 *** Keywords ***
 Keyword doc
=======================================
--- /atest/testdata/tidy/documentation_expected.html Tue Nov 27 01:27:32 2012 +++ /atest/testdata/tidy/documentation_expected.html Fri Dec 14 02:20:30 2012
@@ -162,12 +162,12 @@
 Middle line\n<br>
 Last line</td>
 <td># First comment</td>
-<td>Middle comment</td>
+<td>#Middle comment</td>
 </tr>
 <tr>
 <td class="name"></td>
 <td>...</td>
-<td>#Last comment</td>
+<td>###Last comment###</td>
 <td></td>
 <td></td>
 </tr>
=======================================
--- /atest/testdata/tidy/documentation_expected.tsv     Tue Nov 27 01:27:32 2012
+++ /atest/testdata/tidy/documentation_expected.tsv     Fri Dec 14 02:20:30 2012
@@ -22,7 +22,7 @@

 None   No Operation

-Comments [Documentation] First line # First comment Middle comment Last comment +Comments [Documentation] First line # First comment #Middle comment ###Last comment###
        ...     Middle line
        ...     Last line

=======================================
--- /atest/testdata/tidy/documentation_expected.txt     Tue Nov 27 01:27:32 2012
+++ /atest/testdata/tidy/documentation_expected.txt     Fri Dec 14 02:20:30 2012
@@ -28,7 +28,7 @@
     No Operation

 Comments
- [Documentation] First line # First comment Middle comment Last comment + [Documentation] First line # First comment #Middle comment ###Last comment###
     ...    Middle line
     ...    Last line

=======================================
--- /src/robot/parsing/comments.py      Fri Dec 14 01:53:50 2012
+++ /src/robot/parsing/comments.py      Fri Dec 14 02:20:30 2012
@@ -51,9 +51,9 @@
         return len(self._comment)

     def as_list(self):
-        if self._has_comment():
+        if self._not_commented():
             self._comment[0] = '# ' + self._comment[0]
         return self._comment

-    def _has_comment(self):
+    def _not_commented(self):
return self._comment and self._comment[0] and self._comment[0][0] != '#'
=======================================
--- /src/robot/parsing/datarow.py       Tue Mar  6 00:46:30 2012
+++ /src/robot/parsing/datarow.py       Fri Dec 14 02:20:30 2012
@@ -28,9 +28,7 @@
         comments = []
         for cell in row:
             cell = self._collapse_whitespace(cell)
-            if cell.startswith('#') and not comments:
-                comments.append(cell[1:])
-            elif comments:
+            if cell.startswith('#') or comments:
                 comments.append(cell)
             else:
                 data.append(cell)
=======================================
--- /src/robot/writer/rowsplitter.py    Tue Nov 27 01:27:32 2012
+++ /src/robot/writer/rowsplitter.py    Fri Dec 14 02:20:30 2012
@@ -80,7 +80,7 @@

     def _add_line_continuation(self, data):
         if data:
-            if self._in_comment:
+ if self._in_comment and not data[0].startswith(self._comment_mark):
                 data[0] = self._comment_mark + data[0]
             data = [self._line_continuation] + data
         return data
=======================================
--- /utest/parsing/test_populator.py    Wed Aug 29 04:28:21 2012
+++ /utest/parsing/test_populator.py    Fri Dec 14 02:20:30 2012
@@ -381,10 +381,10 @@
         test = self._first_test()
         assert_equals(test.name, '')
         assert_equals(test.doc.value, "What's up doc?")
-        assert_equals(test.steps[0].comment.as_list(), ['# comment'])
+        assert_equals(test.steps[0].comment.as_list(), ['#comment'])

     def test_unnamed_test_and_line_continuation(self):
-        self._create_table('test cases', [['', '...', 'foo', '#comment']])
+        self._create_table('test cases', [['', '...', 'foo', '# comment']])
         assert_equals(self._first_test().name, '')
         assert_equals(self._first_test().steps[0].keyword, 'foo')
assert_equals(self._first_test().steps[0].comment.as_list(), ['# comment'])
@@ -513,30 +513,30 @@

     def test_setting_table(self):
self._create_table('settings', [['Force Tags', 'Foo', 'Bar', '#comment'],
-                                        ['Library', 'Foo', '#Lib comment'],
+ ['Library', 'Foo', '# Lib comment'],
                                         [' #Resource', 'resource.txt'],
                                         ['Resource', 'resource2.txt'],
- ['#comment', 'between rows', 'in many cells'], - ['Default Tags', 'Quux', '#also end of line'], + ['# comment', 'between rows', 'in many cells'], + ['Default Tags', 'Quux', '# also eol'],
                                         ['Variables', 'varz.py'],
                                         ['# between values'],
                                         ['...', 'arg'],
                                         ['Meta: metaname', 'metavalue'],
-                                        ['#last line is commented'],
+                                        ['### last line is commented'],
                                         ])
         self._assert_no_parsing_errors()
-        self._assert_setting('force_tags', ['Foo', 'Bar'], ['# comment'])
+        self._assert_setting('force_tags', ['Foo', 'Bar'], ['#comment'])
         self._assert_import(0, 'Foo', [], ['# Lib comment'])
- self._assert_import(1, 'resource2.txt', [], ['# Resource', 'resource.txt']) - self._assert_setting('default_tags', ['Quux'], ['# comment', 'between rows', 'in many cells', 'also end of line']) + self._assert_import(1, 'resource2.txt', [], ['#Resource', 'resource.txt']) + self._assert_setting('default_tags', ['Quux'], ['# comment', 'between rows', 'in many cells', '# also eol'])
         self._assert_import(2, 'varz.py', ['arg'], ['# between values'])
- self._assert_meta(0, 'metaname', 'metavalue', ['# last line is commented']) + self._assert_meta(0, 'metaname', 'metavalue', ['### last line is commented'])

     def test_variable_table(self):
         self._create_table('variables', [['# before'],
- ['${varname}', 'varvalue', '#has comment'], + ['${varname}', 'varvalue', '# has comment'],
                                          ['${name}', '# no value'],
-                                         ['#middle', 'A', 'B', 'C'],
+                                         ['# middle', 'A', 'B', 'C'],
                                          ['@{items}', '1', '2', '3'],
                                          ['# s1'],
                                          ['', '# s2', ''],
@@ -546,7 +546,7 @@
                                          ['...', 'V1', '# c3'],
                                          ['# c4'],
                                          ['...', 'V2', '# c5'],
-                                         ['#EOT']])
+                                         ['###EOT###']])
         self._assert_no_parsing_errors()
         self._assert_variable(0, '', [], ['# before'])
self._assert_variable(1, '${varname}', ['varvalue'], ['# has comment'])
@@ -556,13 +556,13 @@
         self._assert_variable(5, '', [], ['# s1'])
         self._assert_variable(6, '', [], ['# s2'])
         self._assert_variable(7, '', [], ['# s3'])
- self._assert_variable(8, '@{X}', ['V1', 'V2'], ['# c1', 'c2', 'c3', 'c4', 'c5'])
-        self._assert_variable(9, '', [], ['# EOT'])
+ self._assert_variable(8, '@{X}', ['V1', 'V2'], ['# c1', '# c2', '# c3', '# c4', '# c5'])
+        self._assert_variable(9, '', [], ['###EOT###'])

     def test_test_case_table(self):
-        self._create_table('test cases', [['#start of table comment'],
+        self._create_table('test cases', [['# start of table comment'],
                                           ['Test case'],
- ['', 'No operation', '#step comment'], + ['', 'No operation', '# step comment'], ['', '', '#This step has', 'only comment'], ['Another test', '#comment in name row'],
                                           ['', 'Log many', 'argh'],
@@ -571,19 +571,19 @@
                                           ['Test with for loop'],
                                           ['',':FOR', 'v*ttuperkele'],
                                           ['#commented out in for loop'],
- ['','', 'Fooness in the bar', '#end commtne'], + ['','', 'Fooness in the bar', '###end commtne'],
                                           ['','# ', '   Barness  '],
                                           ['', 'Lodi']
                                           ])
self._assert_comment(self._first_test().steps[0], ['# start of table comment']) self._assert_comment(self._first_test().steps[1], ['# step comment']) - self._assert_comment(self._first_test().steps[2], ['# This step has', 'only comment']) - self._assert_comment(self._nth_test(2).steps[0], ['# comment in name row']) - self._assert_comment(self._nth_test(2).steps[1], ['# Comment between step def']) + self._assert_comment(self._first_test().steps[2], ['#This step has', 'only comment']) + self._assert_comment(self._nth_test(2).steps[0], ['#comment in name row']) + self._assert_comment(self._nth_test(2).steps[1], ['#', 'Comment between step def'])
         assert_equals(self._nth_test(2).steps[1].args, ['argh', 'urgh'])
- self._assert_comment(self._nth_test(3).steps[0].steps[0], ['# commented out in for loop']) - self._assert_comment(self._nth_test(3).steps[0].steps[1], ['# end commtne'])
-        self._assert_comment(self._nth_test(3).steps[1], ['# Barness'])
+ self._assert_comment(self._nth_test(3).steps[0].steps[0], ['#commented out in for loop']) + self._assert_comment(self._nth_test(3).steps[0].steps[1], ['###end commtne'])
+        self._assert_comment(self._nth_test(3).steps[1], ['#', 'Barness'])
         self._number_of_steps_should_be(self._nth_test(3), 3)

     def _assert_comment(self, step, expected_comment):

Reply via email to