Skip to content
Browse files

Merge conflict resolution

  • Loading branch information...
2 parents 11eea03 + 6b775db commit 4ddff9f9619c6ebf594e5402c724794c73f8e422 @tautologistics committed Apr 21, 2012
View
4 .gitignore
@@ -1,2 +1,4 @@
.DS_Store
-
+.project*
+.settings/*
+old/*
View
15 CHANGELOG
@@ -1,5 +1,16 @@
-v1.8.0
- *
+v2.0.0
+ * Brand new parser, handles edge cases old parser did not
+ * Parser handlers renamed to builders
+ * Builder method signature simplified
+ * Moved element position calculation to builders for efficiency
+ * Added case-sensitivity options for tag and attribute names
+ * Parser output minimized (unecessary values removed)
+ * Element attribute list renamed from attribs to attributes
+ * Node types consolidated; "script" and "style" moved to "tag"
+ * An order of magnitude more tests, with many targeting the parser rather than just the builders
+ * Tests consolidated into single files per test type (e.g. parser tests, html tests, rss tests)
+ * Testing code rewritten (e.g. direct object comparator instead of comparison of and object's JSON)
+ * Brand new bugs! (not sure what they are yet but I am sure there are at least a few)
v1.7.6
* Removed "os" entry from package.json
View
2 LICENSE
@@ -1,4 +1,4 @@
-Copyright 2010, 2011, Chris Winberry <chris@winberry.net>. All rights reserved.
+Copyright 2010 - 2012, Chris Winberry <chris@winberry.net>. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
View
1,672 lib/htmlparser.js
889 additions, 783 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
22 lib/htmlparser.min.js
@@ -1,22 +0,0 @@
-/***********************************************
-Copyright 2010, 2011, Chris Winberry <chris@winberry.net>. All rights reserved.
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to
-deal in the Software without restriction, including without limitation the
-rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-sell copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-IN THE SOFTWARE.
-***********************************************/
-/* v1.7.6 */
-(function(){function e(a,c){this._options=c?c:{};void 0==this._options.includeLocation&&(this._options.includeLocation=!1);this.validateHandler(a);this._handler=a;this.reset()}function j(a){j.super_.call(this,a,{ignoreWhitespace:!0,verbose:!1,enforceEmptyTags:!1})}function g(a,c){this.reset();this._options=c?c:{};void 0==this._options.ignoreWhitespace&&(this._options.ignoreWhitespace=!1);void 0==this._options.verbose&&(this._options.verbose=!0);void 0==this._options.enforceEmptyTags&&(this._options.enforceEmptyTags= !0);"function"==typeof a&&(this._callback=a)}if(!("function"==typeof require&&"object"==typeof exports&&"object"==typeof module&&"string"==typeof __filename&&"string"==typeof __dirname)){if(this.Tautologistics){if(this.Tautologistics.NodeHtmlParser)return}else this.Tautologistics={};this.Tautologistics.NodeHtmlParser={};exports=this.Tautologistics.NodeHtmlParser}var d={Text:"text",Directive:"directive",Comment:"comment",Script:"script",Style:"style",Tag:"tag"};e._reTrim=/(^\s+|\s+$)/g;e._reTrimComment= /(^\!--|--$)/g;e._reWhitespace=/\s/g;e._reTagName=/^\s*(\/?)\s*([^\s\/]+)/;e._reAttrib=/([^=<>\"\'\s]+)\s*=\s*"([^"]*)"|([^=<>\"\'\s]+)\s*=\s*'([^']*)'|([^=<>\"\'\s]+)\s*=\s*([^'"\s]+)|([^=<>\"\'\s\/]+)/g;e._reTags=/[\<\>]/g;e.prototype.parseComplete=function(a){this.reset();this.parseChunk(a);this.done()};e.prototype.parseChunk=function(a){this._done&&this.handleError(Error("Attempted to parse chunk after parsing already done"));this._buffer+=a;this.parseTags()};e.prototype.done=function(){if(!this._done){this._done= !0;if(this._buffer.length){var a=this._buffer;this._buffer="";a={raw:a,data:this._parseState==d.Text?a:a.replace(e._reTrim,""),type:this._parseState};if(this._parseState==d.Tag||this._parseState==d.Script||this._parseState==d.Style)a.name=this.parseTagName(a.data);this.parseAttribs(a);this._elements.push(a)}this.writeHandler();this._handler.done()}};e.prototype.reset=function(){this._buffer="";this._done=!1;this._elements=[];this._next=this._current=this._elementsCurrent=0;this._location={row:0,col:0, charOffset:0,inBuffer:0};this._parseState=d.Text;this._prevTagSep="";this._tagStack=[];this._handler.reset()};e.prototype._options=null;e.prototype._handler=null;e.prototype._buffer=null;e.prototype._done=!1;e.prototype._elements=null;e.prototype._elementsCurrent=0;e.prototype._current=0;e.prototype._next=0;e.prototype._location=null;e.prototype._parseState=d.Text;e.prototype._prevTagSep="";e.prototype._tagStack=null;e.prototype.parseTagAttribs=function(a){for(var c=a.length,b=0;b<c;){var e=a[b++]; (e.type==d.Tag||e.type==d.Script||e.type==d.style)&&this.parseAttribs(e)}return a};e.prototype.parseAttribs=function(a){if(!(a.type!=d.Script&&a.type!=d.Style&&a.type!=d.Tag)){var c=a.data.split(e._reWhitespace,1)[0],c=a.data.substring(c.length);if(!(1>c.length)){var b;for(e._reAttrib.lastIndex=0;b=e._reAttrib.exec(c);)void 0==a.attribs&&(a.attribs={}),"string"==typeof b[1]&&b[1].length?a.attribs[b[1]]=b[2]:"string"==typeof b[3]&&b[3].length?a.attribs[b[3].toString()]=b[4].toString():"string"==typeof b[5]&& b[5].length?a.attribs[b[5]]=b[6]:"string"==typeof b[7]&&b[7].length&&(a.attribs[b[7]]=b[7])}}};e.prototype.parseTagName=function(a){if(null==a||""==a)return"";a=e._reTagName.exec(a);return!a?"":(a[1]?"/":"")+a[2]};e.prototype.parseTags=function(){for(var a=this._buffer.length-1;e._reTags.test(this._buffer);){this._next=e._reTags.lastIndex-1;var c=this._buffer.charAt(this._next),b=this._buffer.substring(this._current,this._next),b={raw:b,data:this._parseState==d.Text?b:b.replace(e._reTrim,""),type:this._parseState}, f=this.parseTagName(b.data);if(this._tagStack.length)if(this._tagStack[this._tagStack.length-1]==d.Script)if("/script"==f.toLowerCase())this._tagStack.pop();else{if(0!=b.raw.indexOf("!--")&&(b.type=d.Text,this._elements.length&&this._elements[this._elements.length-1].type==d.Text)){var h=this._elements[this._elements.length-1];h.raw=h.data=h.raw+this._prevTagSep+b.raw;b.raw=b.data=""}}else this._tagStack[this._tagStack.length-1]==d.Style?"/style"==f.toLowerCase()?this._tagStack.pop():0!=b.raw.indexOf("!--")&& (b.type=d.Text,this._elements.length&&this._elements[this._elements.length-1].type==d.Text?(h=this._elements[this._elements.length-1],""!=b.raw?(h.raw=h.data=h.raw+this._prevTagSep+b.raw,b.raw=b.data=""):h.raw=h.data=h.raw+this._prevTagSep):""!=b.raw&&(b.raw=b.data=b.raw)):this._tagStack[this._tagStack.length-1]==d.Comment&&(h=b.raw.length,"-"==b.raw.charAt(h-2)&&"-"==b.raw.charAt(h-1)&&">"==c?(this._tagStack.pop(),this._elements.length&&this._elements[this._elements.length-1].type==d.Comment?(h= this._elements[this._elements.length-1],h.raw=h.data=(h.raw+b.raw).replace(e._reTrimComment,""),b.raw=b.data="",b.type=d.Text):b.type=d.Comment):(b.type=d.Comment,this._elements.length&&this._elements[this._elements.length-1].type==d.Comment?(h=this._elements[this._elements.length-1],h.raw=h.data=h.raw+b.raw+c,b.raw=b.data="",b.type=d.Text):b.raw=b.data=b.raw+c));if(b.type==d.Tag&&(b.name=f,f=f.toLowerCase(),0==b.raw.indexOf("!--")?(b.type=d.Comment,delete b.name,h=b.raw.length,"-"==b.raw.charAt(h- 1)&&"-"==b.raw.charAt(h-2)&&">"==c?b.raw=b.data=b.raw.replace(e._reTrimComment,""):(b.raw+=c,this._tagStack.push(d.Comment))):0==b.raw.indexOf("!")||0==b.raw.indexOf("?")?b.type=d.Directive:"script"==f?(b.type=d.Script,"/"!=b.data.charAt(b.data.length-1)&&this._tagStack.push(d.Script)):"/script"==f?b.type=d.Script:"style"==f?(b.type=d.Style,"/"!=b.data.charAt(b.data.length-1)&&this._tagStack.push(d.Style)):"/style"==f&&(b.type=d.Style),b.name&&"/"==b.name.charAt(0)))b.data=b.name;if(""!=b.raw||b.type!= d.Text)this._options.includeLocation&&!b.location&&(b.location=this.getLocation(b.type==d.Tag)),this.parseAttribs(b),this._elements.push(b),b.type!=d.Text&&b.type!=d.Comment&&b.type!=d.Directive&&"/"==b.data.charAt(b.data.length-1)&&this._elements.push({raw:"/"+b.name,data:"/"+b.name,name:"/"+b.name,type:b.type});this._parseState="<"==c?d.Tag:d.Text;this._current=this._next+1;this._prevTagSep=c}this._options.includeLocation&&(this.getLocation(),this._location.row+=this._location.inBuffer,this._location.inBuffer= 0,this._location.charOffset=0);this._buffer=this._current<=a?this._buffer.substring(this._current):"";this._current=0;this.writeHandler()};e.prototype.getLocation=function(a){for(var c=this._location,b=this._current-(a?1:0),d=a&&0==c.charOffset&&0==this._current;c.charOffset<b;c.charOffset++)a=this._buffer.charAt(c.charOffset),"\n"==a?(c.inBuffer++,c.col=0):"\r"!=a&&c.col++;return{line:c.row+c.inBuffer+1,col:c.col+(d?0:1)}};e.prototype.validateHandler=function(a){if("object"!=typeof a)throw Error("Handler is not an object"); if("function"!=typeof a.reset)throw Error("Handler method 'reset' is invalid");if("function"!=typeof a.done)throw Error("Handler method 'done' is invalid");if("function"!=typeof a.writeTag)throw Error("Handler method 'writeTag' is invalid");if("function"!=typeof a.writeText)throw Error("Handler method 'writeText' is invalid");if("function"!=typeof a.writeComment)throw Error("Handler method 'writeComment' is invalid");if("function"!=typeof a.writeDirective)throw Error("Handler method 'writeDirective' is invalid"); };e.prototype.writeHandler=function(a){if(!this._tagStack.length||a)for(;this._elements.length;)switch(a=this._elements.shift(),a.type){case d.Comment:this._handler.writeComment(a);break;case d.Directive:this._handler.writeDirective(a);break;case d.Text:this._handler.writeText(a);break;default:this._handler.writeTag(a)}};e.prototype.handleError=function(a){if("function"==typeof this._handler.error)this._handler.error(a);else throw a;};(function(a,c){var b=function(){};b.prototype=c.prototype;a.super_= c;a.prototype=new b;a.prototype.constructor=a})(j,g);j.prototype.done=function(){var a={},c,b=f.getElementsByTagName(function(a){return"rss"==a||"feed"==a},this.dom,!1);b.length&&(c=b[0]);if(c){if("rss"==c.name){a.type="rss";c=c.children[0];a.id="";try{a.title=f.getElementsByTagName("title",c.children,!1)[0].children[0].data}catch(d){}try{a.link=f.getElementsByTagName("link",c.children,!1)[0].children[0].data}catch(e){}try{a.description=f.getElementsByTagName("description",c.children,!1)[0].children[0].data}catch(g){}try{a.updated= new Date(f.getElementsByTagName("lastBuildDate",c.children,!1)[0].children[0].data)}catch(i){}try{a.author=f.getElementsByTagName("managingEditor",c.children,!1)[0].children[0].data}catch(l){}a.items=[];f.getElementsByTagName("item",c.children).forEach(function(b){var c={};try{c.id=f.getElementsByTagName("guid",b.children,!1)[0].children[0].data}catch(d){}try{c.title=f.getElementsByTagName("title",b.children,!1)[0].children[0].data}catch(e){}try{c.link=f.getElementsByTagName("link",b.children,!1)[0].children[0].data}catch(h){}try{c.description= f.getElementsByTagName("description",b.children,!1)[0].children[0].data}catch(g){}try{c.pubDate=new Date(f.getElementsByTagName("pubDate",b.children,!1)[0].children[0].data)}catch(k){}a.items.push(c)})}else{a.type="atom";try{a.id=f.getElementsByTagName("id",c.children,!1)[0].children[0].data}catch(m){}try{a.title=f.getElementsByTagName("title",c.children,!1)[0].children[0].data}catch(n){}try{a.link=f.getElementsByTagName("link",c.children,!1)[0].attribs.href}catch(o){}try{a.description=f.getElementsByTagName("subtitle", c.children,!1)[0].children[0].data}catch(p){}try{a.updated=new Date(f.getElementsByTagName("updated",c.children,!1)[0].children[0].data)}catch(q){}try{a.author=f.getElementsByTagName("email",c.children,!0)[0].children[0].data}catch(r){}a.items=[];f.getElementsByTagName("entry",c.children).forEach(function(b){var c={};try{c.id=f.getElementsByTagName("id",b.children,!1)[0].children[0].data}catch(d){}try{c.title=f.getElementsByTagName("title",b.children,!1)[0].children[0].data}catch(e){}try{c.link=f.getElementsByTagName("link", b.children,!1)[0].attribs.href}catch(h){}try{c.description=f.getElementsByTagName("summary",b.children,!1)[0].children[0].data}catch(g){}try{c.pubDate=new Date(f.getElementsByTagName("updated",b.children,!1)[0].children[0].data)}catch(k){}a.items.push(c)})}this.dom=a}j.super_.prototype.done.call(this)};g._emptyTags={area:1,base:1,basefont:1,br:1,col:1,frame:1,hr:1,img:1,input:1,isindex:1,link:1,meta:1,param:1,embed:1};g.reWhitespace=/^\s*$/;g.prototype.dom=null;g.prototype.reset=function(){this.dom= [];this._done=!1;this._tagStack=[];this._tagStack.last=function(){return this.length?this[this.length-1]:null}};g.prototype.done=function(){this._done=!0;this.handleCallback(null)};g.prototype.writeTag=function(a){this.handleElement(a)};g.prototype.writeText=function(a){(!this._options.ignoreWhitespace||!g.reWhitespace.test(a.data))&&this.handleElement(a)};g.prototype.writeComment=function(a){this.handleElement(a)};g.prototype.writeDirective=function(a){this.handleElement(a)};g.prototype.error=function(a){this.handleCallback(a)}; g.prototype._options=null;g.prototype._callback=null;g.prototype._done=!1;g.prototype._tagStack=null;g.prototype.handleCallback=function(a){if("function"!=typeof this._callback){if(a)throw a;}else this._callback(a,this.dom)};g.prototype.isEmptyTag=function(a){a=a.name.toLowerCase();"/"==a.charAt(0)&&(a=a.substring(1));return this._options.enforceEmptyTags&&!!g._emptyTags[a]};g.prototype.handleElement=function(a){this._done&&this.handleCallback(Error("Writing to the handler after done() called is not allowed without a reset()")); this._options.verbose||(delete a.raw,("tag"==a.type||"script"==a.type||"style"==a.type)&&delete a.data);if(this._tagStack.last())if(a.type!=d.Text&&a.type!=d.Comment&&a.type!=d.Directive)if("/"==a.name.charAt(0)){var c=a.name.substring(1);if(!this.isEmptyTag(a)){for(a=this._tagStack.length-1;-1<a&&this._tagStack[a--].name!=c;);if(-1<a||this._tagStack[0].name==c)for(;a<this._tagStack.length-1;)this._tagStack.pop()}}else this._tagStack.last().children||(this._tagStack.last().children=[]),this._tagStack.last().children.push(a), this.isEmptyTag(a)||this._tagStack.push(a);else this._tagStack.last().children||(this._tagStack.last().children=[]),this._tagStack.last().children.push(a);else a.type!=d.Text&&a.type!=d.Comment&&a.type!=d.Directive?"/"!=a.name.charAt(0)&&(this.dom.push(a),this.isEmptyTag(a)||this._tagStack.push(a)):this.dom.push(a)};var f={testElement:function(a,c){if(!c)return!1;for(var b in a)if("tag_name"==b){if("tag"!=c.type&&"script"!=c.type&&"style"!=c.type||!a.tag_name(c.name))return!1}else if("tag_type"== b){if(!a.tag_type(c.type))return!1}else if("tag_contains"==b){if("text"!=c.type&&"comment"!=c.type&&"directive"!=c.type||!a.tag_contains(c.data))return!1}else if(!c.attribs||!a[b](c.attribs[b]))return!1;return!0},getElements:function(a,c,b,d){function e(a){return function(b){return b==a}}b=void 0===b||null===b||!!b;d=isNaN(parseInt(d))?-1:parseInt(d);if(!c)return[];var g=[],i;for(i in a)"function"!=typeof a[i]&&(a[i]=e(a[i]));f.testElement(a,c)&&g.push(c);if(0<=d&&g.length>=d)return g;if(b&&c.children)c= c.children;else if(!(c instanceof Array))return g;for(i=0;i<c.length&&!(g=g.concat(f.getElements(a,c[i],b,d)),0<=d&&g.length>=d);i++);return g},getElementById:function(a,c,b){a=f.getElements({id:a},c,b,1);return a.length?a[0]:null},getElementsByTagName:function(a,c,b,d){return f.getElements({tag_name:a},c,b,d)},getElementsByTagType:function(a,c,b,d){return f.getElements({tag_type:a},c,b,d)}};exports.Parser=e;exports.DefaultHandler=g;exports.RssHandler=j;exports.ElementType=d;exports.DomUtils=f})();
View
6 lib/node-htmlparser.js
@@ -1,6 +0,0 @@
-var htmlparser = require("./htmlparser");
-exports.Parser = htmlparser.Parser;
-exports.DefaultHandler = htmlparser.DefaultHandler;
-exports.RssHandler = htmlparser.RssHandler;
-exports.ElementType = htmlparser.ElementType;
-exports.DomUtils = htmlparser.DomUtils;
View
6 lib/node-htmlparser.min.js
@@ -1,6 +0,0 @@
-var htmlparser = require("./htmlparser.min");
-exports.Parser = htmlparser.Parser;
-exports.DefaultHandler = htmlparser.DefaultHandler;
-exports.RssHandler = htmlparser.RssHandler;
-exports.ElementType = htmlparser.ElementType;
-exports.DomUtils = htmlparser.DomUtils;
View
4 package.json
@@ -1,7 +1,7 @@
{
"name": "htmlparser"
, "description": "Forgiving HTML/XML/RSS Parser in JS for *both* Node and Browsers"
- , "version": "1.7.6"
+ , "version": "2.0.0"
, "author": "Chris Winberry <chris@winberry.net>"
, "contributors": []
, "repository": {
@@ -25,7 +25,7 @@
}
, "directories": { "lib": "./lib/" }
, "main": "./lib/htmlparser"
- , "engines": { "node": ">=0.1.33" }
+ , "engines": { "node": ">=0.5.0" }
, "licenses": [{
"type": "MIT"
, "url": "http://github.com/tautologistics/node-htmlparser/raw/master/LICENSE"
View
63 profile.js
@@ -1,63 +0,0 @@
-//node --prof --prof_auto profile.js
-//deps/v8/tools/mac-tick-processor v8.log
-var sys = require("sys");
-var fs = require("fs");
-var http = require("http");
-var htmlparser = require("./lib/htmlparser");
-//var libxml = require('./libxmljs');
-
-var testNHP = true; //Should node-htmlparser be exercised?
-var testLXJS = false; //Should libxmljs be exercised?
-var testIterations = 100; //Number of test loops to run
-
-var testHost = "localhost"; //Host to fetch test HTML from
-var testPort = 80; //Port on host to fetch test HTML from
-var testPath = "/~chris/feed.xml"; //Path on host to fetch HTML from
-
-function getMillisecs () {
- return((new Date()).getTime());
-}
-
-function timeExecutions (loops, func) {
- var start = getMillisecs();
-
- while (loops--)
- func();
-
- return(getMillisecs() - start);
-}
-
-var html = "";
-http.createClient(testPort, testHost)
- .request("GET", testPath, { host: testHost })
- .addListener("response", function (response) {
- if (response.statusCode == "200") {
- response.setEncoding("utf8");
- response.addListener("data", function (chunk) {
- html += chunk;
- }).addListener("end", function() {
- var timeNodeHtmlParser = !testNHP ? 0 : timeExecutions(testIterations, function () {
- var handler = new htmlparser.DefaultHandler(function(err, dom) {
- if (err)
- sys.debug("Error: " + err);
- });
- var parser = new htmlparser.Parser(handler, { includeLocation: true });
- parser.parseComplete(html);
- })
-
- var timeLibXmlJs = !testLXJS ? 0 : timeExecutions(testIterations, function () {
- var dom = libxml.parseHtmlString(html);
- })
-
- if (testNHP)
- sys.debug("NodeHtmlParser: " + timeNodeHtmlParser);
- if (testLXJS)
- sys.debug("LibXmlJs: " + timeLibXmlJs);
- if (testNHP && testLXJS)
- sys.debug("Difference: " + ((timeNodeHtmlParser - timeLibXmlJs) / timeLibXmlJs) * 100);
- });
- }
- else
- sys.debug("Error: got response status " + response.statusCode);
- })
- .end();
View
285 runtests.html
@@ -1,13 +1,37 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+Copyright 2010 - 2012, Chris Winberry <chris@winberry.net>. All rights reserved.
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
+-->
+
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Node.js HTML Parser</title>
<style type="text/css">
- .good {
+ .testName {
+ font-weight: bold;
+ }
+ .pass {
color: #363;
}
- .bad {
+ .fail {
color: #633;
font-style: italic;
}
@@ -22,87 +46,194 @@
}
</script>
<script language="JavaScript" src="lib/htmlparser.js"></script>
- <script language="JavaScript" src="tests/01-basic.js"></script>
- <script language="JavaScript" src="tests/02-single_tag_1.js"></script>
- <script language="JavaScript" src="tests/03-single_tag_2.js"></script>
- <script language="JavaScript" src="tests/04-unescaped_in_script.js"></script>
- <script language="JavaScript" src="tests/05-tags_in_comment.js"></script>
- <script language="JavaScript" src="tests/06-comment_in_script.js"></script>
- <script language="JavaScript" src="tests/07-unescaped_in_style.js"></script>
- <script language="JavaScript" src="tests/08-extra_spaces_in_tag.js"></script>
- <script language="JavaScript" src="tests/09-unquoted_attrib.js"></script>
- <script language="JavaScript" src="tests/10-singular_attribute.js"></script>
- <script language="JavaScript" src="tests/11-text_outside_tags.js"></script>
- <script language="JavaScript" src="tests/12-text_only.js"></script>
- <script language="JavaScript" src="tests/13-comment_in_text.js"></script>
- <script language="JavaScript" src="tests/14-comment_in_text_in_script.js"></script>
- <script language="JavaScript" src="tests/15-non-verbose.js"></script>
- <script language="JavaScript" src="tests/16-ignore_whitespace.js"></script>
- <script language="JavaScript" src="tests/17-xml_namespace.js"></script>
- <script language="JavaScript" src="tests/18-enforce_empty_tags.js"></script>
- <script language="JavaScript" src="tests/19-ignore_empty_tags.js"></script>
- <script language="JavaScript" src="tests/20-rss.js"></script>
- <script language="JavaScript" src="tests/21-atom.js"></script>
- <script language="JavaScript" src="tests/22-position_data.js"></script>
+ <script language="JavaScript" src="tests/testutils.js"></script>
+ <script language="JavaScript" src="tests/html.js"></script>
+ <script language="JavaScript" src="tests/parser.js"></script>
+ <script language="JavaScript" src="tests/rss.js"></script>
<!-- //TODO: dynamic loading of test files -->
</head>
<body style="font-size: small; font-family:Arial, Helvetica, sans-serif;">
<script language="JavaScript">
- var chunkSize = 5;
- var testCount = 0;
- var failedCount = 0;
- while (Tautologistics.NodeHtmlParser.Tests.length) {
- testCount++;
- var test = Tautologistics.NodeHtmlParser.Tests.shift();
- try {
- var handlerCallback = function handlerCallback (error) {
- if (error)
- document.write("<hr>Handler error: " + error + "<hr>");
- }
- var handler = (test.type == "rss") ?
- new Tautologistics.NodeHtmlParser.RssHandler(handlerCallback, test.options.handler)
- :
- new Tautologistics.NodeHtmlParser.DefaultHandler(handlerCallback, test.options.handler)
- ;
- var parser = new Tautologistics.NodeHtmlParser.Parser(handler, test.options.parser);
- document.write("<b>" + test.name + "</b>: ");
- parser.parseComplete(test.html);
- var resultComplete = handler.dom;
- var chunkPos = 0;
- parser.reset();
- while (chunkPos < test.html.length) {
- parser.parseChunk(test.html.substring(chunkPos, chunkPos + chunkSize));
- chunkPos += chunkSize;
- }
- parser.done();
- var resultChunk = handler.dom;
- var testResult =
- JSON.stringify(resultComplete).toString() === JSON.stringify(test.expected).toString()
- &&
- JSON.stringify(resultChunk).toString() === JSON.stringify(test.expected).toString()
- ;
- document.write(testResult ? "<font class='good'>passed</font>" : "<font class='bad'>FAILED</font>");
- if (!testResult) {
- failedCount++;
- document.write("<pre>");
- document.write("<b>Complete</b>\n");
- document.write(JSON.stringify(resultComplete, null, 2));
- document.write("<b>Chunked</b>\n");
- document.write(JSON.stringify(resultChunk, null, 2));
- document.write("<h2>Expected</h2>\n");
- document.write(JSON.stringify(test.expected, null, 2));
- document.write("</pre>");
- }
- } catch (ex) {
- document.write("<h1>Exception occured during test: " + ex + "</h1>")
- }
- document.write("<br>");
+ (function () {
+
+ function writeTest (name, result) {
+ document.write(
+ "<div>" +
+ "<span class='testName'>" + name + "</span>: " +
+ "<span class='" + (result ? 'pass' : 'fail') + "'>" + (result ? 'passed' : 'FAILED') + "</span>" +
+ "</div>"
+ );
}
- document.write("<hr>");
- document.write("Total tests: " + testCount + "<br>");
- document.write("Failed tests: " + failedCount + "<br>");
+
+ var testResults = {};
+
+ Tautologistics.NodeHtmlParser.Tests.Utils.runBuilderTests(
+ Tautologistics.NodeHtmlParser.Tests.Html
+ , Tautologistics.NodeHtmlParser.Parser
+ , Tautologistics.NodeHtmlParser.HtmlBuilder
+ , null
+ , function (testName, testResult, actual, expected) {
+ // console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ writeTest(testName, testResult);
+ }, function (elapsed, passed, failed) {
+ testResults['HTML builder'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
+ Tautologistics.NodeHtmlParser.Tests.Utils.runBuilderTests(
+ Tautologistics.NodeHtmlParser.Tests.Html
+ , Tautologistics.NodeHtmlParser.Parser
+ , Tautologistics.NodeHtmlParser.HtmlBuilder
+ , function (test) {
+ var newTest = {};
+ for (var key in test) {
+ if (!test.hasOwnProperty(key)) {
+ continue;
+ }
+ newTest[key] = (key === 'data') ?
+ test.data.join('').split('')
+ :
+ test[key]
+ ;
+ }
+ return newTest;
+ }
+ , function (testName, testResult, actual, expected) {
+ // console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ writeTest(testName, testResult);
+ }, function (elapsed, passed, failed) {
+ testResults['HTML builder (streamed)'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
+
+ Tautologistics.NodeHtmlParser.Tests.Utils.runBuilderTests(
+ Tautologistics.NodeHtmlParser.Tests.Rss
+ , Tautologistics.NodeHtmlParser.Parser
+ , Tautologistics.NodeHtmlParser.RssBuilder
+ , null
+ , function (testName, testResult, actual, expected) {
+ // console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ writeTest(testName, testResult);
+ }, function (elapsed, passed, failed) {
+ testResults['RSS builder'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
+ Tautologistics.NodeHtmlParser.Tests.Utils.runBuilderTests(
+ Tautologistics.NodeHtmlParser.Tests.Rss
+ , Tautologistics.NodeHtmlParser.Parser
+ , Tautologistics.NodeHtmlParser.RssBuilder
+ , function (test) {
+ var newTest = {};
+ for (var key in test) {
+ if (!test.hasOwnProperty(key)) {
+ continue;
+ }
+ newTest[key] = (key === 'data') ?
+ test.data.join('').split('')
+ :
+ test[key]
+ ;
+ }
+ return newTest;
+ }
+ , function (testName, testResult, actual, expected) {
+ // console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ writeTest(testName, testResult);
+ }, function (elapsed, passed, failed) {
+ testResults['RSS builder (streamed)'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
+
+ Tautologistics.NodeHtmlParser.Tests.Utils.runParserTests(
+ Tautologistics.NodeHtmlParser.Tests.Parser
+ , Tautologistics.NodeHtmlParser.Parser
+ , null
+ , function (testName, testResult, actual, expected) {
+ // console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ writeTest(testName, testResult);
+ }, function (elapsed, passed, failed) {
+ testResults['Parser'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
+ Tautologistics.NodeHtmlParser.Tests.Utils.runParserTests(
+ Tautologistics.NodeHtmlParser.Tests.Parser
+ , Tautologistics.NodeHtmlParser.Parser
+ , function (test) {
+ var newTest = {};
+ for (var key in test) {
+ if (!test.hasOwnProperty(key)) {
+ continue;
+ }
+ newTest[key] = (key === 'data') ?
+ test.data.join('').split('')
+ :
+ test[key]
+ ;
+ }
+ return newTest;
+ }
+ , function (testName, testResult, actual, expected) {
+ // console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ writeTest(testName, testResult);
+ }, function (elapsed, passed, failed) {
+ testResults['Parser (streamed)'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
+
+ document.write(
+ "<br>" +
+ '<h1>Test Results</h1>' +
+ '<hr>'
+ );
+ var passedTotal = 0;
+ var failedTotal = 0;
+ var elapsedTotal = 0;
+ for (var testName in testResults) {
+ if (!testResults.hasOwnProperty(testName)) {
+ continue;
+ }
+ var test = testResults[testName];
+ passedTotal += test.passed;
+ failedTotal += test.failed;
+ elapsedTotal += test.elapsed;
+ document.write(
+ "<div>" +
+ "<span class='testName'>" + testName + '</span>: ' +
+ "<span class='" + (test.failed === 0 ? 'pass' : 'fail') + "'>" +
+ test.passed + '/' + (test.passed + test.failed) +
+ ' (' + Math.round(test.passed / (test.passed + test.failed) * 100) + '%) ' +
+ '[' + test.elapsed + 'ms]' +
+ "</span>" +
+ "</div>"
+ );
+ }
+ document.write(
+ '<hr>' +
+ 'Total: ' + passedTotal + '/' + (passedTotal + failedTotal) +
+ ' (' + Math.round(passedTotal / (passedTotal + failedTotal) * 100) + '%) ' +
+ '[' + elapsedTotal + 'ms]'
+ );
+
+ })();
</script>
-
+
</body>
</html>
View
253 runtests.js
@@ -1,15 +1,15 @@
/***********************************************
-Copyright 2010, Chris Winberry <chris@winberry.net>. All rights reserved.
+Copyright 2010 - 2012, Chris Winberry <chris@winberry.net>. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
-
+
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
-
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -19,57 +19,206 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
***********************************************/
-var sys = require("sys");
+Object.prototype.equals = function (x) {
+ //http://stackoverflow.com/questions/1068834/object-comparison-in-javascript
+ var p;
+
+ for (p in this) {
+ if (typeof(x[p]) == 'undefined') {
+ // console.log('Missing property: ', p);
+ return false;
+ }
+ }
+
+ for (p in x) {
+ if (typeof(this[p]) == 'undefined') {
+ // console.log('Extra property: ', p);
+ return false;
+ }
+ }
+
+ for (p in this) {
+ if (this[p]) {
+ switch(typeof(this[p])) {
+ case 'object':
+ if (!this[p].equals(x[p])) {
+ // console.log('Mismatched property: ', p);
+ return false;
+ }
+ break;
+ case 'function':
+ if (typeof(x[p])=='undefined' || (p != 'equals' && this[p].toString() != x[p].toString())) {
+ // console.log('Mismatched property: ', p);
+ return false;
+ }
+ break;
+ default:
+ if (this[p] != x[p]) {
+ // console.log('Mismatched property: ', p);
+ return false;
+ }
+ }
+ } else {
+ if (x[p]) {
+ // console.log('Poop: ', p);
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+var util = require("util");
var fs = require("fs");
var htmlparser = require("./lib/htmlparser");
-var testFolder = "./tests";
-var chunkSize = 5;
+var testUtils = require('./tests/testutils');
+var htmlTests = require('./tests/html');
+var rssTests = require('./tests/rss');
+var parserTests = require('./tests/parser');
+
+var testResults = {};
+
+testUtils.runBuilderTests(
+ htmlTests
+ , htmlparser.Parser
+ , htmlparser.HtmlBuilder
+ , null
+ , function (testName, testResult, actual, expected) {
+ console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ }, function (elapsed, passed, failed) {
+ testResults['HTML builder'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
+testUtils.runBuilderTests(
+ htmlTests
+ , htmlparser.Parser
+ , htmlparser.HtmlBuilder
+ , function (test) {
+ var newTest = {};
+ for (var key in test) {
+ if (!test.hasOwnProperty(key)) {
+ continue;
+ }
+ newTest[key] = (key === 'data') ?
+ test.data.join('').split('')
+ :
+ test[key]
+ ;
+ }
+ return newTest;
+ }
+ , function (testName, testResult, actual, expected) {
+ console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ }, function (elapsed, passed, failed) {
+ testResults['HTML builder (streamed)'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
+
+testUtils.runBuilderTests(
+ rssTests
+ , htmlparser.Parser
+ , htmlparser.RssBuilder
+ , null
+ , function (testName, testResult, actual, expected) {
+ console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ }, function (elapsed, passed, failed) {
+ testResults['RSS builder'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
+testUtils.runBuilderTests(
+ rssTests
+ , htmlparser.Parser
+ , htmlparser.RssBuilder
+ , function (test) {
+ var newTest = {};
+ for (var key in test) {
+ if (!test.hasOwnProperty(key)) {
+ continue;
+ }
+ newTest[key] = (key === 'data') ?
+ test.data.join('').split('')
+ :
+ test[key]
+ ;
+ }
+ return newTest;
+ }
+ , function (testName, testResult, actual, expected) {
+ console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ }, function (elapsed, passed, failed) {
+ testResults['RSS builder (streamed)'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
+
+testUtils.runParserTests(
+ parserTests
+ , htmlparser.Parser
+ , null
+ , function (testName, testResult, actual, expected) {
+ console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ }, function (elapsed, passed, failed) {
+ testResults['Parser'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
+testUtils.runParserTests(
+ parserTests
+ , htmlparser.Parser
+ , function (test) {
+ var newTest = {};
+ for (var key in test) {
+ if (!test.hasOwnProperty(key)) {
+ continue;
+ }
+ newTest[key] = (key === 'data') ?
+ test.data.join('').split('')
+ :
+ test[key]
+ ;
+ }
+ return newTest;
+ }
+ , function (testName, testResult, actual, expected) {
+ console.log("[" + testName + "]: " + (testResult ? "passed" : "FAILED"));
+ }, function (elapsed, passed, failed) {
+ testResults['Parser (streamed)'] = {
+ elapsed: elapsed
+ , passed: passed
+ , failed: failed
+ };
+ });
-var testFiles = fs.readdirSync(testFolder);
-var testCount = 0;
-var failedCount = 0;
-for (var i in testFiles) {
- testCount++;
- var fileParts = testFiles[i].split(".");
- fileParts.pop();
- var moduleName = fileParts.join(".");
- var test = require(testFolder + "/" + moduleName);
- var handlerCallback = function handlerCallback (error) {
- if (error)
- sys.puts("Handler error: " + error);
- }
- var handler = (test.type == "rss") ?
- new htmlparser.RssHandler(handlerCallback, test.options.handler)
- :
- new htmlparser.DefaultHandler(handlerCallback, test.options.handler)
- ;
- var parser = new htmlparser.Parser(handler, test.options.parser);
- parser.parseComplete(test.html);
- var resultComplete = handler.dom;
- var chunkPos = 0;
- parser.reset();
- while (chunkPos < test.html.length) {
- parser.parseChunk(test.html.substring(chunkPos, chunkPos + chunkSize));
- chunkPos += chunkSize;
- }
- parser.done();
- var resultChunk = handler.dom;
- var testResult =
- sys.inspect(resultComplete, false, null) === sys.inspect(test.expected, false, null)
- &&
- sys.inspect(resultChunk, false, null) === sys.inspect(test.expected, false, null)
- ;
- sys.puts("[" + test.name + "\]: " + (testResult ? "passed" : "FAILED"));
- if (!testResult) {
- failedCount++;
- sys.puts("== Complete ==");
- sys.puts(sys.inspect(resultComplete, false, null));
- sys.puts("== Chunked ==");
- sys.puts(sys.inspect(resultChunk, false, null));
- sys.puts("== Expected ==");
- sys.puts(sys.inspect(test.expected, false, null));
- }
+console.log('');
+console.log('Test Results');
+console.log('------------------');
+var passedTotal = 0;
+var failedTotal = 0;
+var elapsedTotal = 0;
+for (var testName in testResults) {
+ if (!testResults.hasOwnProperty(testName)) {
+ continue;
+ }
+ var test = testResults[testName];
+ passedTotal += test.passed;
+ failedTotal += test.failed;
+ elapsedTotal += test.elapsed;
+ console.log(testName + ': ' + test.passed + '/' + (test.passed + test.failed) + ' (' + Math.round(test.passed / (test.passed + test.failed) * 100) + '%) [' + test.elapsed + 'ms]');
}
-sys.puts("Total tests: " + testCount);
-sys.puts("Failed tests: " + failedCount);
+console.log('------------------');
+console.log('Total: ' + passedTotal + '/' + (passedTotal + failedTotal) + ' (' + Math.round(passedTotal / (passedTotal + failedTotal) * 100) + '%) [' + elapsedTotal + 'ms]');
View
108 runtests.min.html
@@ -1,108 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Node.js HTML Parser</title>
- <style type="text/css">
- .good {
- color: #363;
- }
- .bad {
- color: #633;
- font-style: italic;
- }
- </style>
- <script language="JavaScript">
- if ((typeof JSON) != "object") {
- var head = document.getElementsByTagName("head")[0];
- var script = document.createElement('script');
- script.type = "text/javascript";
- script.src = "json2.js";
- head.insertBefore(script, head.firstChild)
- }
- </script>
- <script language="JavaScript" src="lib/htmlparser.min.js"></script>
- <script language="JavaScript" src="tests/01-basic.js"></script>
- <script language="JavaScript" src="tests/02-single_tag_1.js"></script>
- <script language="JavaScript" src="tests/03-single_tag_2.js"></script>
- <script language="JavaScript" src="tests/04-unescaped_in_script.js"></script>
- <script language="JavaScript" src="tests/05-tags_in_comment.js"></script>
- <script language="JavaScript" src="tests/06-comment_in_script.js"></script>
- <script language="JavaScript" src="tests/07-unescaped_in_style.js"></script>
- <script language="JavaScript" src="tests/08-extra_spaces_in_tag.js"></script>
- <script language="JavaScript" src="tests/09-unquoted_attrib.js"></script>
- <script language="JavaScript" src="tests/10-singular_attribute.js"></script>
- <script language="JavaScript" src="tests/11-text_outside_tags.js"></script>
- <script language="JavaScript" src="tests/12-text_only.js"></script>
- <script language="JavaScript" src="tests/13-comment_in_text.js"></script>
- <script language="JavaScript" src="tests/14-comment_in_text_in_script.js"></script>
- <script language="JavaScript" src="tests/15-non-verbose.js"></script>
- <script language="JavaScript" src="tests/16-ignore_whitespace.js"></script>
- <script language="JavaScript" src="tests/17-xml_namespace.js"></script>
- <script language="JavaScript" src="tests/18-enforce_empty_tags.js"></script>
- <script language="JavaScript" src="tests/19-ignore_empty_tags.js"></script>
- <script language="JavaScript" src="tests/20-rss.js"></script>
- <script language="JavaScript" src="tests/21-atom.js"></script>
- <script language="JavaScript" src="tests/22-position_data.js"></script>
- <!-- //TODO: dynamic loading of test files -->
- </head>
- <body style="font-size: small; font-family:Arial, Helvetica, sans-serif;">
-
- <script language="JavaScript">
- var chunkSize = 5;
- var testCount = 0;
- var failedCount = 0;
- while (Tautologistics.NodeHtmlParser.Tests.length) {
- testCount++;
- var test = Tautologistics.NodeHtmlParser.Tests.shift();
- try {
- var handlerCallback = function handlerCallback (error) {
- if (error)
- document.write("<hr>Handler error: " + error + "<hr>");
- }
- var handler = (test.type == "rss") ?
- new Tautologistics.NodeHtmlParser.RssHandler(handlerCallback, test.options.handler)
- :
- new Tautologistics.NodeHtmlParser.DefaultHandler(handlerCallback, test.options.handler)
- ;
- var parser = new Tautologistics.NodeHtmlParser.Parser(handler, test.options.parser);
- document.write("<b>" + test.name + "</b>: ");
- parser.parseComplete(test.html);
- var resultComplete = handler.dom;
- var chunkPos = 0;
- parser.reset();
- while (chunkPos < test.html.length) {
- parser.parseChunk(test.html.substring(chunkPos, chunkPos + chunkSize));
- chunkPos += chunkSize;
- }
- parser.done();
- var resultChunk = handler.dom;
- var testResult =
- JSON.stringify(resultComplete).toString() === JSON.stringify(test.expected).toString()
- &&
- JSON.stringify(resultChunk).toString() === JSON.stringify(test.expected).toString()
- ;
- document.write(testResult ? "<font class='good'>passed</font>" : "<font class='bad'>FAILED</font>");
- if (!testResult) {
- failedCount++;
- document.write("<pre>");
- document.write("<b>Complete</b>\n");
- document.write(JSON.stringify(resultComplete, null, 2));
- document.write("<b>Chunked</b>\n");
- document.write(JSON.stringify(resultChunk, null, 2));
- document.write("<h2>Expected</h2>\n");
- document.write(JSON.stringify(test.expected, null, 2));
- document.write("</pre>");
- }
- } catch (ex) {
- document.write("<h1>Exception occured during test: " + ex + "</h1>")
- }
- document.write("<br>");
- }
- document.write("<hr>");
- document.write("Total tests: " + testCount + "<br>");
- document.write("Failed tests: " + failedCount + "<br>");
- </script>
-
- </body>
-</html>
View
75 runtests.min.js
@@ -1,75 +0,0 @@
-/***********************************************
-Copyright 2010, Chris Winberry <chris@winberry.net>. All rights reserved.
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to
-deal in the Software without restriction, including without limitation the
-rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-sell copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-IN THE SOFTWARE.
-***********************************************/
-
-var sys = require("sys");
-var fs = require("fs");
-var htmlparser = require("./lib/htmlparser.min");
-
-var testFolder = "./tests";
-var chunkSize = 5;
-
-var testFiles = fs.readdirSync(testFolder);
-var testCount = 0;
-var failedCount = 0;
-for (var i in testFiles) {
- testCount++;
- var fileParts = testFiles[i].split(".");
- fileParts.pop();
- var moduleName = fileParts.join(".");
- var test = require(testFolder + "/" + moduleName);
- var handlerCallback = function handlerCallback (error) {
- if (error)
- sys.puts("Handler error: " + error);
- }
- var handler = (test.type == "rss") ?
- new htmlparser.RssHandler(handlerCallback, test.options.handler)
- :
- new htmlparser.DefaultHandler(handlerCallback, test.options.handler)
- ;
- var parser = new htmlparser.Parser(handler, test.options.parser);
- parser.parseComplete(test.html);
- var resultComplete = handler.dom;
- var chunkPos = 0;
- parser.reset();
- while (chunkPos < test.html.length) {
- parser.parseChunk(test.html.substring(chunkPos, chunkPos + chunkSize));
- chunkPos += chunkSize;
- }
- parser.done();
- var resultChunk = handler.dom;
- var testResult =
- sys.inspect(resultComplete, false, null) === sys.inspect(test.expected, false, null)
- &&
- sys.inspect(resultChunk, false, null) === sys.inspect(test.expected, false, null)
- ;
- sys.puts("[" + test.name + "\]: " + (testResult ? "passed" : "FAILED"));
- if (!testResult) {
- failedCount++;
- sys.puts("== Complete ==");
- sys.puts(sys.inspect(resultComplete, false, null));
- sys.puts("== Chunked ==");
- sys.puts(sys.inspect(resultChunk, false, null));
- sys.puts("== Expected ==");
- sys.puts(sys.inspect(test.expected, false, null));
- }
-}
-sys.puts("Total tests: " + testCount);
-sys.puts("Failed tests: " + failedCount);
View
61 tests/01-basic.js
@@ -1,61 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Basic test";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<html><title>The Title</title><body>Hello world</body></html>";
-exports.expected =
- [ { raw: 'html'
- , data: 'html'
- , type: 'tag'
- , name: 'html'
- , children:
- [ { raw: 'title'
- , data: 'title'
- , type: 'tag'
- , name: 'title'
- , children: [ { raw: 'The Title', data: 'The Title', type: 'text' } ]
- }
- , { raw: 'body'
- , data: 'body'
- , type: 'tag'
- , name: 'body'
- , children:
- [ { raw: 'Hello world'
- , data: 'Hello world'
- , type: 'text'
- }
- ]
- }
- ]
- }
- ];
-
-})();
View
39 tests/02-single_tag_1.js
@@ -1,39 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Single Tag 1";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<br>text</br>";
-exports.expected =
- [ { raw: 'br', data: 'br', type: 'tag', name: 'br' }
- , { raw: 'text', data: 'text', type: 'text' }
- ];
-
-})();
View
40 tests/03-single_tag_2.js
@@ -1,40 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Single Tag 2";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<br>text<br>";
-exports.expected =
- [ { raw: 'br', data: 'br', type: 'tag', name: 'br' }
- , { raw: 'text', data: 'text', type: 'text' }
- , { raw: 'br', data: 'br', type: 'tag', name: 'br' }
- ];
-
-})();
View
56 tests/04-unescaped_in_script.js
@@ -1,56 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Unescaped chars in script";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<head><script language=\"Javascript\">var foo = \"<bar>\"; alert(2 > foo); var baz = 10 << 2; var zip = 10 >> 1; var yap = \"<<>>>><<\";</script></head>";
-exports.expected =
-[ { raw: 'head'
- , data: 'head'
- , type: 'tag'
- , name: 'head'
- , children:
- [ { raw: 'script language="Javascript"'
- , data: 'script language="Javascript"'
- , type: 'script'
- , name: 'script'
- , attribs: { language: 'Javascript' }
- , children:
- [ { raw: 'var foo = "<bar>"; alert(2 > foo); var baz = 10 << 2; var zip = 10 >> 1; var yap = \"<<>>>><<\";'
- , data: 'var foo = "<bar>"; alert(2 > foo); var baz = 10 << 2; var zip = 10 >> 1; var yap = \"<<>>>><<\";'
- , type: 'text'
- }
- ]
- }
- ]
- }
-];
-
-})();
View
48 tests/05-tags_in_comment.js
@@ -1,48 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Special char in comment";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<head><!-- commented out tags <title>Test</title>--></head>";
-exports.expected =
-[ { raw: 'head'
- , data: 'head'
- , type: 'tag'
- , name: 'head'
- , children:
- [ { raw: ' commented out tags <title>Test</title>'
- , data: ' commented out tags <title>Test</title>'
- , type: 'comment'
- }
- ]
- }
-];
-
-})();
View
48 tests/06-comment_in_script.js
@@ -1,48 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Script source in comment";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<script><!--var foo = 1;--></script>";
-exports.expected =
-[ { raw: 'script'
- , data: 'script'
- , type: 'script'
- , name: 'script'
- , children:
- [ { raw: 'var foo = 1;'
- , data: 'var foo = 1;'
- , type: 'comment'
- }
- ]
- }
-];
-
-})();
View
49 tests/07-unescaped_in_style.js
@@ -1,49 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Unescaped chars in style";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<style type=\"text/css\">\n body > p\n { font-weight: bold; }</style>";
-exports.expected =
-[ { raw: 'style type="text/css"'
- , data: 'style type="text/css"'
- , type: 'style'
- , name: 'style'
- , attribs: { type: 'text/css' }
- , children:
- [ { raw: '\n body > p\n { font-weight: bold; }'
- , data: '\n body > p\n { font-weight: bold; }'
- , type: 'text'
- }
- ]
- }
-];
-
-})();
View
49 tests/08-extra_spaces_in_tag.js
@@ -1,49 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Extra spaces in tag";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<\n font \n size='14' \n>the text<\n / \nfont \n>";
-exports.expected =
-[ { raw: '\n font \n size=\'14\' \n'
- , data: 'font \n size=\'14\''
- , type: 'tag'
- , name: 'font'
- , attribs: { size: '14' }
- , children:
- [ { raw: 'the text'
- , data: 'the text'
- , type: 'text'
- }
- ]
- }
-];
-
-})();
View
49 tests/09-unquoted_attrib.js
@@ -1,49 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Unquoted attributes";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<font size= 14>the text</font>";
-exports.expected =
-[ { raw: 'font size= 14'
- , data: 'font size= 14'
- , type: 'tag'
- , name: 'font'
- , attribs: { size: '14' }
- , children:
- [ { raw: 'the text'
- , data: 'the text'
- , type: 'text'
- }
- ]
- }
-];
-
-})();
View
43 tests/10-singular_attribute.js
@@ -1,43 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Singular attribute";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<option value='foo' selected>";
-exports.expected =
-[ { raw: 'option value=\'foo\' selected'
- , data: 'option value=\'foo\' selected'
- , type: 'tag'
- , name: 'option'
- , attribs: { value: 'foo', selected: 'selected' }
- }
-];
-
-})();
View
50 tests/11-text_outside_tags.js
@@ -1,50 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Text outside tags";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "Line one\n<br>\nline two";
-exports.expected =
-[ { raw: 'Line one\n'
- , data: 'Line one\n'
- , type: 'text'
- }
- , { raw: 'br'
- , data: 'br'
- , type: 'tag'
- , name: 'br'
- }
- , { raw: '\nline two'
- , data: '\nline two'
- , type: 'text'
- }
-];
-
-})();
View
41 tests/12-text_only.js
@@ -1,41 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Only text";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "this is the text";
-exports.expected =
-[ { raw: 'this is the text'
- , data: 'this is the text'
- , type: 'text'
- }
-];
-
-})();
View
49 tests/13-comment_in_text.js
@@ -1,49 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Comment within text";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "this is <!-- the comment --> the text";
-exports.expected =
-[ { raw: 'this is '
- , data: 'this is '
- , type: 'text'
- }
-, { raw: ' the comment '
- , data: ' the comment '
- , type: 'comment'
- }
-, { raw: ' the text'
- , data: ' the text'
- , type: 'text'
- }
-];
-
-})();
View
57 tests/14-comment_in_text_in_script.js
@@ -1,57 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Comment within text within script";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<script>this is <!-- the comment --> the text</script>";
-exports.expected =
-[ { raw: 'script'
- , data: 'script'
- , type: 'script'
- , name: 'script'
- , children:
- [ { raw: 'this is '
- , data: 'this is '
- , type: 'text'
- }
- , { raw: ' the comment '
- , data: ' the comment '
- , type: 'comment'
- }
- , { raw: ' the text'
- , data: ' the text'
- , type: 'text'
- }
-
- ]
- }
-];
-
-})();
View
46 tests/15-non-verbose.js
@@ -1,46 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Option 'verbose' set to 'false'";
-exports.options = {
- handler: { verbose: false }
- , parser: {}
-};
-exports.html = "<\n font \n size='14' \n>the text<\n / \nfont \n>";
-exports.expected =
-[ { type: 'tag'
- , name: 'font'
- , attribs: { size: '14' }
- , children:
- [ { data: 'the text'
- , type: 'text'
- }
- ]
- }
-];
-
-})();
View
71 tests/16-ignore_whitespace.js
@@ -1,71 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Options 'ignoreWhitespace' set to 'true'";
-exports.options = {
- handler: { ignoreWhitespace: true }
- , parser: {}
-};
-exports.html = "Line one\n<br> \t\n<br>\nline two<font>\n <br> x </font>";
-exports.expected =
-[ { raw: 'Line one\n'
- , data: 'Line one\n'
- , type: 'text'
- }
- , { raw: 'br'
- , data: 'br'
- , type: 'tag'
- , name: 'br'
- }
- , { raw: 'br'
- , data: 'br'
- , type: 'tag'
- , name: 'br'
- }
- , { raw: '\nline two'
- , data: '\nline two'
- , type: 'text'
- }
- , { raw: 'font'
- , data: 'font'
- , type: 'tag'
- , name: 'font'
- , children:
- [ { raw: 'br'
- , data: 'br'
- , type: 'tag'
- , name: 'br'
- }
- , { raw: ' x '
- , data: ' x '
- , type: 'text'
- }
- ]
- }
-];
-
-})();
View
38 tests/17-xml_namespace.js
@@ -1,38 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "XML Namespace";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<ns:tag>text</ns:tag>";
-exports.expected =
- [ { raw: 'ns:tag', data: 'ns:tag', type: 'tag', name: 'ns:tag', children: [ { raw: 'text', data: 'text', type: 'text' } ] }
- ];
-
-})();
View
40 tests/18-enforce_empty_tags.js
@@ -1,40 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Enforce empty tags";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.html = "<link>text</link>";
-exports.expected =
- [
- { raw: 'link', data: 'link', type: 'tag', name: 'link' }
- , { raw: 'text', data: 'text', type: 'text' }
- ];
-
-})();
View
41 tests/19-ignore_empty_tags.js
@@ -1,41 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Ignore empty tags";
-exports.options = {
- handler: { enforceEmptyTags: false }
- , parser: {}
-};
-exports.html = "<link>text</link>";
-exports.expected =
- [
- { raw: 'link', data: 'link', type: 'tag', name: 'link', children: [
- { raw: 'text', data: 'text', type: 'text' }
- ] }
- ];
-
-})();
View
120 tests/20-rss.js
@@ -1,120 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "RSS (2.0)";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.type = "rss";
-//http://cyber.law.harvard.edu/rss/examples/rss2sample.xml
-exports.html = '<?xml version="1.0"?>\
-<rss version="2.0">\
- <channel>\
- <title>Liftoff News</title>\
- <link>http://liftoff.msfc.nasa.gov/</link>\
- <description>Liftoff to Space Exploration.</description>\
- <language>en-us</language>\
- <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>\
-\
- <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>\
- <docs>http://blogs.law.harvard.edu/tech/rss</docs>\
- <generator>Weblog Editor 2.0</generator>\
- <managingEditor>editor@example.com</managingEditor>\
- <webMaster>webmaster@example.com</webMaster>\
- <item>\
-\
- <title>Star City</title>\
- <link>http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp</link>\
- <description>How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia\'s &lt;a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm"&gt;Star City&lt;/a&gt;.</description>\
- <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>\
- <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid>\
-\
- </item>\
- <item>\
- <description>Sky watchers in Europe, Asia, and parts of Alaska and Canada will experience a &lt;a href="http://science.nasa.gov/headlines/y2003/30may_solareclipse.htm"&gt;partial eclipse of the Sun&lt;/a&gt; on Saturday, May 31st.</description>\
- <pubDate>Fri, 30 May 2003 11:06:42 GMT</pubDate>\
- <guid>http://liftoff.msfc.nasa.gov/2003/05/30.html#item572</guid>\
-\
- </item>\
- <item>\
- <title>The Engine That Does More</title>\
- <link>http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp</link>\
- <description>Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly. The proposed VASIMR engine would do that.</description>\
- <pubDate>Tue, 27 May 2003 08:37:32 GMT</pubDate>\
- <guid>http://liftoff.msfc.nasa.gov/2003/05/27.html#item571</guid>\
-\
- </item>\
- <item>\
- <title>Astronauts\' Dirty Laundry</title>\
- <link>http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp</link>\
- <description>Compared to earlier spacecraft, the International Space Station has many luxuries, but laundry facilities are not one of them. Instead, astronauts have other options.</description>\
- <pubDate>Tue, 20 May 2003 08:56:02 GMT</pubDate>\
- <guid>http://liftoff.msfc.nasa.gov/2003/05/20.html#item570</guid>\
-\
- </item>\
- </channel>\
-</rss>';
-exports.expected = {
- type: "rss"
- , id: ""
- , title: "Liftoff News"
- , link: "http://liftoff.msfc.nasa.gov/"
- , description: "Liftoff to Space Exploration."
- , updated: new Date("Tue, 10 Jun 2003 09:41:01 GMT")
- , author: "editor@example.com"
- , items: [
- {
- id: "http://liftoff.msfc.nasa.gov/2003/06/03.html#item573"
- , title: "Star City"
- , link: "http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp"
- , description: "How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's &lt;a href=\"http://howe.iki.rssi.ru/GCTC/gctc_e.htm\"&gt;Star City&lt;/a&gt;."
- , pubDate: new Date("Tue, 03 Jun 2003 09:39:21 GMT")
- }
- , {
- id: "http://liftoff.msfc.nasa.gov/2003/05/30.html#item572"
- , description: "Sky watchers in Europe, Asia, and parts of Alaska and Canada will experience a &lt;a href=\"http://science.nasa.gov/headlines/y2003/30may_solareclipse.htm\"&gt;partial eclipse of the Sun&lt;/a&gt; on Saturday, May 31st."
- , pubDate: new Date("Fri, 30 May 2003 11:06:42 GMT")
- }
- , {
- id: "http://liftoff.msfc.nasa.gov/2003/05/27.html#item571"
- , title: "The Engine That Does More"
- , link: "http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp"
- , description: "Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly. The proposed VASIMR engine would do that."
- , pubDate: new Date("Tue, 27 May 2003 08:37:32 GMT")
- }
- , {
- id: "http://liftoff.msfc.nasa.gov/2003/05/20.html#item570"
- , title: "Astronauts' Dirty Laundry"
- , link: "http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp"
- , description: "Compared to earlier spacecraft, the International Space Station has many luxuries, but laundry facilities are not one of them. Instead, astronauts have other options."
- , pubDate: new Date("Tue, 20 May 2003 08:56:02 GMT")
- }
- ]
- };
-
-})();
View
80 tests/21-atom.js
@@ -1,80 +0,0 @@
-(function () {
-
-function RunningInNode () {
- return(
- (typeof require) == "function"
- &&
- (typeof exports) == "object"
- &&
- (typeof module) == "object"
- &&
- (typeof __filename) == "string"
- &&
- (typeof __dirname) == "string"
- );
-}
-
-if (!RunningInNode()) {
- if (!this.Tautologistics)
- this.Tautologistics = {};
- if (!this.Tautologistics.NodeHtmlParser)
- this.Tautologistics.NodeHtmlParser = {};
- if (!this.Tautologistics.NodeHtmlParser.Tests)
- this.Tautologistics.NodeHtmlParser.Tests = [];
- exports = {};
- this.Tautologistics.NodeHtmlParser.Tests.push(exports);
-}
-
-exports.name = "Atom (1.0)";
-exports.options = {
- handler: {}
- , parser: {}
-};
-exports.type = "rss";
-//http://en.wikipedia.org/wiki/Atom_%28standard%29
-exports.html = '<?xml version="1.0" encoding="utf-8"?>\
-\
-<feed xmlns="http://www.w3.org/2005/Atom">\
-\
- <title>Example Feed</title>\
- <subtitle>A subtitle.</subtitle>\
- <link href="http://example.org/feed/" rel="self" />\
- <link href="http://example.org/" />\
- <id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>\
- <updated>2003-12-13T18:30:02Z</updated>\
- <author>\
- <name>John Doe</name>\
- <email>johndoe@example.com</email>\
- </author>\
-\
- <entry>\
- <title>Atom-Powered Robots Run Amok</title>\
- <link href="http://example.org/2003/12/13/atom03" />\
- <link rel="alternate" type="text/html" href="http://example.org/2003/12/13/atom03.html"/>\
- <link rel="edit" href="http://example.org/2003/12/13/atom03/edit"/>\
- <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>\
- <updated>2003-12-13T18:30:02Z</updated>\
- <summary>Some text.</summary>\
- &l