def test(c): def end(): with m: doc.reload_document() eq_(doc.text, text) text = "edit" config = " ".join("project" for x in c.view_state) with make_file(content="disk") as path, test_app(config) as app: if c.url_is_none: path = "not-saved" elif not c.exists: path += "-not-found" m = Mocker() call_later = m.replace(mod, "call_later") doc = TextDocument(app, path) reset_text_attributes = m.method(doc.reset_text_attributes) doc.text = text if c.url_is_none or not c.exists: return end() undo = doc.undo_manager = m.mock(UndoManager) if not c.read2_success: os.remove(path) os.mkdir(path) return end() text = "disk" tv = m.mock(TextView) for i, text_view_exists in enumerate(c.view_state): project = app.windows[0].projects[i] with m.off_the_record(): editor = Editor(project, document=doc) editor.text_view = (tv if text_view_exists else None) project.editors.append(editor) reset_text_attributes() if not any(c.view_state): # TODO reload without undo #doc_ts.replaceCharactersInRange_withString_(range, text) undo.removeAllActions() return end() range = fn.NSRange(0, 4) tv.shouldChangeTextInRange_replacementString_(range, text) >> True # TODO get edit_state of each document view # TODO diff the two text blocks and change chunks of text # throughout the document (in a single undo group if possible) # also adjust edit states if possible # see http://www.python.org/doc/2.5.2/lib/module-difflib.html #doc_ts.replaceCharactersInRange_withString_(range, text) tv.didChangeText() tv.breakUndoCoalescing() # TODO restore edit states # HACK use timed invocation to allow didChangeText notification # to update change count before _clearUndo is invoked call_later(0, doc.clear_dirty) tv.select((0, 0)) reset_text_attributes() m.method(doc.update_syntaxer)() end()
def test(app, c): m = Mocker() doc = m.mock(TextDocument) project = app.windows[0].projects[0] with m.off_the_record(): dv = Editor(project, document=doc) m.property(dv, "soft_wrap") m.property(dv, "file_path") doc.updates_path_on_file_move >> True if c.tv_is_none: if c.set_state: dv.edit_state = state = dict(key="value") else: state = {} state["soft_wrap"] = const.WRAP_NONE else: dv.text_view = m.mock(ak.NSTextView) dv.scroll_view = m.mock(ak.NSScrollView) sel = m.mock(fn.NSRange) sp = m.mock(fn.NSPoint) dv.text_view.selectedRange() >> sel dv.scroll_view.documentVisibleRect().origin >> sp sel.location >> "<sel.location>" sel.length >> "<sel.length>" sp.x >> "<sp.x>" sp.y >> "<sp.y>" dv.soft_wrap >> c.soft_wrap state = dict( selection=["<sel.location>", "<sel.length>"], scrollpoint=["<sp.x>", "<sp.y>"], soft_wrap=c.soft_wrap, ) (dv.file_path << "<path>").count(1, 2) state["path"] = "<path>" with m: result = dv.edit_state eq_(result, state) if c.tv_is_none and c.set_state: assert result is not state, \ "identity check should fail: must be a new (mutable) dict"