Ejemplo n.º 1
0
def test_CommandManager_load_shortcuts():
    from editxt.config import config_schema

    @command
    def doc(editor, opts):
        pass

    shorts = config_schema()["shortcuts"]
    menu = const.Constant("menu")
    expect = []
    tags = {doc: doc.name}
    key = lambda kv: kv[1]["rank"].default
    for i, (hotkey, value) in enumerate(sorted(shorts.items(), key=key)):
        hkey = mod.parse_hotkey(hotkey)
        title = value["name"].default
        expect.append((menu, title) + hkey)
        tags[title] = i
    items = []

    def add_menu_item(menu, title, hotkey, modifiers):
        items.append((menu, title, hotkey, modifiers))
        return tags[title]

    with test_app() as app:
        ctl = CommandManager("<history>", app=app)
        ctl.add_command(doc, None, menu)
        ctl.add_menu_item = add_menu_item
        ctl.load_shortcuts(menu)
        eq_(items, expect)
        eq_(set(ctl.commands), set(tags.values()))
Ejemplo n.º 2
0
def test_config_shortcuts():
    from editxt.config import config_schema

    eq_(
        {
            f["command"].default
            for f in config_schema()["shortcuts"].values()
            if f["command"].default.startswith(" doc ")
        },
        {" doc  previous", " doc  next", " doc  up", " doc  down"},
    )