From 75053dd0c0446955daa85adb405fbccbf0004f27 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 11 Mar 2012 00:45:28 -0600 Subject: [PATCH] refactor test. dont use html prettifier. --- test/browser/test.js | 4 -- test/index.js | 119 +++---------------------------------------- 2 files changed, 7 insertions(+), 116 deletions(-) diff --git a/test/browser/test.js b/test/browser/test.js index c08c865d4c..ebbff43ad3 100644 --- a/test/browser/test.js +++ b/test/browser/test.js @@ -18,10 +18,6 @@ var print = function(text) { var console = { log: print }; -var pretty = function(text) { - return text; -}; - var load = function() {}; Object.keys = Object.keys || function(obj) { diff --git a/test/index.js b/test/index.js index 4fd697e2df..20c903c208 100644 --- a/test/index.js +++ b/test/index.js @@ -71,16 +71,18 @@ main: text = text.substring( Math.max(i - 30, 0), Math.min(i + 30, text.length)); + html = html.substring( Math.max(i - 30, 0), Math.min(i + 30, html.length)); + console.log( '\n#%d. %s failed at offset %d. Near: "%s".\n', i_ + 1, filename, i, text); - console.log('\nGot:\n%s\n', - pretty(text).trim() || text); - console.log('\nExpected:\n%s\n', - pretty(html).trim() || html); + + console.log('\nGot:\n%s\n', text.trim() || text); + console.log('\nExpected:\n%s\n', html.trim() || html); + if (BREAK_ON_ERROR) { break main; } else { @@ -175,114 +177,6 @@ var time = function() { main.bench('marked', marked); }; -/** - * Pretty print HTML - * Copyright (c) 2011, Christopher Jeffrey - */ - -var pretty = (function() { - var indent = function(num) { - return Array((num >= 0 ? num : 0) + 1).join(' '); - }; - - var closing = { - base: true, - link: true, - meta: true, - hr: true, - br: true, - wbr: true, - img: true, - embed: true, - param: true, - source: true, - track: true, - area: true, - col: true, - input: true, - keygen: true, - command: true - }; - - var remove = /<(pre|textarea|title|p|li|a)(?:\s[^>]+)?>[\s\S]+?<\/\1>/g - , replace = //g - , wrap = /([ \t]*)

([\s\S]+?)<\/p>/g; - - return function(str) { - var hash = [] - , out = [] - , cap - , depth = 0 - , text - , full - , tag - , name; - - // temporarily remove elements before - // processing, also remove whitespace - str = str.replace(remove, function(element, name) { - element = element - .replace(/(<[^\/][^>]*>)\s+|\s+(<\/)/g, '$1$2') - .replace(/[\r\n]/g, ''); - return ''; - }); - - // indent elements - str = str - .replace(/(>)\s+|\s+(<)/g, '$1$2') - .replace(/[\r\n]/g, ''); - - while (cap = /^([\s\S]*?)(<([^>]+)>)/.exec(str)) { - str = str.substring(cap[0].length); - text = cap[1]; - full = cap[2]; - tag = cap[3]; - name = tag.split(' ')[0]; - - if (text) { - out.push(indent(depth) + text); - } - - if (name[0] !== '/') { - out.push(indent(depth) + full); - if (!closing[name] - && name[0] !== '!' - && name[0] !== '?' - && tag[tag.length-1] !== '/') { - depth++; - } - } else { - depth--; - out.push(indent(depth) + full); - } - } - str = out.join('\n'); - - // restore the elements to - // their original locations - str = str.replace(replace, function($0, $1) { - return hash[$1]; - }); - - // wrap paragraphs - str = str.replace(wrap, function($0, $1, $2) { - var indent = $1 + ' ' - , text = indent + $2; - - text = text - .replace(/[\t\r\n]+/g, '') - .replace(/(<\/[^>]+>|\/>)(?=\s*<\w)/g, '$1\n' + indent) - .replace(/(.{75,}?\s+(?![^<]+>))/g, '$1\n' + indent) - .replace(/([^<>\n]{50,}?)(<[^<]{15,}>)/g, '$1\n' + indent + '$2'); - - return $1 + '

\n' + text + '\n' + $1 + '

'; - }); - - return str; - }; -})(); - if (!module.parent) { if (~process.argv.indexOf('--bench')) { bench(); @@ -292,6 +186,7 @@ if (!module.parent) { main(); } } else { + main.main = main; main.load = load; module.exports = main; }