示例#1
0
def test_fuzzy_no_prefix():
    # search by distance, no common prefix with any command
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    matches = app.get_fuzzy_matches('uesr')
    assert matches == ['user']
示例#2
0
def test_fuzzy_no_prefix():
    # search by distance, no common prefix with any command
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    matches = app.get_fuzzy_matches('uesr')
    assert matches == ['user']
示例#3
0
def test_fuzzy_same_distance():
    # searched string has the same distance to all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    for cmd in cmd_mgr.commands.keys():
        assert damerau_levenshtein('node', cmd, COST) == 8
    matches = app.get_fuzzy_matches('node')
    assert matches == ['complete', 'help', 'user']
示例#4
0
def test_fuzzy_common_prefix():
    # searched string is a prefix of all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.commands = {}
    cmd_mgr.add_command('user list', utils.TestCommand)
    cmd_mgr.add_command('user show', utils.TestCommand)
    matches = app.get_fuzzy_matches('user')
    assert matches == ['user list', 'user show']
示例#5
0
def test_fuzzy_same_distance():
    # searched string has the same distance to all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    for cmd in cmd_mgr.commands.keys():
        assert damerau_levenshtein('node', cmd, COST) == 8
    matches = app.get_fuzzy_matches('node')
    assert matches == ['complete', 'help', 'user']
示例#6
0
def test_fuzzy_common_prefix():
    # searched string is a prefix of all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.commands = {}
    cmd_mgr.add_command('user list', utils.TestCommand)
    cmd_mgr.add_command('user show', utils.TestCommand)
    matches = app.get_fuzzy_matches('user')
    assert matches == ['user list', 'user show']
示例#7
0
def test_fuzzy_no_commands():
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.commands = {}
    matches = app.get_fuzzy_matches('foo')
    assert matches == []
示例#8
0
def test_fuzzy_no_commands():
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.commands = {}
    matches = app.get_fuzzy_matches('foo')
    assert matches == []