Example #1
0
 def test(c):
     text = "the text is made of many texts"
     m = Mocker()
     tv = m.mock(TextView)
     tv._Finder__last_mark >> (None, 0)
     tv._Finder__last_mark = (c.options.find_text, c.count)
     ts = tv.textStorage() >> m.mock(ak.NSTextStorage)
     app = m.replace(editxt, "app")
     app.config["highlight_selected_text.color"] >> "<color>"
     full_range = fn.NSMakeRange(0, ts.length() >> len(text))
     layout = tv.layoutManager()
     layout.removeTemporaryAttribute_forCharacterRange_(
         ak.NSBackgroundColorAttributeName, full_range)
     find_target = lambda: tv
     finder = Finder(find_target, c.options)
     if c.options.find_text:
         text = fn.NSString.alloc().initWithString_(text)
         (tv.string() << text).count(1, None)
         mark_range = layout.addTemporaryAttribute_value_forCharacterRange_ >> m.mock(
         )
         mark = mark_range(ak.NSBackgroundColorAttributeName, ANY, ANY)
         expect(mark).count(c.count)
     with m:
         count = finder.mark_occurrences(c.options.find_text, c.allow_regex)
         eq_(count, c.count)
Example #2
0
    def test(c):
        m = Mocker()
        options = make_options(c)
        tv = m.mock(TextView)
        tv.selectedRange() >> fn.NSMakeRange(0, 16)
        tv.string() >> fn.NSString.alloc().initWithString_(c.text)
        if not isinstance(c.expect, Exception):
            result = [c.text]

            def replace(range, value):
                start, end = range
                text = result[0]
                result[0] = text[:start] + value + text[start + end:]

            tv.shouldChangeTextInRange_replacementString_(ANY, ANY) >> True
            expect(tv.textStorage().replaceCharactersInRange_withString_(
                ANY, ANY)).call(replace)
            tv.didChangeText()
            tv.setNeedsDisplay_(True)
        finder = Finder((lambda: tv), options)
        with m:
            if isinstance(c.expect, Exception):

                def check(err):
                    print(err)
                    eq_(str(err), str(c.expect))

                with assert_raises(type(c.expect), msg=check):
                    getattr(finder, c.action)(None)
            else:
                getattr(finder, c.action)(None)
                eq_(result[0], c.expect)
Example #3
0
 def finder(self):
     try:
         finder = self._finder
     except Exception:
         finder = self._finder = Finder(
             (lambda: self.text_view),
             FindOptions(ignore_case=False, wrap_around=False),
         )
     return finder
Example #4
0
 def test(c):
     string = "the text is made of many texts"
     m = Mocker()
     editor = m.mock(Editor)
     editor._Finder__last_mark >> (None, 0)
     editor._Finder__last_mark = (c.options.find_text, c.count)
     app = m.mock('editxt.application.Application')
     app.theme["highlight_selected_text.color"] >> "<color>"
     (editor.text << Text(string)).count(1, None)
     full_range = (0, len(string))
     layout = editor.text_view.layoutManager()
     layout.removeTemporaryAttribute_forCharacterRange_(
         ak.NSBackgroundColorAttributeName, full_range)
     finder = Finder((lambda: editor), c.options, app)
     if c.options.find_text:
         mark_range = layout.addTemporaryAttribute_value_forCharacterRange_ >> m.mock()
         mark = mark_range(ak.NSBackgroundColorAttributeName, ANY, ANY)
         expect(mark).count(c.count)
     with m:
         count = finder.mark_occurrences(c.options.find_text, c.allow_regex)
         eq_(count, c.count)
Example #5
0
 def test(c):
     text = "the text is made of many texts"
     m = Mocker()
     tv = m.mock(TextView)
     tv._Finder__last_mark >> (None, 0)
     tv._Finder__last_mark = (c.options.find_text, c.count)
     ts = tv.textStorage() >> m.mock(ak.NSTextStorage)
     app = m.replace(editxt, "app")
     app.config["highlight_selected_text.color"] >> "<color>"
     full_range = fn.NSMakeRange(0, ts.length() >> len(text))
     layout = tv.layoutManager()
     layout.removeTemporaryAttribute_forCharacterRange_(
         ak.NSBackgroundColorAttributeName, full_range)
     find_target = lambda: tv
     finder = Finder(find_target, c.options)
     if c.options.find_text:
         text = fn.NSString.alloc().initWithString_(text)
         (tv.string() << text).count(1, None)
         mark_range = layout.addTemporaryAttribute_value_forCharacterRange_ >> m.mock()
         mark = mark_range(ak.NSBackgroundColorAttributeName, ANY, ANY)
         expect(mark).count(c.count)
     with m:
         count = finder.mark_occurrences(c.options.find_text, c.allow_regex)
         eq_(count, c.count)