def test_multichar_nmap(caplog): caplog.set_level(logging.DEBUG) setMode(Mode.normal) expected = Motion.right.value * 2 assert handleInput("ll") == expected nmap("x", "ll") assert handleInput("x") == expected, "multichar nmap doesn't work"
def test_basic_nmap(caplog): caplog.set_level(logging.DEBUG) setMode(Mode.normal) expected = Motion.right.value assert handleInput("l") == expected nmap("x", "l") assert handleInput("x") == expected, "basic nmap doesn't work"
def test_disable(): assert getMode() == Mode.normal, "Univisal not set up for test" handleInput(":disable") assert getMode() == Mode.disabled, "Disable does not change mode" # TODO: Move mode tests like this to separte test. assert handleInput('l') == 'l', "Disabled univisal does not return normal key" assert handleInput(Keys.esc.value) == ("<esc>"), \ "Disabled univisal does not return special keys"
def test_imap_to_esc_one_at_a_time(caplog): caplog.set_level(logging.DEBUG) setMode(Mode.insert) expected = "<bs>" imap("jk", "<esc>") handleInput("j") assert handleInput("k") == expected, "one key at a time doesn't trigger map" assert isMode(Mode.normal) imap("jk")
def test_handleInput_while_expecting_searchletter(): inpt = "letter to search for" expected = "handle search letter" errMsg = "handleInput doesn't handle search letter when expecting one" with unittest.mock.patch( 'univisal.handleInput.handleExpectedSearchLetter', return_value=expected): assert not handleInput.handleInput(inpt) == expected, "testing setup error" model.expecting_search_letter = True assert handleInput.handleInput(inpt) == expected, errMsg
def test_handleInput_with_commandlike_input(): inpt = ":commandlike" expected = "command called" errMsg = "commandlike inputs don't call command handler" with unittest.mock.patch( 'univisal.handleInput.handleUnivisalCommand', return_value=expected): assert handleInput.handleInput(inpt) == expected, errMsg
def test_swallow_unused_normal(opt, expected, msg): from tests.mock_setup import init_univisal from univisal.handleInput import handleInput from univisal.handleKey import handleVimInputKey init_univisal() config.configStore = {"swallow_unused_normal_keys": opt} setMode(Mode.normal) # Test handling the single key, then the whole input to confirm. result = handleVimInputKey("m") assert result == expected, msg + " after handleSingleInputKey" result = handleInput("m") assert result == expected, msg + " after handleInput"
def translate_keys(keys): """ Pass in a string if no special keys, else pass in a list. """ out = [] for char in keys: handleResult = handleInput(char) out.append(handleResult) out = trimNop(out) out = ''.join(out) # Simulate sending the backspaces. Do with string, not array, to ensure # normal commands not affected. while Keys.backspace.value in out: # need to iteratively replace <bs> with removed char out = translate_backspace(out) out = trimJoinChar(out) return ''.join(out)
def test_getConfigDir(): from univisal.config import getConfigDir assert handleInput(':getConfigDir') == getConfigDir(), "getConfigDir doesn't return path"
def test_enable(): handleInput(":disable") assert getMode() == Mode.disabled, "Disable does not change mode" handleInput(":enable") assert getMode() == Mode.normal, "Enable does not change mode to normal" assert handleInput('l') == Motion.right.value, "re-enabled univisal does not return motion"
def test_handleInput_gets_fallback(fallbackMock): with unittest.mock.patch('univisal.handleInput.handleInputUnsafe', side_effect=raiseError): result = handleInput.handleInput("test") error_msg = "HandleInput doesn't return fallback if error encountered while handling." assert result == fallbackMock(), error_msg
def test_handleInput_while_disabled(): test = "input key" errMsg = "HandleInput doesn't return input when univisal disabled" setMode(Mode.disabled) assert handleInput.handleInput(test) == test, errMsg
def test_basic_motions(motion, expected): setMode(Mode.normal) result = handleInput(motion) assert result == expected.value, "{} returns wrong thing".format(motion)
def test_escape(): setMode(Mode.insert) assert getMode() == Mode.insert result = handleInput(Keys.esc.value) assert getMode() == Mode.normal assert result == Keys.nop.value
def handleSequence(keys): for key in keys: result = handleInput(key) return result