本文整理汇总了Python中vai.models.TextDocument.TextDocument.extractFragment方法的典型用法代码示例。如果您正苦于以下问题:Python TextDocument.extractFragment方法的具体用法?Python TextDocument.extractFragment怎么用?Python TextDocument.extractFragment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vai.models.TextDocument.TextDocument
的用法示例。
在下文中一共展示了TextDocument.extractFragment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testInsertFragment
# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import extractFragment [as 别名]
def testInsertFragment(self):
doc = TextDocument()
with open(fixtures.get("numbers.txt"), "r") as f:
doc.read(f)
doc.createLineMetaInfo("whatever")
doc.createLineMetaInfo("whatever2")
fragment = doc.extractFragment(2)
self.assertNotEqual(fragment.lineText(1), doc.lineText(15))
doc.insertFragment(15, fragment)
self.assertEqual(fragment.lineText(1), doc.lineText(15))
fragment = doc.extractFragment(2, 4)
self.assertNotEqual(fragment.lineText(1), doc.lineText(10))
doc.insertFragment(10, fragment)
self.assertEqual(fragment.lineText(1), doc.lineText(10))
self.assertEqual(fragment.lineText(2), doc.lineText(11))
self.assertEqual(fragment.lineText(3), doc.lineText(12))
self.assertEqual(fragment.lineText(4), doc.lineText(13))
示例2: testExtractFragment
# 需要导入模块: from vai.models.TextDocument import TextDocument [as 别名]
# 或者: from vai.models.TextDocument.TextDocument import extractFragment [as 别名]
def testExtractFragment(self):
doc = TextDocument()
with open(fixtures.get("bigfile.py"), "r") as f:
doc.read(f)
doc.createLineMetaInfo("whatever")
doc.createLineMetaInfo("whatever2")
fragment = doc.extractFragment(2)
self.assertEqual(fragment.numLines(), 1)
self.assertEqual(fragment.lineText(1), doc.lineText(2))
self.assertTrue(fragment.hasLineMetaInfo("whatever"))
self.assertTrue(fragment.hasLineMetaInfo("whatever2"))
fragment = doc.extractFragment(2, 3)
self.assertEqual(fragment.numLines(), 3)
self.assertEqual(fragment.lineText(1), doc.lineText(2))
self.assertEqual(fragment.lineText(2), doc.lineText(3))
self.assertEqual(fragment.lineText(3), doc.lineText(4))
self.assertTrue(fragment.hasLineMetaInfo("whatever"))
self.assertTrue(fragment.hasLineMetaInfo("whatever2"))