Rewrite parser to support block/dynamic comments

This commit is contained in:
alstr
2021-03-28 09:56:33 +01:00
parent a6fcdf71b1
commit cd988d2d92
8 changed files with 1269 additions and 300 deletions

102
tests/test_closed.diff Normal file
View File

@@ -0,0 +1,102 @@
diff --git a/tests/ExampleFile.java b/tests/ExampleFile.java
index d340f6a..29b54da 100644
--- a/tests/ExampleFile.java
+++ b/tests/ExampleFile.java
@@ -1,13 +1,5 @@
package com.mydomain.myapp;
public class JavaTests {
- // TODO: Expand this class
- // Do it
- // labels: urgent
- /*
- TODO: Definitely expand this class
- Do it ASAP
- labels: urgent
- */
}
\ No newline at end of file
diff --git a/tests/example-file.css b/tests/example-file.css
index 344fe46..0519500 100644
--- a/tests/example-file.css
+++ b/tests/example-file.css
@@ -1,10 +1,4 @@
body {
- <!-- TODO: This is too bright -->
background: red;
- <!--
- TODO: Insufficient contrast
- Use another colour for the text
- labels: UI
- -->
color: deeppink;
}
\ No newline at end of file
diff --git a/tests/example-file.php b/tests/example-file.php
index d36df2f..e77f4bb 100644
--- a/tests/example-file.php
+++ b/tests/example-file.php
@@ -4,19 +4,8 @@
<?php
echo 'Testing 123';
- // TODO: Expand this page
- // We aren't doing anything here yet
-
echo 'Testing 456';
- # TODO: Definitely expand this
- # There needs to be some point to this file
-
echo 'Testing 789'
- /*
- * TODO: Echo a greeting instead
- * This should work with or without the asterisk on each line
- * labels: help wanted
- */
?>
</body>
diff --git a/tests/example_file.py b/tests/example_file.py
index 525e25d..ba4e68d 100644
--- a/tests/example_file.py
+++ b/tests/example_file.py
@@ -1,7 +1,2 @@
def hello_world():
- # TODO: Come up with a more imaginative greeting
print('Hello world')
-
- # TODO: Do more stuff
- # This function should probably do something more interesting
- # labels: help wanted
diff --git a/tests/example_file.rb b/tests/example_file.rb
index e6da2ec..67f14dd 100644
--- a/tests/example_file.rb
+++ b/tests/example_file.rb
@@ -1,14 +1,3 @@
#!/usr/bin/ruby -w
-# TODO: Come up with a more imaginative greeting
puts "Greetings"
-
-=begin
-TODO: Do more stuff
-This function should probably do something more interesting
-labels: help wanted
-=end
-
-# TODO: Do even more stuff
-# This function should probably do something more interesting
-# labels: help wanted
diff --git a/tests/example_file.yaml b/tests/example_file.yaml
index 6397789..494d42f 100644
--- a/tests/example_file.yaml
+++ b/tests/example_file.yaml
@@ -1,7 +1,3 @@
name: "TODO to Issue"
-# TODO: Write a more interesting description
description: "Converts IDE TODO comments to GitHub issues"
author: "Alastair Mooney"
-# TODO: Define inputs
-# Need to do this before the action is released
-# labels: urgent

113
tests/test_new.diff Normal file
View File

@@ -0,0 +1,113 @@
diff --git a/tests/ExampleFile.java b/tests/ExampleFile.java
new file mode 100644
index 0000000..d340f6a
--- /dev/null
+++ b/tests/ExampleFile.java
@@ -0,0 +1,13 @@
+package com.mydomain.myapp;
+
+public class JavaTests {
+ // TODO: Expand this class
+ // Do it
+ // labels: urgent
+
+ /*
+ TODO: Definitely expand this class
+ Do it ASAP
+ labels: urgent
+ */
+}
\ No newline at end of file
diff --git a/tests/example-file.css b/tests/example-file.css
new file mode 100644
index 0000000..344fe46
--- /dev/null
+++ b/tests/example-file.css
@@ -0,0 +1,10 @@
+body {
+ <!-- TODO: This is too bright -->
+ background: red;
+ <!--
+ TODO: Insufficient contrast
+ Use another colour for the text
+ labels: UI
+ -->
+ color: deeppink;
+}
\ No newline at end of file
diff --git a/tests/example-file.php b/tests/example-file.php
new file mode 100644
index 0000000..d36df2f
--- /dev/null
+++ b/tests/example-file.php
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+<body>
+
+<?php
+ echo 'Testing 123';
+ // TODO: Expand this page
+ // We aren't doing anything here yet
+
+ echo 'Testing 456';
+ # TODO: Definitely expand this
+ # There needs to be some point to this file
+
+ echo 'Testing 789'
+ /*
+ * TODO: Echo a greeting instead
+ * This should work with or without the asterisk on each line
+ * labels: help wanted
+ */
+?>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/tests/example_file.py b/tests/example_file.py
new file mode 100644
index 0000000..525e25d
--- /dev/null
+++ b/tests/example_file.py
@@ -0,0 +1,7 @@
+def hello_world():
+ # TODO: Come up with a more imaginative greeting
+ print('Hello world')
+
+ # TODO: Do more stuff
+ # This function should probably do something more interesting
+ # labels: help wanted
diff --git a/tests/example_file.rb b/tests/example_file.rb
new file mode 100644
index 0000000..e6da2ec
--- /dev/null
+++ b/tests/example_file.rb
@@ -0,0 +1,14 @@
+#!/usr/bin/ruby -w
+
+# TODO: Come up with a more imaginative greeting
+puts "Greetings"
+
+=begin
+TODO: Do more stuff
+This function should probably do something more interesting
+labels: help wanted
+=end
+
+# TODO: Do even more stuff
+# This function should probably do something more interesting
+# labels: help wanted
diff --git a/tests/example_file.yaml b/tests/example_file.yaml
new file mode 100644
index 0000000..6397789
--- /dev/null
+++ b/tests/example_file.yaml
@@ -0,0 +1,7 @@
+name: "TODO to Issue"
+# TODO: Write a more interesting description
+description: "Converts IDE TODO comments to GitHub issues"
+author: "Alastair Mooney"
+# TODO: Define inputs
+# Need to do this before the action is released
+# labels: urgent

60
tests/test_todo_parser.py Normal file
View File

@@ -0,0 +1,60 @@
import unittest
from main import TodoParser
def count_issues_for_file_type(raw_issues, file_type):
num_issues = 0
for issue in raw_issues:
if issue.markdown_language == file_type:
num_issues += 1
return num_issues
class NewIssueTests(unittest.TestCase):
# Check for newly added TODOs across the files specified (covers all current marker types).
def setUp(self):
diff_file = open('tests/test_new.diff', 'r')
self.raw_issues = TodoParser().parse(diff_file)
def test_python_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'python'), 2)
def test_yaml_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'yaml'), 2)
def test_php_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'php'), 3)
def test_java_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'java'), 2)
def test_css_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'css'), 2)
def test_ruby_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'ruby'), 3)
class ClosedIssueTests(unittest.TestCase):
# Check for removed TODOs across the files specified (covers all current marker types).
def setUp(self):
diff_file = open('tests/test_closed.diff', 'r')
self.raw_issues = TodoParser().parse(diff_file)
def test_python_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'python'), 2)
def test_yaml_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'yaml'), 2)
def test_php_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'php'), 3)
def test_java_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'java'), 2)
def test_css_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'css'), 2)
def test_ruby_issues(self):
self.assertEqual(count_issues_for_file_type(self.raw_issues, 'ruby'), 3)