diff --git a/main.py b/main.py index c1620a7..7e83639 100644 --- a/main.py +++ b/main.py @@ -404,7 +404,7 @@ class TodoParser(object): for marker in block['markers']: # Check if there are line or block comments. if marker['type'] == 'line': - comment_pattern = r'(^[+\-\s]\s*' + marker['pattern'] + '.+$)' + comment_pattern = r'(^[+\-\s].*' + marker['pattern'] + '.+$)' comments = re.finditer(comment_pattern, block['hunk'], re.MULTILINE) extracted_comments = [] prev_comment = None diff --git a/tests/test_closed.diff b/tests/test_closed.diff index 510ac0b..2c3f965 100644 --- a/tests/test_closed.diff +++ b/tests/test_closed.diff @@ -89,4 +89,21 @@ index 6397789..494d42f 100644 author: "Alastair Mooney" -# TODO: Define inputs -# Need to do this before the action is released --# labels: urgent \ No newline at end of file +-# labels: urgent +diff --git a/tests/example_file.prog.abap b/tests/example_file.prog.abap +index 6397789..494d42f 100644 +--- /dev/null ++++ b/tests/example_file.prog.abap +@@ -1,5 +0,0 @@ +-REPORT ztest_todo_2. +- +-DATA moo TYPE i VALUE 2. +-WRITE moo. " TODO This is an end-of-line to-do +-moo = 4. * TODO This is another end-of-line to-do +diff --git a/tests/example_file.sql b/src/tests/example_file.sql +index 6397789..494d42f 100644 +--- /dev/null ++++ b/src/tests/example_file.sql +@@ -1,2 +0,0 @@ +--- TODO Select all: +-SELECT * FROM Products; \ No newline at end of file diff --git a/tests/test_new.diff b/tests/test_new.diff index 1ab8862..1a423df 100644 --- a/tests/test_new.diff +++ b/tests/test_new.diff @@ -93,4 +93,23 @@ index 0000000..6397789 +author: "Alastair Mooney" +# TODO: Define inputs +# Need to do this before the action is released -+# labels: urgent \ No newline at end of file ++# labels: urgent +diff --git a/tests/example_file.prog.abap b/src/tests/example_file.prog.abap +new file mode 100644 +index 0000000..7cccc5b +--- /dev/null ++++ b/tests/example_file.prog.abap +@@ -0,0 +1,5 @@ ++REPORT ztest_todo_2. ++ ++DATA moo TYPE i VALUE 2. ++WRITE moo. " TODO This is an end-of-line to-do ++moo = 4. * TODO This is another end-of-line to-do +diff --git a/tests/example_file.sql b/src/tests/example_file.sql +new file mode 100644 +index 0000000..7cccc5b +--- /dev/null ++++ b/src/tests/example_file.sql +@@ -0,0 +1,2 @@ ++-- TODO Select all: ++SELECT * FROM Products; \ No newline at end of file diff --git a/tests/test_todo_parser.py b/tests/test_todo_parser.py index 3d44f55..59b57d3 100644 --- a/tests/test_todo_parser.py +++ b/tests/test_todo_parser.py @@ -12,7 +12,7 @@ def count_issues_for_file_type(raw_issues, file_type): class NewIssueTests(unittest.TestCase): - # Check for newly added TODOs across the files specified (covers all current marker types). + # Check for newly added TODOs across the files specified. def setUp(self): diff_file = open('tests/test_new.diff', 'r') self.raw_issues = TodoParser().parse(diff_file) @@ -32,9 +32,18 @@ class NewIssueTests(unittest.TestCase): def test_ruby_issues(self): self.assertEqual(count_issues_for_file_type(self.raw_issues, 'ruby'), 3) + def test_abap_issues(self): + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'abap'), 2) + + def test_sql_issues(self): + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'sql'), 1) + + # TODO: Update tests + # Need tests for Julia, AutoHotKey, Handlebars, Org and TeX, as these markers are not currently covered. + class ClosedIssueTests(unittest.TestCase): - # Check for removed TODOs across the files specified (covers all current marker types). + # Check for removed TODOs across the files specified. def setUp(self): diff_file = open('tests/test_closed.diff', 'r') self.raw_issues = TodoParser().parse(diff_file) @@ -54,10 +63,17 @@ class ClosedIssueTests(unittest.TestCase): def test_ruby_issues(self): self.assertEqual(count_issues_for_file_type(self.raw_issues, 'ruby'), 3) + def test_abap_issues(self): + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'abap'), 2) + + def test_sql_issues(self): + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'sql'), 1) + + class IgnorePatternTests(unittest.TestCase): def test_single_ignore(self): - os.environ['INPUT_IGNORE'] = '.*\.java' + os.environ['INPUT_IGNORE'] = '.*\\.java' diff_file = open('tests/test_new.diff', 'r') self.raw_issues = TodoParser().parse(diff_file) self.assertEqual(count_issues_for_file_type(self.raw_issues, 'python'), 2) @@ -68,7 +84,7 @@ class IgnorePatternTests(unittest.TestCase): os.environ['INPUT_IGNORE'] = '' def test_multiple_ignores(self): - os.environ['INPUT_IGNORE'] = '.*\.java, tests/example-file\.php' + os.environ['INPUT_IGNORE'] = '.*\\.java, tests/example-file\\.php' diff_file = open('tests/test_new.diff', 'r') self.raw_issues = TodoParser().parse(diff_file) self.assertEqual(count_issues_for_file_type(self.raw_issues, 'python'), 2)