def test_search_extraListMarkerRightBeforeCheckbox(self): """Make sure we find a todo with an extra list marker right before the checkbox""" # If there is a valid list item marker with a space after it, then another list # item marker without a space after it directly before the checkbox, GitHub # renders this as a checkbox, so we'll treat it as one, too - even though I'm not # sure if this is a feature or a bug. result = search_line_for_todo("- -[ ] todo") self.assertEqual(result, "todo")
def get_todos(self): """Return a list of all lines in the comment that represent todos Returns a list of CommentTodo objects (or an empty list if there are no todos in this comment) """ todos = [] for line in self._content.splitlines(): todo_text = search_line_for_todo(line) if todo_text is not None: todos.append( CommentTodo(username=self._username, creation_date=self._creation_date, url=self._url, text=todo_text)) return todos
def get_todos(self, completed=False): """Return a list of all lines in the comment that represent todos Returns a list of CommentTodo objects (or an empty list if there are no todos in this comment) Args: completed: boolean - whether to look for completed todos instead of incomplete todos """ todos = [] for line in self._content.splitlines(): todo_text = search_line_for_todo(line, completed=completed) if todo_text is not None: todos.append( CommentTodo(username=self._username, time_info=self._time_info, url=self._url, text=todo_text, extra_info=self._get_extra_info(), completed=completed)) return todos
def test_search_checkedCheckbox_fails(self): """If the checkbox is checked, the search should fail""" result = search_line_for_todo("- [x] todo") self.assertIsNone(result)
def test_search_completed_unchecked_fails(self): """If the checkbox is unchecked, should fail""" result = search_line_for_todo("- [ ] todo", completed=True) self.assertIsNone(result)
def test_search_quotedWithSpace(self): """Make sure we find a quoted todo with a space after the quote marker""" result = search_line_for_todo("> - [ ] todo") self.assertEqual(result, "todo")
def test_search_multipleAlternatingQuotesAndLists2(self): """Make sure we find a todo with a mix of quote and list markers""" result = search_line_for_todo(">- >- >- [ ] todo") self.assertEqual(result, "todo")
def test_search_multipleSpacesAfterCheckbox(self): """Make sure we find a todo with multiple spaces after the checkbox""" result = search_line_for_todo("- [ ] todo") self.assertEqual(result, "todo")
def test_search_multipleUOL(self): """Make sure we find a todo with multiple unordered & ordered list markers""" result = search_line_for_todo("- 1. + 30) [ ] todo") self.assertEqual(result, "todo")
def test_search_onlyWhitespaceAfterCheckbox_fails(self): """If there is only whitespace after the checkbox character, the search should fail""" result = search_line_for_todo("- [ ] ") self.assertIsNone(result)
def test_search_olMultipleDigits(self): """Make sure we find a todo with multiple digits in the list indicator""" result = search_line_for_todo("123. [ ] todo") self.assertEqual(result, "todo")
def test_search_noPeriodOrParenAfterNumber_fails(self): """If there is no . or ) after a number, the search should fail""" result = search_line_for_todo("1 [ ] todo") self.assertIsNone(result)
def test_search_noWhitespaceAfterCheckbox_fails(self): """If no whitespace between the checkbox and the following text, the search should fail""" result = search_line_for_todo("- [ ]todo") self.assertIsNone(result)
def test_search_noWhitespaceAfterOL_fails(self): """If there is no whitespace after an ordered list marker, the search should fail""" result = search_line_for_todo("1.[ ] todo") self.assertIsNone(result)
def test_search_noCheckbox_fails(self): """If there is no checkbox, the search should fail""" result = search_line_for_todo("- todo") self.assertIsNone(result)
def test_search_noListMarker_fails(self): """If there is no list marker, the search should fail""" result = search_line_for_todo(" [ ] todo") self.assertIsNone(result)
def test_search_ulstar(self): """Make sure we find a todo like '* [ ] todo'""" result = search_line_for_todo("* [ ] todo") self.assertEqual(result, "todo")
def test_search_multipleSpacesInBrackets_fails(self): """If there are multiple spaces inside the brackets, the search should fail""" result = search_line_for_todo("- [ ] todo") self.assertIsNone(result)
def test_search_olparen(self): """Make sure we find a todo like '1) [ ] todo'""" result = search_line_for_todo("1) [ ] todo") self.assertEqual(result, "todo")
def test_search_otherTextFirst_fails(self): """If there is other text on the line before the checkbox stuff, the search should fail""" result = search_line_for_todo("hi - [ ] todo") self.assertIsNone(result)
def test_search_olMultipleSpaces(self): """Make sure we find a todo with multiple spaces after the ordered list indicator""" result = search_line_for_todo("1. [ ] todo") self.assertEqual(result, "todo")
def test_search_quoteJustBeforeCheckbox_fails(self): """If there are both list and quote markers, but the last is a quote, should fail""" result = search_line_for_todo("> - > [ ] todo") self.assertIsNone(result)
def test_search_leadingSpaces(self): """Make sure we find a todo with leading spaces on the line""" result = search_line_for_todo(" - [ ] todo") self.assertEqual(result, "todo")
def test_search_twoListMarkersRightBeforeCheckbox_fails(self): """If there are two list markers right before the checkbox, should fail""" # Even though "- -[ ] todo" renders as a checkbox, "- --[ ] todo" does not result = search_line_for_todo("- --[ ] todo") self.assertIsNone(result)
def test_search_quoted(self): """Make sure we find a quoted todo""" result = search_line_for_todo(">- [ ] todo") self.assertEqual(result, "todo")
def test_search_multipleAlternatingQuotesAndLists3(self): """Make sure we find a todo with a mix of quote and list markers""" # This is a really weird case, but GitHub treats it as a checkbox, so we will, too result = search_line_for_todo(">- >> + >1. - [ ] todo") self.assertEqual(result, "todo")
def test_search_multipleQuotes(self): """Make sure we find a quoted todo with multiple quote markers""" result = search_line_for_todo(">>> > > - [ ] todo") self.assertEqual(result, "todo")
def test_search_completed_y_fails(self): """If the checkbox is 'checked' with '[y]' instead of '[x'], should fail""" result = search_line_for_todo("- [y] todo", completed=True) self.assertIsNone(result)
def test_search_completed_uppercasex(self): """Make sure we find a completed todo like '- [X] todo'""" result = search_line_for_todo("- [X] todo", completed=True) self.assertEqual(result, "todo")
def test_search_emptyString_fails(self): """If the input is an empty string, the search should fail""" result = search_line_for_todo("") self.assertIsNone(result)