Jan Borsodi avatar Jan Borsodi committed 818bd7e

Fixed issue #2: Incorrect parsing of documentation blocks.

Comments (0)

Files changed (2)

     if re.match("///", cmt):
         cmt = cmt[3:]
     elif cmt.startswith("/**") and cmt.endswith("*/"):
-        m = re.match(r"/\*\*(?:\w*[\n])?(.+)(?:\w+)?\*/", cmt, re.DOTALL | re.MULTILINE)
+        m = re.match(r"/\*\*(?:\w*[\n])?(.+)/$", cmt, re.DOTALL | re.MULTILINE)
         cmt = m.group(1)
-        cmt = "".join([re.sub("[ \t]*[*]", "", line) for line in cmt.splitlines(True)])
+        cmt = "".join([re.sub("^[ \t]*[*]", "", line, flags=re.MULTILINE) for line in cmt.splitlines(True)])
     return textwrap.dedent(cmt)
 
 words_re = re.compile("([A-Z][A-Z0-9]*(?=[A-Z][a-z0-9]))|([A-Z][A-Z0-9]*$)|([A-Z][a-z0-9]*)|([a-z][a-z0-9]*)")

tests/test_utils.py

+import difflib
+from hob.utils import parse_docblock
+
+def compareOutput(out, expected):
+    if out != expected:
+        for line in difflib.unified_diff(expected.splitlines(True), out.splitlines(True), "a", "b"):
+            print line,
+    assert out == expected
+
+def test_parse_docblock():
+    doc = """/**
+ * **DocTc** is a fake service designed to test the doucmentation generator.
+ *
+ * Inline markup (this is a subtitle)
+ * ----------------------------------
+ * This sentence uses *italic* text. This sentence uses **bold**.
+ *
+ * We also have ``monospace text``. Does monospace also work next to an edge?
+ * ``Maybe``.
+ *
+ * This interpreted text: `DocTc` should probably link to the service. So should
+ * `DocTc::PerformSomeAction`. That's probably some amount of work, though.
+ *
+ * Lists
+ * -----
+ *
+ * - First way
+ * - Of doing lists
+ *
+ * * Second way
+ * * Meh, don't use this way. But it should work.
+ *
+ * Enumerated list:
+ *
+ * #. One
+ * #. Two
+ *
+ * Escaping
+ * --------
+ *
+ * \*not bold*, \``not monospace``, a backslash should be visible: \\
+ *
+ * Line blocks
+ * -----------
+ *
+ * | These
+ * | words
+ * | should
+ * | be
+ * | on
+ * | different
+ * | lines
+ */"""
+
+    expected = """**DocTc** is a fake service designed to test the doucmentation generator.
+
+Inline markup (this is a subtitle)
+----------------------------------
+This sentence uses *italic* text. This sentence uses **bold**.
+
+We also have ``monospace text``. Does monospace also work next to an edge?
+``Maybe``.
+
+This interpreted text: `DocTc` should probably link to the service. So should
+`DocTc::PerformSomeAction`. That's probably some amount of work, though.
+
+Lists
+-----
+
+- First way
+- Of doing lists
+
+* Second way
+* Meh, don't use this way. But it should work.
+
+Enumerated list:
+
+#. One
+#. Two
+
+Escaping
+--------
+
+\*not bold*, \``not monospace``, a backslash should be visible: \\
+
+Line blocks
+-----------
+
+| These
+| words
+| should
+| be
+| on
+| different
+| lines
+"""
+    result = parse_docblock(doc)
+    compareOutput(result, expected)
+
+def test_parse_docblock2():
+    doc = """/**
+     *   RST
+     *   ---
+     *
+     *   Is whitespace
+     *   preserved (in rst)?
+     *
+     *   Everything except the first space after the asterisk should be preserved. IMO.
+     *
+     *              MIxed
+     *             WhItespace
+     *   This is horrIble
+     *               I am aligned (in rst)
+     */"""
+
+    expected = """RST
+---
+
+Is whitespace
+preserved (in rst)?
+
+Everything except the first space after the asterisk should be preserved. IMO.
+
+           MIxed
+          WhItespace
+This is horrIble
+            I am aligned (in rst)
+"""
+
+    result = parse_docblock(doc)
+    compareOutput(result, expected)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.