From 4d358c49fbeafe504cc7b9a8b66ea572c8cbb0ee Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 15 Dec 2017 07:20:07 +1300 Subject: WIP: autocompletion --- test/mitmproxy/test_command.py | 18 +++++++++++-- test/mitmproxy/tools/console/test_commander.py | 35 ++++++++++++++++---------- 2 files changed, 38 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index 5218042c..b4711236 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -66,8 +66,22 @@ class TestCommand: def test_parse_partial(self): tests = [ - ["foo bar", [("foo", command.Cmd), ("bar", str)]], - ["foo 'bar", [("foo", command.Cmd), ("'bar", str)]], + [ + "foo bar", + [ + command.ParseResult(value = "foo", type = command.Cmd), + command.ParseResult(value = "bar", type = str) + ], + ], + [ + "foo 'bar", + [ + command.ParseResult(value = "foo", type = command.Cmd), + command.ParseResult(value = "'bar", type = str) + ] + ], + ["a", [command.ParseResult(value = "a", type = command.Cmd)]], + ["", [command.ParseResult(value = "", type = command.Cmd)]], ] with taddons.context() as tctx: cm = command.CommandManager(tctx.master) diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index fdf54897..9ef4a318 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -1,5 +1,5 @@ - from mitmproxy.tools.console.commander import commander +from mitmproxy.test import taddons class TestCommandBuffer: @@ -13,12 +13,13 @@ class TestCommandBuffer: [("123", 2), ("13", 1)], [("123", 0), ("123", 0)], ] - for start, output in tests: - cb = commander.CommandBuffer() - cb.buf, cb.cursor = start[0], start[1] - cb.backspace() - assert cb.buf == output[0] - assert cb.cursor == output[1] + with taddons.context() as tctx: + for start, output in tests: + cb = commander.CommandBuffer(tctx.master) + cb.buf, cb.cursor = start[0], start[1] + cb.backspace() + assert cb.buf == output[0] + assert cb.cursor == output[1] def test_insert(self): tests = [ @@ -26,9 +27,17 @@ class TestCommandBuffer: [("a", 0), ("xa", 1)], [("xa", 2), ("xax", 3)], ] - for start, output in tests: - cb = commander.CommandBuffer() - cb.buf, cb.cursor = start[0], start[1] - cb.insert("x") - assert cb.buf == output[0] - assert cb.cursor == output[1] + with taddons.context() as tctx: + for start, output in tests: + cb = commander.CommandBuffer(tctx.master) + cb.buf, cb.cursor = start[0], start[1] + cb.insert("x") + assert cb.buf == output[0] + assert cb.cursor == output[1] + + def test_cycle_completion(self): + with taddons.context() as tctx: + cb = commander.CommandBuffer(tctx.master) + cb.buf = "foo bar" + cb.cursor = len(cb.buf) + cb.cycle_completion() -- cgit v1.2.3