LEFT | RIGHT |
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 Loading... |
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_start(): | 161 def test_parse_start(): |
162 # Header-line lines are headers. | 162 # Header-line lines are headers. |
163 assert parse_line('[Adblock Plus 1.1]', mode='start').type == 'header' | 163 assert parse_line('[Adblock Plus 1.1]', 'start').type == 'header' |
164 # But space is not allowed in headers. | 164 # Even if they have extra characters around. |
165 assert parse_line(' [Adblock Plus 1.1]', mode='start').type == 'filter' | 165 assert parse_line('foo[Adblock Plus 1.1] bar', 'start').type == 'header' |
166 assert parse_line('[Adblock Plus 1.1] ', mode='start').type == 'filter' | 166 |
167 | 167 with pytest.raises(ParseError): |
168 with pytest.raises(ParseError): | 168 # But the inside of the header needs to be right. |
169 # Invalid headers cause exceptions. | 169 parse_line('[Adblock Minus 1.1]', 'start').type |
170 parse_line('[Adblock 1.1]', mode='start') | 170 |
| 171 with pytest.raises(ParseError): |
| 172 # Really right! |
| 173 parse_line('[Adblock 1.1]', 'start') |
171 | 174 |
172 # Metadata-like lines are metadata. | 175 # Metadata-like lines are metadata. |
173 assert parse_line('! Foo: bar', mode='metadata').type == 'metadata' | 176 assert parse_line('! Foo: bar', 'metadata').type == 'metadata' |
174 | 177 |
175 | 178 |
176 def test_parse_metadata(): | 179 def test_parse_metadata(): |
177 # Header-like lines are just filters. | 180 # Header-like lines are just filters. |
178 assert parse_line('[Adblock 1.1]', mode='metadata').type == 'filter' | 181 assert parse_line('[Adblock 1.1]', 'metadata').type == 'filter' |
179 # Metadata-like lines are metadata. | 182 # Metadata-like lines are metadata. |
180 assert parse_line('! Foo: bar', mode='metadata').type == 'metadata' | 183 assert parse_line('! Foo: bar', 'metadata').type == 'metadata' |
181 | 184 |
182 | 185 |
183 def test_parse_body(): | 186 def test_parse_body(): |
184 # Header-like lines are just filters. | 187 # Header-like lines are just filters. |
185 assert parse_line('[Adblock 1.1]', mode='body').type == 'filter' | 188 assert parse_line('[Adblock 1.1]', 'body').type == 'filter' |
186 # Metadata-like lines are comments. | 189 # Metadata-like lines are comments. |
187 assert parse_line('! Foo: bar', mode='body').type == 'comment' | 190 assert parse_line('! Foo: bar', 'body').type == 'comment' |
188 # But there's an exception for the checksum. | 191 # But there's an exception for the checksum. |
189 assert parse_line('! Checksum: 42', mode='body').type == 'metadata' | 192 assert parse_line('! Checksum: 42', 'body').type == 'metadata' |
190 | 193 |
191 | 194 |
192 def test_parse_invalid_mode(): | 195 def test_parse_invalid_position(): |
193 with pytest.raises(ValueError): | 196 with pytest.raises(ValueError): |
194 parse_line('', mode='nonsense') | 197 parse_line('', 'nonsense') |
195 | 198 |
196 | 199 |
197 def test_parse_filterlist(): | 200 def test_parse_filterlist(): |
198 result = parse_filterlist(['[Adblock Plus 1.1]', | 201 result = parse_filterlist(['[Adblock Plus 1.1]', |
199 ' ! Last modified: 26 Jul 2018 02:10 UTC ', | 202 ' ! Last modified: 26 Jul 2018 02:10 UTC ', |
200 '! Homepage : http://aaa.com/b', | 203 '! Homepage : http://aaa.com/b', |
201 '||example.com^', | 204 '||example.com^', |
202 '! Checksum: OaopkIiiAl77sSHk/VAWDA', | 205 '! Checksum: OaopkIiiAl77sSHk/VAWDA', |
203 '! Note: bla bla']) | 206 '! Note: bla bla']) |
204 | 207 |
(...skipping 12 matching lines...) Expand all Loading... |
217 def test_exception_timing(): | 220 def test_exception_timing(): |
218 result = parse_filterlist(['! good line', '%bad line%']) | 221 result = parse_filterlist(['! good line', '%bad line%']) |
219 assert next(result) == Comment('good line') | 222 assert next(result) == Comment('good line') |
220 with pytest.raises(ParseError): | 223 with pytest.raises(ParseError): |
221 next(result) | 224 next(result) |
222 | 225 |
223 | 226 |
224 def test_parse_line_bytes(): | 227 def test_parse_line_bytes(): |
225 line = parse_line(b'! \xc3\xbc') | 228 line = parse_line(b'! \xc3\xbc') |
226 assert line.text == '\xfc' | 229 assert line.text == '\xfc' |
LEFT | RIGHT |