def test(c): m = Mocker() beep = m.replace(mod, "beep") @command( arg_parser=CommandParser( Choice(("selection", True), ("all", False)), Choice(("no", False), ("yes", True)), Regex("sort_regex", True), ) ) def cmd(editor, args): raise NotImplementedError("should not get here") @command( arg_parser=CommandParser(Regex("search_pattern", replace=c.replace), Choice(("yep", False), ("yes", True))), lookup_with_arg_parser=True, ) def search(editor, args): raise NotImplementedError("should not get here") @command(arg_parser=CommandParser(IllBehaved("bang"))) def ill(editor, args): raise NotImplementedError("should not get here") bar = CommandTester(cmd, search, ill) with m: eq_(bar.get_placeholder(c.text), c.expect)
def test(text, output): view = CommandView() bar = CommandTester(cmd, count, ill, command_view=view, output=True) bar.show_help(text) eq_(bar.output, output)
def test( text, command_key, *, new_text=NA, complete=None, default_complete=None, new_complete=None, new_default_complete=None, completions_select_range=None, completions_title=None, sel=None, new_sel=None, expect=True, has_command=True, output="", new_output=NA ): view = CommandView() bar = CommandTester(cmd, count, ill, textview=object, command_view=view) bar.activate(text) if complete: view.completions.items = complete if default_complete: print("selected completion:", complete.index(default_complete)) view.completions.select(complete.index(default_complete)) view.command_text = text if sel: view.command_text_selected_range = sel if completions_select_range: view.completions.select_range = completions_select_range if output: view.message(output) result = bar.on_key_command(command_key, view) eq_(result, expect) eq_(view.completions.items, (complete or []) if new_complete is None else new_complete) eq_(view.completions.selected_item, new_default_complete) eq_(view.completions.title, completions_title) eq_(view.command_text, text if new_text is NA else new_text) eq_(view.output_text, output if new_output is NA else new_output) if sel is not None or new_sel is not None: eq_(view.command_text_selected_range, sel if new_sel is None else new_sel) if complete == new_complete: eq_(view.completions.select_range, sel if new_sel is None else new_sel) else: eq_(view.completions.select_range, None) eq_(view.command, bar.bar if has_command else None)
def test(command, expected): m = Mocker() tv = FakeTextView(TEXT) do = CommandTester(mod.sort_lines, textview=tv) with m: do(command) eq_(sort_result(tv.text), expected, TEXT)
def test(c): m = Mocker() beep = m.replace(ak, 'NSBeep') @command(arg_parser=CommandParser( Choice(('selection', True), ('all', False)), Choice(('forward', False), ('reverse xyz', True), name='reverse'), Regex('sort_regex', True), )) def cmd(textview, sender, args): raise NotImplementedError("should not get here") @command(arg_parser=CommandParser( Regex('search_pattern'), Choice(('yes', True), ('no', False)), ), lookup_with_arg_parser=True) def search(textview, sender, args): raise NotImplementedError("should not get here") bar = CommandTester(cmd, search) with m: eq_(bar.get_completions(c.text), c.expect)
def test(c): m = Mocker() beep = m.replace(ak, 'NSBeep') @command(arg_parser=CommandParser( Choice(('selection', True), ('all', False)), Choice(('no', False), ('yes', True)), Regex('sort_regex', True), )) def cmd(textview, sender, args): raise NotImplementedError("should not get here") @command(arg_parser=CommandParser( Regex('search_pattern', replace=c.replace), Choice(('yep', False), ('yes', True)), VarArgs("args", placeholder="..."), ), lookup_with_arg_parser=True) def search(textview, sender, args): raise NotImplementedError("should not get here") bar = CommandTester(cmd, search) with m: eq_(bar.get_placeholder(c.text), c.expect)
def test(text, expect, select=None, start=None): m = Mocker() beep = m.replace(mod, "beep") @command( arg_parser=CommandParser( Choice(("selection", True), ("all", False)), Choice(("forward", False), ("reverse xyz", True), name="reverse"), Regex("sort_regex", True), ) ) def cmd(editor, args): raise NotImplementedError("should not get here") @command( arg_parser=CommandParser(Regex("search_pattern"), Choice(("yes", True), ("no", False))), lookup_with_arg_parser=True, ) def search(editor, args): raise NotImplementedError("should not get here") @command(arg_parser=CommandParser(Int("number")), is_enabled=lambda *a: False) def count(editor, args): raise NotImplementedError("should not get here") @command(arg_parser=CommandParser(HexDigit("hex"))) def hex(editor, args): raise NotImplementedError("should not get here") @command(arg_parser=CommandParser(IllBehaved("bang"))) def ill(editor, args): raise NotImplementedError("should not get here") bar = CommandTester(cmd, search, count, hex, ill, textview=object) with m: result = bar.get_completions(text) eq_(result, (expect, select)) if start is not None: eq_([w.start for w in result[0]], [start] * len(result[0]))