diff --git a/autoapi/mappers/dotnet.py b/autoapi/mappers/dotnet.py index 89bb945..d4628cf 100644 --- a/autoapi/mappers/dotnet.py +++ b/autoapi/mappers/dotnet.py @@ -276,8 +276,10 @@ class DotNetPythonMapper(PythonMapperBase): param.get('description', '')) }) - self.returns = self.transform_doc_comments( - syntax.get('return', None)) + self.returns = {} + self.returns['type'] = syntax.get('return', {}).get('type') + self.returns['description'] = self.transform_doc_comments( + syntax.get('return', {}).get('description')) # Inheritance # TODO Support more than just a class type here, should support enum/etc @@ -400,8 +402,19 @@ class DotNetPythonMapper(PythonMapperBase): text_start = re.sub(r'(\S)$', r'\1 ', text_start) text = ''.join([text_start, replacement, text_end]) - text = DOC_COMMENT_PARAM_PATTERN.sub( - '``\g``', text) + while True: + found = DOC_COMMENT_PARAM_PATTERN.search(text) + if found is None: + break + + # Escape following text + text_end = text[found.end():] + text_start = text[:found.start()] + text_end = re.sub(r'^(\S)', r'\\\1', text_end) + text_start = re.sub(r'(\S)$', r'\1 ', text_start) + + text = ''.join([text_start, '``', found.group('attr_value'), + '``', text_end]) except TypeError: pass return text diff --git a/tests/test_domains.py b/tests/test_domains.py index 5111941..38b98f0 100644 --- a/tests/test_domains.py +++ b/tests/test_domains.py @@ -7,7 +7,7 @@ from mock import patch from autoapi.mappers import dotnet -class DomainTests(unittest.TestCase): +class DotNetSphinxMapperTests(unittest.TestCase): def setUp(self): '''Test setup''' @@ -91,8 +91,11 @@ class DomainTests(unittest.TestCase): self.assertEqual(objs['Foo.Bar2'].id, 'Foo.Bar2') self.assertEqual(objs['Foo.Bar2'].name, 'Foo.Bar2') + +class DotNetPythonMapperTests(unittest.TestCase): + def test_xml_parse(self): - '''XML doc comment parsing''' + """XML doc comment parsing""" ret = dotnet.DotNetPythonMapper.transform_doc_comments( 'This is an example comment ') self.assertEqual(ret, 'This is an example comment :any:`FOO`') @@ -117,6 +120,14 @@ class DomainTests(unittest.TestCase): 'This is an example comment ') self.assertEqual(ret, 'This is an example comment ``FOO``') + ret = dotnet.DotNetPythonMapper.transform_doc_comments( + 'With surrounding characters ss') + self.assertEqual(ret, 'With surrounding characters s :any:`FOO`\s') + + ret = dotnet.DotNetPythonMapper.transform_doc_comments( + 'With surrounding characters ss') + self.assertEqual(ret, 'With surrounding characters s ``FOO``\s') + def test_xml_transform_escape(self): """XML transform escaping""" ret = dotnet.DotNetPythonMapper.transform_doc_comments( @@ -126,3 +137,31 @@ class DomainTests(unittest.TestCase): ret = dotnet.DotNetPythonMapper.transform_doc_comments( 'No space beforeor after') self.assertEqual(ret, 'No space before :dn:meth:`Foo\\`1`\\or after') + + def test_parsing_obj(self): + """Parse out object, test for transforms, etc""" + obj = { + 'uid': 'Foo`1', + 'name': 'Foo', + 'summary': 'Test parsing ', + 'syntax': { + 'parameters': [ + {'id': 'a', 'type': '{TUser}', + 'description': 'Test '} + ], + 'return': { + 'type': 'Bar', + 'description': ('Test references ' + 'and paramrefs '), + } + } + } + mapped = dotnet.DotNetPythonMapper(obj) + self.assertEqual( + mapped.parameters[0], + {'name': 'a', 'type': '{TUser}', 'desc': 'Test :any:`TUser`'} + ) + self.assertEqual( + mapped.returns['description'], + 'Test references :any:`Bar` and paramrefs ``a``' + )