aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2017-12-14 12:24:46 +1300
committerAldo Cortesi <aldo@corte.si>2017-12-15 10:07:47 +1300
commit04e19f91716b9de6ec26df1478146eaedd47a329 (patch)
tree03575fea9a90faef70ee23f000ddec6f5e1d7a9c /test
parent21324086c37dcf55d38562081ae9fc8f5e4852b1 (diff)
downloadmitmproxy-04e19f91716b9de6ec26df1478146eaedd47a329.tar.gz
mitmproxy-04e19f91716b9de6ec26df1478146eaedd47a329.tar.bz2
mitmproxy-04e19f91716b9de6ec26df1478146eaedd47a329.zip
Introduce a custom widget for command editing
The builtin urwid.Edit widget is not sufficiently flexible for what we want to do.
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/tools/console/test_commander.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py
new file mode 100644
index 00000000..b1f23df4
--- /dev/null
+++ b/test/mitmproxy/tools/console/test_commander.py
@@ -0,0 +1,37 @@
+
+from mitmproxy.tools.console.commander import commander
+
+
+class TestCommandBuffer:
+
+ def test_backspace(self):
+ tests = [
+ [("", 0), ("", 0)],
+ [("1", 0), ("1", 0)],
+ [("1", 1), ("", 0)],
+ [("123", 3), ("12", 2)],
+ [("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]
+
+ def test_insert(self):
+ tests = [
+ [("", 0), ("x", 1)],
+ [("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]
+
+
+