当前位置: 首页>>代码示例>>Python>>正文


Python Document.search方法代码示例

本文整理汇总了Python中model.Document.search方法的典型用法代码示例。如果您正苦于以下问题:Python Document.search方法的具体用法?Python Document.search怎么用?Python Document.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Document的用法示例。


在下文中一共展示了Document.search方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DocumentTestCase

# 需要导入模块: from model import Document [as 别名]
# 或者: from model.Document import search [as 别名]
class DocumentTestCase(unittest.TestCase):
    def setUp(self):
        self.doc = Document()

    def test_insert(self):
        self.doc.insert(0, "here")
        self.assertEqual(self.doc.visible_text, "here")

        self.doc.insert(0, "again ")
        self.assertEqual(self.doc.visible_text, "again here")

        self.doc.insert(8, "1")
        self.assertEqual(self.doc.visible_text, "again he1re")

        self.doc.insert(8, "23")
        self.assertEqual(self.doc.visible_text, "again he231re")

        self.doc.insert(len(self.doc.visible_text), "ing")
        self.assertEqual(self.doc.visible_text, "again he231reing")

    def test_remove(self):
        self.doc.insert(0, "here is some stuff\nover a few lines")
        self.assertEqual(self.doc.visible_text, "here is some stuff\nover a few lines")

        self.doc.remove(0, 5)
        self.assertEqual(self.doc.visible_text, "is some stuff\nover a few lines")

        self.doc.remove(1, 1)
        self.assertEqual(self.doc.visible_text, "i some stuff\nover a few lines")

        self.doc.remove(len(self.doc.visible_text) - 4, 4)
        self.assertEqual(self.doc.visible_text, "i some stuff\nover a few l")

    def test_search(self):
        self.doc.insert(0, "hello there\nthis is a test\nof search")
        self.doc.search("hello")
        self.assertEqual(self.doc.current_search, "hello")

        self.assertEqual(self.doc.visible_text, "hello there")
        self.doc.search("o")
        self.assertEqual(self.doc.visible_text, "hello there\nof search")
        self.doc.search("th")
        self.assertEqual(self.doc.visible_text, "hello there\nthis is a test")
        self.doc.search("")
        self.assertEqual(self.doc.visible_text, "hello there\nthis is a test\nof search")

    def test_search_multiple_words(self):
        self.doc.insert(0, "hello there\nthis is a test\nof search")
        self.doc.search("this test")
        self.assertEqual(self.doc.current_search, "this test")

        self.assertEqual(self.doc.visible_text, "this is a test")

    def test_search_and_insert(self):
        self.doc.search("test")
        self.assertEqual(self.doc.visible_text, "")

        self.doc.search("")
        self.doc.insert(0, "hello there\nthis is a test\nof search")

        self.doc.search("test")
        self.assertEqual(self.doc.visible_text, "this is a test")
        self.doc.insert(0, "again ")
        self.assertEqual(self.doc.visible_text, "again this is a test")
        self.assertEqual(self.doc.text, "hello there\nagain this is a test\nof search")

        self.doc.search("")
        self.assertEqual(self.doc.visible_text, "hello there\nagain this is a test\nof search")

        self.doc.search("search")
        self.assertEqual(self.doc.visible_text, "of search")
        self.doc.insert(0, "hello ")
        self.assertEqual(self.doc.visible_text, "hello of search")

        self.doc.search("hello")
        self.assertEqual(self.doc.visible_text, "hello there\nhello of search")
        self.doc.insert(11, "go")
        self.assertEqual(self.doc.visible_text, "hello therego\nhello of search")
        self.assertEqual(self.doc.text, "hello therego\nagain this is a test\nhello of search")
        self.doc.insert(15, "23")
        self.assertEqual(self.doc.visible_text, "hello therego\nh23ello of search")
        self.assertEqual(self.doc.text, "hello therego\nagain this is a test\nh23ello of search")

    def test_search_and_remove(self):
        self.doc.search("")
        self.doc.insert(0, "hello there\nthis is a test\nof search\nhello there")

        self.doc.search("hello")
        self.assertEqual(self.doc.visible_text, "hello there\nhello there")

        self.doc.remove(0, 3)
        self.assertEqual(self.doc.visible_text, "lo there\nhello there")

        self.doc.remove(len(self.doc.visible_text) - 3, 3)
        self.assertEqual(self.doc.visible_text, "lo there\nhello th")

        # now remove accross multiple visible regions
        self.doc.remove(7, 3)
        self.assertEqual(self.doc.visible_text, "lo therello th")

#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:notecomb,代码行数:103,代码来源:tests.py


注:本文中的model.Document.search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。