OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 addDefaults(expected); | 189 addDefaults(expected); |
190 | 190 |
191 let filter = Filter.fromText(text); | 191 let filter = Filter.fromText(text); |
192 if (postInit) | 192 if (postInit) |
193 postInit(filter); | 193 postInit(filter); |
194 let result = serializeFilter(filter); | 194 let result = serializeFilter(filter); |
195 test.equal(result.sort().join("\n"), expected.sort().join("\n"), text); | 195 test.equal(result.sort().join("\n"), expected.sort().join("\n"), text); |
196 | 196 |
197 // Test round-trip | 197 // Test round-trip |
198 let filter2; | 198 let filter2; |
199 let buffer = []; | 199 filter2 = Filter.fromText(filter.text); |
200 filter.serialize(buffer); | |
201 if (buffer.length) | |
202 { | |
203 let map = Object.create(null); | |
204 for (let line of buffer.slice(1)) | |
205 { | |
206 if (/(.*?)=(.*)/.test(line)) | |
207 map[RegExp.$1] = RegExp.$2; | |
208 } | |
209 filter2 = Filter.fromObject(map); | |
210 } | |
211 else | |
212 filter2 = Filter.fromText(filter.text); | |
213 | 200 |
214 test.equal(serializeFilter(filter).join("\n"), serializeFilter(filter2).join("
\n"), text + " deserialization"); | 201 test.equal(serializeFilter(filter).join("\n"), serializeFilter(filter2).join("
\n"), text + " deserialization"); |
215 } | 202 } |
216 | 203 |
217 exports.testFilterClassDefinitions = function(test) | 204 exports.testFilterClassDefinitions = function(test) |
218 { | 205 { |
219 test.equal(typeof Filter, "function", "typeof Filter"); | 206 test.equal(typeof Filter, "function", "typeof Filter"); |
220 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter"); | 207 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter"); |
221 test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); | 208 test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); |
222 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); | 209 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 // This compares the references to make sure that both refer to the same | 598 // This compares the references to make sure that both refer to the same |
612 // object (#6815). | 599 // object (#6815). |
613 test.equal(filter1.domains, filter2.domains); | 600 test.equal(filter1.domains, filter2.domains); |
614 | 601 |
615 let filter3 = Filter.fromText("www.example.com##.bar"); | 602 let filter3 = Filter.fromText("www.example.com##.bar"); |
616 | 603 |
617 test.notEqual(filter2.domains, filter3.domains); | 604 test.notEqual(filter2.domains, filter3.domains); |
618 | 605 |
619 test.done(); | 606 test.done(); |
620 }; | 607 }; |
OLD | NEW |