Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: tests/test_parser.py

Issue 29880577: Issue 6877 - Only parse headers in the first line of the filter list (Closed)
Patch Set: Correct behavior, add comments, improve naming, add tests Created Sept. 18, 2018, 12:37 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/test_parser.py
===================================================================
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -153,31 +153,63 @@
assert line.target == 'foo:bar/baz.txt'
def test_parse_bad_instruction():
with pytest.raises(ParseError):
parse_line('%foo bar%')
-def test_parse_bad_header():
+def test_parse_start():
+ # Header-line lines are headers.
+ assert parse_line('[Adblock Plus 1.1]', mode='start').type == 'header'
+ # But space is not allowed in headers.
+ assert parse_line(' [Adblock Plus 1.1]', mode='start').type == 'filter'
+ assert parse_line('[Adblock Plus 1.1] ', mode='start').type == 'filter'
+
with pytest.raises(ParseError):
- parse_line('[Adblock 1.1]')
+ # Invalid headers cause exceptions.
+ parse_line('[Adblock 1.1]', mode='start')
+
+ # Metadata-like lines are metadata.
+ assert parse_line('! Foo: bar', mode='metadata').type == 'metadata'
+
+
+def test_parse_metadata():
+ # Header-like lines are just filters.
+ assert parse_line('[Adblock 1.1]', mode='metadata').type == 'filter'
+ # Metadata-like lines are metadata.
+ assert parse_line('! Foo: bar', mode='metadata').type == 'metadata'
+
+
+def test_parse_body():
+ # Header-like lines are just filters.
+ assert parse_line('[Adblock 1.1]', mode='body').type == 'filter'
+ # Metadata-like lines are comments.
+ assert parse_line('! Foo: bar', mode='body').type == 'comment'
+ # But there's an exception for the checksum.
+ assert parse_line('! Checksum: 42', mode='body').type == 'metadata'
+
+
+def test_parse_invalid_mode():
+ with pytest.raises(ValueError):
+ parse_line('', mode='nonsense')
def test_parse_filterlist():
result = parse_filterlist(['[Adblock Plus 1.1]',
- '! Last modified: 26 Jul 2018 02:10 UTC',
+ ' ! Last modified: 26 Jul 2018 02:10 UTC ',
'! Homepage : http://aaa.com/b',
'||example.com^',
'! Checksum: OaopkIiiAl77sSHk/VAWDA',
'! Note: bla bla'])
assert next(result) == Header('Adblock Plus 1.1')
- assert next(result) == Metadata('Last modified', '26 Jul 2018 02:10 UTC')
+ # Check that trailing space is not stripped (like in ABP).
+ assert next(result) == Metadata('Last modified', '26 Jul 2018 02:10 UTC ')
assert next(result) == Metadata('Homepage', 'http://aaa.com/b')
assert next(result).type == 'filter'
assert next(result) == Metadata('Checksum', 'OaopkIiiAl77sSHk/VAWDA')
assert next(result).type == 'comment'
with pytest.raises(StopIteration):
next(result)

Powered by Google App Engine
This is Rietveld