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: Fix header parsing, improve argument naming and documentation Created Sept. 18, 2018, 6:06 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
« no previous file with comments | « abp/filters/rpy.py ('k') | tests/test_rpy.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/test_parser.py
===================================================================
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -153,31 +153,66 @@
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]', 'start').type == 'header'
+ # Even if they have extra characters around.
+ assert parse_line('foo[Adblock Plus 1.1] bar', 'start').type == 'header'
+
+ with pytest.raises(ParseError):
+ # But the inside of the header needs to be right.
+ parse_line('[Adblock Minus 1.1]', 'start').type
+
with pytest.raises(ParseError):
- parse_line('[Adblock 1.1]')
+ # Really right!
+ parse_line('[Adblock 1.1]', 'start')
+
+ # Metadata-like lines are metadata.
+ assert parse_line('! Foo: bar', 'metadata').type == 'metadata'
+
+
+def test_parse_metadata():
+ # Header-like lines are just filters.
+ assert parse_line('[Adblock 1.1]', 'metadata').type == 'filter'
+ # Metadata-like lines are metadata.
+ assert parse_line('! Foo: bar', 'metadata').type == 'metadata'
+
+
+def test_parse_body():
+ # Header-like lines are just filters.
+ assert parse_line('[Adblock 1.1]', 'body').type == 'filter'
+ # Metadata-like lines are comments.
+ assert parse_line('! Foo: bar', 'body').type == 'comment'
+ # But there's an exception for the checksum.
+ assert parse_line('! Checksum: 42', 'body').type == 'metadata'
+
+
+def test_parse_invalid_position():
+ with pytest.raises(ValueError):
+ parse_line('', '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)
« no previous file with comments | « abp/filters/rpy.py ('k') | tests/test_rpy.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld