| @@ 20-63 (lines=44) @@ | ||
| 17 | with self.assertRaises(FileNotFoundError): |
|
| 18 | tuple(extract_documentation("", "PYTHON", "INVALID")) |
|
| 19 | ||
| 20 | def test_extract_documentation_C(self): |
|
| 21 | data = load_testdata("data.c") |
|
| 22 | ||
| 23 | # No built-in documentation for C. |
|
| 24 | with self.assertRaises(KeyError): |
|
| 25 | tuple(extract_documentation(data, "C", "default")) |
|
| 26 | ||
| 27 | docstyle_C_doxygen = DocstyleDefinition.load("C", "doxygen") |
|
| 28 | ||
| 29 | expected_results = (DocumentationComment( |
|
| 30 | ("\n" |
|
| 31 | " This is the main function.\n" |
|
| 32 | "\n" |
|
| 33 | " @returns Your favorite number.\n"), |
|
| 34 | docstyle_C_doxygen, "", |
|
| 35 | docstyle_C_doxygen.markers[0], |
|
| 36 | TextRange.from_values(3, 1, 7, 4)), |
|
| 37 | DocumentationComment( |
|
| 38 | ("\n" |
|
| 39 | " Preserves alignment\n" |
|
| 40 | " - Main item\n" |
|
| 41 | " - sub item\n" |
|
| 42 | " - sub sub item\n"), |
|
| 43 | docstyle_C_doxygen, "", |
|
| 44 | docstyle_C_doxygen.markers[2], |
|
| 45 | TextRange.from_values(15, 1, 20, 4)), |
|
| 46 | DocumentationComment( |
|
| 47 | (" ABC\n" |
|
| 48 | " Another type of comment\n" |
|
| 49 | "\n" |
|
| 50 | " ..."), |
|
| 51 | docstyle_C_doxygen, "", |
|
| 52 | docstyle_C_doxygen.markers[1], |
|
| 53 | TextRange.from_values(23, 1, 26, 11)), |
|
| 54 | DocumentationComment( |
|
| 55 | (" foobar = barfoo.\n" |
|
| 56 | " @param x whatever...\n"), |
|
| 57 | docstyle_C_doxygen, "", |
|
| 58 | docstyle_C_doxygen.markers[0], |
|
| 59 | TextRange.from_values(28, 1, 30, 4))) |
|
| 60 | ||
| 61 | self.assertEqual(tuple( |
|
| 62 | extract_documentation(data, "C", "doxygen")), |
|
| 63 | expected_results) |
|
| 64 | ||
| 65 | def test_extract_documentation_C_2(self): |
|
| 66 | data = ['/** my main description\n', ' * continues here */'] |
|
| @@ 77-119 (lines=43) @@ | ||
| 74 | docstyle_C_doxygen.markers[0], |
|
| 75 | TextRange.from_values(1, 1, 2, 21))]) |
|
| 76 | ||
| 77 | def test_extract_documentation_CPP(self): |
|
| 78 | data = load_testdata("data.cpp") |
|
| 79 | ||
| 80 | # No built-in documentation for C++. |
|
| 81 | with self.assertRaises(KeyError): |
|
| 82 | tuple(extract_documentation(data, "CPP", "default")) |
|
| 83 | ||
| 84 | docstyle_CPP_doxygen = DocstyleDefinition.load("CPP", "doxygen") |
|
| 85 | ||
| 86 | self.assertEqual(tuple(extract_documentation(data, "CPP", "doxygen")), |
|
| 87 | (DocumentationComment( |
|
| 88 | ("\n" |
|
| 89 | " This is the main function.\n" |
|
| 90 | " @returns Exit code.\n" |
|
| 91 | " Or any other number.\n"), |
|
| 92 | docstyle_CPP_doxygen, "", |
|
| 93 | docstyle_CPP_doxygen.markers[0], |
|
| 94 | TextRange.from_values(4, 1, 8, 4)), |
|
| 95 | DocumentationComment( |
|
| 96 | (" foobar\n" |
|
| 97 | " @param xyz\n"), |
|
| 98 | docstyle_CPP_doxygen, "", |
|
| 99 | docstyle_CPP_doxygen.markers[0], |
|
| 100 | TextRange.from_values(15, 1, 17, 4)), |
|
| 101 | DocumentationComment( |
|
| 102 | " Some alternate style of documentation\n", |
|
| 103 | docstyle_CPP_doxygen, "", |
|
| 104 | docstyle_CPP_doxygen.markers[4], |
|
| 105 | TextRange.from_values(22, 1, 23, 1)), |
|
| 106 | DocumentationComment( |
|
| 107 | " ends instantly", |
|
| 108 | docstyle_CPP_doxygen, "\t", |
|
| 109 | docstyle_CPP_doxygen.markers[0], |
|
| 110 | TextRange.from_values(26, 2, 26, 23)), |
|
| 111 | DocumentationComment( |
|
| 112 | (" Should work\n" |
|
| 113 | "\n" |
|
| 114 | " even without a function standing below.\n" |
|
| 115 | "\n" |
|
| 116 | " @param foo WHAT PARAM PLEASE!?\n"), |
|
| 117 | docstyle_CPP_doxygen, "", |
|
| 118 | docstyle_CPP_doxygen.markers[4], |
|
| 119 | TextRange.from_values(32, 1, 37, 1)))) |
|
| 120 | ||
| 121 | def test_extract_documentation_CPP_2(self): |
|
| 122 | data = load_testdata("data2.cpp") |
|