|
4 | 4 |
|
5 | 5 | from robot.utils.text import cut_long_message, _count_line_lengths, \ |
6 | 6 | _MAX_ERROR_LINES, _MAX_ERROR_LINE_LENGTH, _ERROR_CUT_EXPLN,\ |
7 | | - get_console_length, pad_console_length |
| 7 | + get_console_length, pad_console_length, split_tags_from_doc |
8 | 8 |
|
9 | 9 |
|
10 | 10 | class NoCutting(unittest.TestCase): |
@@ -161,5 +161,40 @@ def test_cut_east_asian(self): |
161 | 161 | assert_equal(pad_console_length(self.mixed_26, 11), u'012345\u6c49...') |
162 | 162 |
|
163 | 163 |
|
| 164 | +class TestDocSplitter(unittest.TestCase): |
| 165 | + |
| 166 | + def test_doc_without_tags(self): |
| 167 | + docs = ["Single doc line.", |
| 168 | + """Hello, we dont have tags here. |
| 169 | + |
| 170 | + No sir. No tags.""", |
| 171 | + "Now Tags: must, start from beginning of the row", |
| 172 | + " We strip the trailing whitespace \n \n"] |
| 173 | + for doc in docs: |
| 174 | + self._assert_doc_and_tags(doc, doc.rstrip(), []) |
| 175 | + |
| 176 | + def _assert_doc_and_tags(self, original, expected_doc, expected_tags): |
| 177 | + doc, tags = split_tags_from_doc(original) |
| 178 | + assert_equal(doc, expected_doc) |
| 179 | + assert_equal(tags, expected_tags) |
| 180 | + |
| 181 | + def test_doc_with_tags(self): |
| 182 | + sets = [ |
| 183 | + ('Tags: foo, bar', '', ['foo', 'bar']), |
| 184 | + (' Tags: foo ', '', ['foo']), |
| 185 | + ('Hello\nTags: foo, bar', 'Hello', ['foo', 'bar']), |
| 186 | + ('Tags: bar\n Tags: foo ', 'Tags: bar', ['foo']), |
| 187 | + ('Tags: bar, Tags:, foo ', '', ['bar', 'Tags:', 'foo']), |
| 188 | + ('tags: foo', '', ['foo']), |
| 189 | + (' tags: foo , bar ', '', ['foo', 'bar']), |
| 190 | + ('Hello\n taGS: foo, bar', 'Hello', ['foo', 'bar']), |
| 191 | + (' Hello\n taGS: f, b \n\n \n', ' Hello', ['f', 'b']), |
| 192 | + ('Hello\nNl \n \nTags: foo', 'Hello\nNl', ['foo']), |
| 193 | + ] |
| 194 | + for original, exp_doc, exp_tags in sets: |
| 195 | + self._assert_doc_and_tags(original, exp_doc, exp_tags) |
| 196 | + self._assert_doc_and_tags(original+'\n', exp_doc, exp_tags) |
| 197 | + |
| 198 | + |
164 | 199 | if __name__ == '__main__': |
165 | 200 | unittest.main() |
0 commit comments