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

Side by Side Diff: tests/test_parser.py

Issue 29880577: Issue 6877 - Only parse headers in the first line of the filter list (Closed)
Patch Set: Initial Created Sept. 14, 2018, 4:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # This file is part of Adblock Plus <https://adblockplus.org/>, 1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 assert line.target == 'foo:bar/baz.txt' 153 assert line.target == 'foo:bar/baz.txt'
154 154
155 155
156 def test_parse_bad_instruction(): 156 def test_parse_bad_instruction():
157 with pytest.raises(ParseError): 157 with pytest.raises(ParseError):
158 parse_line('%foo bar%') 158 parse_line('%foo bar%')
159 159
160 160
161 def test_parse_bad_header(): 161 def test_parse_bad_header():
162 with pytest.raises(ParseError): 162 with pytest.raises(ParseError):
163 parse_line('[Adblock 1.1]') 163 parse_line('[Adblock 1.1]', mode='start')
164 164
165 165
166 def test_parse_filterlist(): 166 def test_parse_filterlist():
167 result = parse_filterlist(['[Adblock Plus 1.1]', 167 result = parse_filterlist(['[Adblock Plus 1.1]',
168 '! Homepage : http://aaa.com/b', 168 '! Homepage : http://aaa.com/b',
169 '||example.com^', 169 '||example.com^',
170 '! Checksum: OaopkIiiAl77sSHk/VAWDA', 170 '! Checksum: OaopkIiiAl77sSHk/VAWDA',
171 '! Note: bla bla']) 171 '! Note: bla bla'])
172 172
173 assert next(result) == Header('Adblock Plus 1.1') 173 assert next(result) == Header('Adblock Plus 1.1')
174 assert next(result) == Metadata('Homepage', 'http://aaa.com/b') 174 assert next(result) == Metadata('Homepage', 'http://aaa.com/b')
175 assert next(result).type == 'filter' 175 assert next(result).type == 'filter'
176 assert next(result) == Metadata('Checksum', 'OaopkIiiAl77sSHk/VAWDA') 176 assert next(result) == Metadata('Checksum', 'OaopkIiiAl77sSHk/VAWDA')
177 assert next(result).type == 'comment' 177 assert next(result).type == 'comment'
178 178
179 with pytest.raises(StopIteration): 179 with pytest.raises(StopIteration):
180 next(result) 180 next(result)
181 181
182 182
183 def test_exception_timing(): 183 def test_exception_timing():
184 result = parse_filterlist(['! good line', '%bad line%']) 184 result = parse_filterlist(['! good line', '%bad line%'])
185 assert next(result) == Comment('good line') 185 assert next(result) == Comment('good line')
186 with pytest.raises(ParseError): 186 with pytest.raises(ParseError):
187 next(result) 187 next(result)
188 188
189 189
190 def test_parse_line_bytes(): 190 def test_parse_line_bytes():
191 line = parse_line(b'! \xc3\xbc') 191 line = parse_line(b'! \xc3\xbc')
192 assert line.text == '\xfc' 192 assert line.text == '\xfc'
OLDNEW
« abp/filters/parser.py ('K') | « abp/filters/rpy.py ('k') | tests/test_rpy.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld