Browse files

refactor test. dont use html prettifier.

  • Loading branch information...
1 parent 1bf3dc4 commit 75053dd0c0446955daa85adb405fbccbf0004f27 @chjj committed Mar 11, 2012
Showing with 7 additions and 116 deletions.
  1. +0 −4 test/browser/test.js
  2. +7 −112 test/index.js
View
4 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) {
View
119 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 = /<!(\d+)%*\/>/g
- , wrap = /([ \t]*)<p>([\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 '<!' + (hash.push(element) - 1)
- + (Array(element.length - 3).join('%')) + '/>';
- });
-
- // 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 + '<p>\n' + text + '\n' + $1 + '</p>';
- });
-
- 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;
}

0 comments on commit 75053dd

Please sign in to comment.