aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2017-12-15 07:20:07 +1300
committerAldo Cortesi <aldo@corte.si>2017-12-15 10:07:47 +1300
commit4d358c49fbeafe504cc7b9a8b66ea572c8cbb0ee (patch)
tree956c4a44e59f5e4891fa8cbbb63390c254ca87ed /test
parent0cd4a7726892ecda494d94bd12af0094c53a6a85 (diff)
downloadmitmproxy-4d358c49fbeafe504cc7b9a8b66ea572c8cbb0ee.tar.gz
mitmproxy-4d358c49fbeafe504cc7b9a8b66ea572c8cbb0ee.tar.bz2
mitmproxy-4d358c49fbeafe504cc7b9a8b66ea572c8cbb0ee.zip
WIP: autocompletion
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/test_command.py18
-rw-r--r--test/mitmproxy/tools/console/test_commander.py35
2 files changed, 38 insertions, 15 deletions
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()