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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 postInit(filter); | 176 postInit(filter); |
177 let result = serializeFilter(filter); | 177 let result = serializeFilter(filter); |
178 test.equal(result.sort().join("\n"), expected.sort().join("\n"), text); | 178 test.equal(result.sort().join("\n"), expected.sort().join("\n"), text); |
179 | 179 |
180 // Test round-trip | 180 // Test round-trip |
181 let filter2; | 181 let filter2; |
182 let buffer = []; | 182 let buffer = []; |
183 filter.serialize(buffer); | 183 filter.serialize(buffer); |
184 if (buffer.length) | 184 if (buffer.length) |
185 { | 185 { |
186 let map = Object.create(null); | 186 let map = new Map(); |
187 for (let line of buffer.slice(1)) | 187 for (let line of buffer.slice(1)) |
188 { | 188 { |
189 if (/(.*?)=(.*)/.test(line)) | 189 if (/(.*?)=(.*)/.test(line)) |
190 map[RegExp.$1] = RegExp.$2; | 190 map.set(RegExp.$1, RegExp.$2); |
191 } | 191 } |
192 filter2 = Filter.fromObject(map); | 192 filter2 = Filter.fromMap(map); |
193 } | 193 } |
194 else | 194 else |
195 filter2 = Filter.fromText(filter.text); | 195 filter2 = Filter.fromText(filter.text); |
196 | 196 |
197 test.equal(serializeFilter(filter).join("\n"), serializeFilter(filter2).join("
\n"), text + " deserialization"); | 197 test.equal(serializeFilter(filter).join("\n"), serializeFilter(filter2).join("
\n"), text + " deserialization"); |
198 } | 198 } |
199 | 199 |
200 exports.testFilterClassDefinitions = function(test) | 200 exports.testFilterClassDefinitions = function(test) |
201 { | 201 { |
202 test.equal(typeof Filter, "function", "typeof Filter"); | 202 test.equal(typeof Filter, "function", "typeof Filter"); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"), | 541 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"), |
542 "http://content.server/file/foo.txt/disable" | 542 "http://content.server/file/foo.txt/disable" |
543 ); | 543 ); |
544 test.equal( | 544 test.equal( |
545 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"), | 545 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"), |
546 "http://example.com/file/foo.txt/disable" | 546 "http://example.com/file/foo.txt/disable" |
547 ); | 547 ); |
548 | 548 |
549 test.done(); | 549 test.done(); |
550 }; | 550 }; |
OLD | NEW |