本文整理汇总了Python中coalib.results.TextRange.TextRange.from_values方法的典型用法代码示例。如果您正苦于以下问题:Python TextRange.from_values方法的具体用法?Python TextRange.from_values怎么用?Python TextRange.from_values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coalib.results.TextRange.TextRange
的用法示例。
在下文中一共展示了TextRange.from_values方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_contains
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_contains(self):
range_a = TextRange.from_values(1, 1, 1, 19)
range_b = TextRange.from_values(1, 1, 1, 20)
self.assertIn(range_a, range_b)
range_a = TextRange.from_values(1, 1, 1, 21)
range_b = TextRange.from_values(1, 1, 1, 20)
self.assertNotIn(range_a, range_b)
range_a = TextRange.from_values(1, 5, 1, 5)
range_b = TextRange.from_values(1, 1, 1, 20)
self.assertIn(range_a, range_b)
range_a = TextRange.from_values(1, 1, 1, 18)
range_b = TextRange.from_values(1, 14, 1, 20)
self.assertNotIn(range_a, range_b)
range_a = TextRange.from_values(1, 1, 1, 20)
range_b = TextRange.from_values(1, 1, 1, 20)
self.assertIn(range_a, range_b)
示例2: test_no_overlap
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_no_overlap(self):
uut1 = TextRange.from_values(2, None, 3)
uut2 = TextRange.from_values(4, None, 5)
self.assertFalse(uut1.overlaps(uut2))
self.assertFalse(uut2.overlaps(uut1))
uut1 = TextRange.from_values(2, None, 3, 6)
uut2 = TextRange.from_values(3, 7, 5)
self.assertFalse(uut1.overlaps(uut2))
self.assertFalse(uut2.overlaps(uut1))
示例3: __init__
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def __init__(self, documentation, docstyle_definition,
indent, marker, position):
"""
Instantiates a new DocumentationComment.
:param documentation:
The documentation text.
:param docstyle_definition:
The ``DocstyleDefinition`` instance that defines what docstyle is
being used in the documentation.
:param indent:
The string of indentation used in front of the first marker of the
documentation.
:param marker:
The three-element tuple with marker strings, that identified this
documentation comment.
:param position:
The starting ``TextPosition`` of the documentation.
"""
self.documentation = documentation
self.docstyle_definition = docstyle_definition
self.indent = '' if indent is None else indent
self.marker = ('', '', '') if marker is None else marker
self.position = position
self.range = None if position is None else TextRange.from_values(
position.line,
position.column,
position.line + self.assemble().count('\n'),
len(self.assemble()) - self.assemble().rfind('\n'))
示例4: test_extract_documentation_C
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_extract_documentation_C(self):
data = load_testdata('data.c')
# No built-in documentation for C.
with self.assertRaises(KeyError):
tuple(extract_documentation(data, 'C', 'default'))
docstyle_C_doxygen = DocstyleDefinition.load('C', 'doxygen')
expected_results = (DocumentationComment(
('\n'
' This is the main function.\n'
'\n'
' @returns Your favorite number.\n'),
docstyle_C_doxygen, '',
docstyle_C_doxygen.markers[0],
TextRange.from_values(3, 1, 7, 4)),
DocumentationComment(
('\n'
' Preserves alignment\n'
' - Main item\n'
' - sub item\n'
' - sub sub item\n'),
docstyle_C_doxygen, '',
docstyle_C_doxygen.markers[2],
TextRange.from_values(15, 1, 20, 4)),
DocumentationComment(
(' ABC\n'
' Another type of comment\n'
'\n'
' ...'),
docstyle_C_doxygen, '',
docstyle_C_doxygen.markers[1],
TextRange.from_values(23, 1, 26, 11)),
DocumentationComment(
(' foobar = barfoo.\n'
' @param x whatever...\n'),
docstyle_C_doxygen, '',
docstyle_C_doxygen.markers[0],
TextRange.from_values(28, 1, 30, 4)))
self.assertEqual(tuple(
extract_documentation(data, 'C', 'doxygen')),
expected_results)
示例5: test_extract_documentation_C
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_extract_documentation_C(self):
data = load_testdata("data.c")
# No built-in documentation for C.
with self.assertRaises(KeyError):
tuple(extract_documentation(data, "C", "default"))
docstyle_C_doxygen = DocstyleDefinition.load("C", "doxygen")
expected_results = (DocumentationComment(
("\n"
" This is the main function.\n"
"\n"
" @returns Your favorite number.\n"),
docstyle_C_doxygen, "",
docstyle_C_doxygen.markers[0],
TextRange.from_values(3, 1, 7, 4)),
DocumentationComment(
("\n"
" Preserves alignment\n"
" - Main item\n"
" - sub item\n"
" - sub sub item\n"),
docstyle_C_doxygen, "",
docstyle_C_doxygen.markers[2],
TextRange.from_values(15, 1, 20, 4)),
DocumentationComment(
(" ABC\n"
" Another type of comment\n"
"\n"
" ..."),
docstyle_C_doxygen, "",
docstyle_C_doxygen.markers[1],
TextRange.from_values(23, 1, 26, 11)),
DocumentationComment(
(" foobar = barfoo.\n"
" @param x whatever...\n"),
docstyle_C_doxygen, "",
docstyle_C_doxygen.markers[0],
TextRange.from_values(28, 1, 30, 4)))
self.assertEqual(tuple(
extract_documentation(data, "C", "doxygen")),
expected_results)
示例6: test_extract_documentation_CPP
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_extract_documentation_CPP(self):
data = load_testdata("data.cpp")
# No built-in documentation for C++.
with self.assertRaises(KeyError):
tuple(extract_documentation(data, "CPP", "default"))
docstyle_CPP_doxygen = DocstyleDefinition.load("CPP", "doxygen")
self.assertEqual(tuple(extract_documentation(data, "CPP", "doxygen")),
(DocumentationComment(
("\n"
" This is the main function.\n"
" @returns Exit code.\n"
" Or any other number.\n"),
docstyle_CPP_doxygen, "",
docstyle_CPP_doxygen.markers[0],
TextRange.from_values(4, 1, 8, 4)),
DocumentationComment(
(" foobar\n"
" @param xyz\n"),
docstyle_CPP_doxygen, "",
docstyle_CPP_doxygen.markers[0],
TextRange.from_values(15, 1, 17, 4)),
DocumentationComment(
" Some alternate style of documentation\n",
docstyle_CPP_doxygen, "",
docstyle_CPP_doxygen.markers[4],
TextRange.from_values(22, 1, 23, 1)),
DocumentationComment(
" ends instantly",
docstyle_CPP_doxygen, "\t",
docstyle_CPP_doxygen.markers[0],
TextRange.from_values(26, 2, 26, 23)),
DocumentationComment(
(" Should work\n"
"\n"
" even without a function standing below.\n"
"\n"
" @param foo WHAT PARAM PLEASE!?\n"),
docstyle_CPP_doxygen, "",
docstyle_CPP_doxygen.markers[4],
TextRange.from_values(32, 1, 37, 1))))
示例7: test_extract_documentation_CPP
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_extract_documentation_CPP(self):
data = load_testdata('data.cpp')
# No built-in documentation for C++.
with self.assertRaises(KeyError):
tuple(extract_documentation(data, 'CPP', 'default'))
docstyle_CPP_doxygen = DocstyleDefinition.load('CPP', 'doxygen')
self.assertEqual(tuple(extract_documentation(data, 'CPP', 'doxygen')),
(DocumentationComment(
('\n'
' This is the main function.\n'
' @returns Exit code.\n'
' Or any other number.\n'),
docstyle_CPP_doxygen, '',
docstyle_CPP_doxygen.markers[0],
TextRange.from_values(4, 1, 8, 4)),
DocumentationComment(
(' foobar\n'
' @param xyz\n'),
docstyle_CPP_doxygen, '',
docstyle_CPP_doxygen.markers[0],
TextRange.from_values(15, 1, 17, 4)),
DocumentationComment(
' Some alternate style of documentation\n',
docstyle_CPP_doxygen, '',
docstyle_CPP_doxygen.markers[4],
TextRange.from_values(22, 1, 23, 1)),
DocumentationComment(
' ends instantly',
docstyle_CPP_doxygen, '\t',
docstyle_CPP_doxygen.markers[0],
TextRange.from_values(26, 2, 26, 23)),
DocumentationComment(
(' Should work\n'
'\n'
' even without a function standing below.\n'
'\n'
' @param foo WHAT PARAM PLEASE!?\n'),
docstyle_CPP_doxygen, '',
docstyle_CPP_doxygen.markers[4],
TextRange.from_values(32, 1, 37, 1))))
示例8: test_extract_documentation_C_2
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_extract_documentation_C_2(self):
data = ['/** my main description\n', ' * continues here */']
docstyle_C_doxygen = DocstyleDefinition.load("C", "doxygen")
self.assertEqual(
list(extract_documentation(data, "C", "doxygen")),
[DocumentationComment(" my main description\n continues here",
docstyle_C_doxygen.markers[0],
TextRange.from_values(1, 1, 2, 21))])
示例9: test_extract_documentation_PYTHON3_2
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_extract_documentation_PYTHON3_2(self):
data = ['\n', '""" documentation in single line """\n', 'print(1)\n']
docstyle_PYTHON3_default = DocstyleDefinition.load("PYTHON3",
"default")
self.assertEqual(
list(extract_documentation(data, "PYTHON3", "default")),
[DocumentationComment(" documentation in single line ",
docstyle_PYTHON3_default.markers[0],
TextRange.from_values(2, 1, 2, 38))])
示例10: test_extract_documentation_CPP_2
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_extract_documentation_CPP_2(self):
data = DocumentationExtractionTest.load_testdata("data2.cpp")
docstyle_CPP_doxygen = DocstyleDefinition.load("CPP", "doxygen")
self.assertEqual(tuple(extract_documentation(data, "CPP", "doxygen")),
(DocumentationComment(
("module comment\n"
" hello world\n"),
docstyle_CPP_doxygen.markers[0],
TextRange.from_values(1, 1, 3, 4)),))
示例11: test_extract_documentation_CPP_2
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_extract_documentation_CPP_2(self):
data = load_testdata('data2.cpp')
docstyle_CPP_doxygen = DocstyleDefinition.load('CPP', 'doxygen')
self.assertEqual(tuple(extract_documentation(data, 'CPP', 'doxygen')),
(DocumentationComment(
('module comment\n'
' hello world\n'),
docstyle_CPP_doxygen, '',
docstyle_CPP_doxygen.markers[0],
TextRange.from_values(1, 1, 3, 4)),))
示例12: test_extract_documentation_PYTHON3_3
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_extract_documentation_PYTHON3_3(self):
data = ['## documentation in single line without return at end.']
docstyle_PYTHON3_doxygen = DocstyleDefinition.load("PYTHON3",
"doxygen")
self.assertEqual(
list(extract_documentation(data, "PYTHON3", "doxygen")),
[DocumentationComment(" documentation in single line without "
"return at end.",
docstyle_PYTHON3_doxygen.markers[1],
TextRange.from_values(1, 1, 1, 55))])
示例13: _extract_doc_comment_from_line
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def _extract_doc_comment_from_line(content, line, column, regex, marker_dict):
begin_match = regex.search(content[line], column)
if begin_match:
column = begin_match.end()
for marker in marker_dict[begin_match.group()]:
doc_comment = _extract_doc_comment(content, line, column, marker)
if doc_comment is not None:
end_line, end_column, documentation = doc_comment
rng = TextRange.from_values(line + 1,
begin_match.start() + 1,
end_line + 1,
end_column + 1)
doc = DocumentationComment(documentation, marker, rng)
return end_line, end_column, doc
return line + 1, 0, None
示例14: test_overlap
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_overlap(self):
uut1 = TextRange.from_values(2, None, 3)
uut2 = TextRange.from_values(3, None, 5)
self.assertTrue(uut1.overlaps(uut2))
self.assertTrue(uut2.overlaps(uut1))
uut1 = TextRange.from_values(2, None, 3, 6)
uut2 = TextRange.from_values(3, 6, 5)
self.assertTrue(uut1.overlaps(uut2))
self.assertTrue(uut2.overlaps(uut1))
uut1 = TextRange.from_values(2, None, 7)
uut2 = TextRange.from_values(3, None, 5)
self.assertTrue(uut1.overlaps(uut2))
self.assertTrue(uut2.overlaps(uut1))
uut1 = TextRange.from_values(5, None, 7)
uut2 = TextRange.from_values(3, None, 6)
self.assertTrue(uut1.overlaps(uut2))
self.assertTrue(uut2.overlaps(uut1))
示例15: test_generate_diff
# 需要导入模块: from coalib.results.TextRange import TextRange [as 别名]
# 或者: from coalib.results.TextRange.TextRange import from_values [as 别名]
def test_generate_diff(self):
data_old = ['\n', '""" documentation in single line """\n']
for doc_comment in DocBaseClass.extract(
data_old, 'PYTHON3', 'default'):
old_doc_comment = doc_comment
old_range = TextRange.from_values(
old_doc_comment.range.start.line,
1,
old_doc_comment.range.end.line,
old_doc_comment.range.end.column)
data_new = ['\n', '"""\n documentation in single line\n"""\n']
for doc_comment in DocBaseClass.extract(
data_new, 'PYTHON3', 'default'):
new_doc_comment = doc_comment
diff = DocBaseClass.generate_diff(
data_old, old_doc_comment, new_doc_comment)
diff_expected = Diff(data_old)
diff_expected.replace(old_range, new_doc_comment.assemble())
self.assertEqual(diff, diff_expected)