From 7daeb34d4d06f38e1b0e99684fcd5ff8a2ae1e00 Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Tue, 28 Feb 2012 13:21:01 +0000 Subject: [PATCH] Implement onlyinclude transformer. 254 tests passing. --- tests/parser/dumpGrepper.js | 19 +++++++++++++------ tests/parser/parserTests.js | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/parser/dumpGrepper.js b/tests/parser/dumpGrepper.js index f5464863d2..3fa9bea225 100644 --- a/tests/parser/dumpGrepper.js +++ b/tests/parser/dumpGrepper.js @@ -1,6 +1,7 @@ var dumpReader = require('./dumpReader.js'), events = require('events'), - optimist = require('optimist'); + optimist = require('optimist'), + colors = require('colors'); function DumpGrepper ( regexp ) { // inherit from EventEmitter @@ -16,7 +17,7 @@ DumpGrepper.prototype.grepRev = function ( revision ) { if ( bits.length > 1 ) { this.emit( 'match', revision, bits ); } -} +}; module.exports.DumpGrepper = DumpGrepper; @@ -34,14 +35,20 @@ if (module === require.main) { flags += 'i'; } + var re = new RegExp( '(' + argv._[0] + ')', flags ); + var reader = new dumpReader.DumpReader(), - grepper = new DumpGrepper( new RegExp( '(' + argv._[0] + ')', flags ) ); + grepper = new DumpGrepper( re ); reader.on( 'revision', grepper.grepRev.bind( grepper ) ); grepper.on( 'match', function ( revision, bits ) { - console - console.log( 'Match:' + revision.page.title ) - console.log( bits.map( function ( s ) { return s.substr(0, 40) } ) ); + console.log( 'Match:' + revision.page.title ); + for ( var i = 0, l = bits.length; i < l-1; i++ ) { + var m = bits[i+1].match( re )[0]; + console.log( 'm: ' + m ); + console.log( bits[i].substr(-40) + m.green + bits[i+1].substr( m.length, 40 ) ); + } + //console.log( bits.map( function ( s ) { return s.substr(0, 40) } ) ); } ); process.stdin.setEncoding('utf8'); process.stdin.on('data', reader.push.bind(reader) ); diff --git a/tests/parser/parserTests.js b/tests/parser/parserTests.js index 4c8259eccc..b344df86a9 100644 --- a/tests/parser/parserTests.js +++ b/tests/parser/parserTests.js @@ -334,7 +334,8 @@ ParserTests.prototype.normalizeHTML = function (source) { ParserTests.prototype.normalizeOut = function ( out ) { // TODO: Do not strip newlines in pre and nowiki blocks! return out.replace(/[\r\n]| data-mw-[a-zA-Z-]+="[^">]*"/g, '') - .replace(/\n?/gm, ''); + .replace(/\n?/gm, '') + .replace(/<\/?meta[^>]*>/g, ''); }; ParserTests.prototype.formatHTML = function ( source ) {