diff options
author | Maximilian Hils <git@maximilianhils.com> | 2019-11-19 18:14:00 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2019-11-19 18:21:14 +0100 |
commit | 76e648410745c61f7a659e864230b6154dc43ced (patch) | |
tree | 3c17752752f382d9ce22bfc668817ec46a6caafe /test | |
parent | 74f5fa6a7736f116416c242b159e6b0525e6fe5b (diff) | |
download | mitmproxy-76e648410745c61f7a659e864230b6154dc43ced.tar.gz mitmproxy-76e648410745c61f7a659e864230b6154dc43ced.tar.bz2 mitmproxy-76e648410745c61f7a659e864230b6154dc43ced.zip |
fix lexing, sort of
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/test_command_lexer.py | 38 | ||||
-rw-r--r-- | test/mitmproxy/tools/console/test_commander.py | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/test/mitmproxy/test_command_lexer.py b/test/mitmproxy/test_command_lexer.py new file mode 100644 index 00000000..3f009f88 --- /dev/null +++ b/test/mitmproxy/test_command_lexer.py @@ -0,0 +1,38 @@ +import pyparsing +import pytest + +from mitmproxy import command_lexer + + +@pytest.mark.parametrize( + "test_input,valid", [ + ("'foo'", True), + ('"foo"', True), + ("'foo' bar'", False), + ("'foo\\' bar'", True), + ("'foo' 'bar'", False), + ("'foo'x", False), + ('''"foo ''', True), + ('''"foo 'bar' ''', True), + ] +) +def test_partial_quoted_string(test_input, valid): + if valid: + assert command_lexer.PartialQuotedString.parseString(test_input, parseAll=True)[0] == test_input + else: + with pytest.raises(pyparsing.ParseException): + command_lexer.PartialQuotedString.parseString(test_input, parseAll=True) + + +@pytest.mark.parametrize( + "test_input,expected", [ + ("'foo'", ["'foo'"]), + ('"foo"', ['"foo"']), + ("'foo' 'bar'", ["'foo'", ' ', "'bar'"]), + ("'foo'x", ["'foo'", 'x']), + ('''"foo''', ['"foo']), + ('''"foo 'bar' ''', ['''"foo 'bar' ''']), + ] +) +def test_expr(test_input, expected): + assert list(command_lexer.expr.parseString(test_input, parseAll=True)) == expected diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index 6b42de76..060e4b9b 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -269,7 +269,7 @@ class TestCommandBuffer: cb.text = "foo" assert cb.render() - cb.text = 'set view_filter=~bq test' + cb.text = 'set view_filter ~bq test' ret = cb.render() assert ret[0] == ('commander_command', 'set') assert ret[1] == ('text', ' ') |