aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorHenrique <typoon@gmail.com>2019-11-12 22:09:04 -0500
committerHenrique <typoon@gmail.com>2019-11-12 22:09:04 -0500
commit578eb7239cf073ee9dd526542ca19ff6c23ae61c (patch)
tree729a7b38efdb7774669f79af1f026e39314de223 /test
parent55239a8a47746cca838f558ea4140d2187dfc8db (diff)
downloadmitmproxy-578eb7239cf073ee9dd526542ca19ff6c23ae61c.tar.gz
mitmproxy-578eb7239cf073ee9dd526542ca19ff6c23ae61c.tar.bz2
mitmproxy-578eb7239cf073ee9dd526542ca19ff6c23ae61c.zip
Tests for the new lexer
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/test_lexer.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/mitmproxy/test_lexer.py b/test/mitmproxy/test_lexer.py
new file mode 100644
index 00000000..c8b30fc6
--- /dev/null
+++ b/test/mitmproxy/test_lexer.py
@@ -0,0 +1,64 @@
+from mitmproxy import lexer
+import pytest
+
+
+class TestScripts:
+
+ def test_simple(self):
+
+ cases = [
+ {
+ "text": r'abc',
+ "result": ['abc']
+ },
+ {
+ "text": r'"Hello \" Double Quotes"',
+ "result": ['"Hello \\" Double Quotes"']
+ },
+ {
+ "text": r"'Hello \' Single Quotes'",
+ "result": ["'Hello \\' Single Quotes'"]
+ },
+ {
+ "text": r'"\""',
+ "result": ['"\\""']
+ },
+ {
+ "text": r'abc "def\" \x bla \z \\ \e \ " xpto',
+ "result": ['abc', '"def\\" \\x bla \\z \\\\ \\e \\ "', 'xpto']
+ },
+ {
+ "text": r'',
+ "result": []
+ },
+ {
+ "text": r' ',
+ "result": []
+ },
+ {
+ "text": r' ',
+ "result": []
+ },
+ {
+ "text": r'Space in the end ',
+ "result": ['Space', 'in', 'the', 'end']
+ },
+ {
+ "text": '\n\n\rHello\n World With Spaces\n\n',
+ "result": ['Hello', 'World', 'With', 'Spaces']
+ },
+ ]
+
+ for t in cases:
+
+ lex = lexer.Lexer(t['text'])
+ tokens = list(lex)
+ result = t['result']
+ assert(tokens == result)
+
+ def test_fail(self):
+ text = r'"should fail with missing closing quote'
+ lex = lexer.Lexer(text)
+ with pytest.raises(ValueError, match="No closing quotation"):
+ assert list(lex)
+