Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/node_modules/htmlparser2/tests/test-helper.js

Issue 125733002: Add vulcanize to tools. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/node_modules/htmlparser2/tests/test-helper.js
diff --git a/tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/node_modules/htmlparser2/tests/test-helper.js b/tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/node_modules/htmlparser2/tests/test-helper.js
new file mode 100644
index 0000000000000000000000000000000000000000..ccf98041fa3aa318d73ded74816457e6e144d63d
--- /dev/null
+++ b/tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/node_modules/htmlparser2/tests/test-helper.js
@@ -0,0 +1,38 @@
+var htmlparser = require(".."),
+ Parser = htmlparser.Parser,
+ CollectingHandler = htmlparser.CollectingHandler,
+ chunkSize = 5;
+
+exports.writeToParser = function(handler, options, data){
+ var parser = new Parser(handler, options);
+ //first, try to run the test via chunks
+ for(var i = 0; i < data.length; i += chunkSize){
+ parser.write(data.substr(i, chunkSize));
+ }
+ parser.end();
+ //then parse everything
+ parser.parseComplete(data);
+};
+
+//returns a tree structure
+exports.getEventCollector = function(cb){
+ var handler = new CollectingHandler({onerror: cb, onend: function(){
+ cb(null, handler.events
+ .reduce(function(events, arr){
+ if(arr[0] === "onerror" || arr[0] === "onend");
+ else if(arr[0] === "ontext" && events.length && events[events.length-1].event === "text"){
+ events[events.length-1].data[0] += arr[1];
+ } else {
+ events.push({
+ event: arr[0].slice(2),
+ data: arr.slice(1)
+ });
+ }
+
+ return events;
+ }, [])
+ );
+ }});
+
+ return handler;
+};

Powered by Google App Engine
This is Rietveld 408576698