[Pkg-javascript-commits] [node-expat] 144/371: Adding tests for parser reset.
Jonas Smedegaard
dr at jones.dk
Sun Feb 28 09:59:56 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-expat.
commit 95f9904d814e84583329bcaa88017c12a0fcda11
Author: Satyam Shekhar <satyamshekhar at gmail.com>
Date: Mon Apr 9 00:24:37 2012 +0530
Adding tests for parser reset.
---
test.js | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/test.js b/test.js
index 6b5a2dd..8b28781 100644
--- a/test.js
+++ b/test.js
@@ -22,9 +22,13 @@ function collapseTexts(evs) {
}
function expect(s, evs_expected) {
- for(var step = s.length; step > 0; step--) {
+ for(var step = s.length; step > 0; step--) {
+ expectWithParserAndStep(s, evs_expected, new expat.Parser("UTF-8"), step);
+ }
+}
+
+function expectWithParserAndStep(s, evs_expected, p, step) {
var evs_received = [];
- var p = new expat.Parser("UTF-8");
//p.setEncoding("UTF-8");
p.addListener('startElement', function(name, attrs) {
evs_received.push(['startElement', name, attrs]);
@@ -66,7 +70,6 @@ function expect(s, evs_expected) {
var expected = JSON.stringify(evs_expected);
var received = JSON.stringify(collapseTexts(evs_received));
assert.equal(received, expected);
- }
}
vows.describe('node-expat').addBatch({
@@ -170,6 +173,27 @@ vows.describe('node-expat').addBatch({
expect("<&", [['error']]);
}
},
+
+ 'reset': {
+ 'complete doc without error': function() {
+ var p = new expat.Parser("UTF-8");
+ expectWithParserAndStep("<start><first /><second>text</second></start>", [['startElement', 'start', {}], ['startElement', 'first', {}], ['endElement', 'first'], ['startElement', 'second', {}], ['text', "text"], ['endElement', 'second'], ['endElement', 'start']], p, 1000);
+ p.reset();
+ expectWithParserAndStep("<restart><third>moretext</third><fourth /></restart>", [['startElement', 'restart', {}], ['startElement', 'third', {}], ['text', "moretext"], ['endElement', 'third'], ['startElement', 'fourth', {}], ['endElement', 'fourth'], ['endElement', 'restart']], p, 1000);
+ },
+ 'incomplete doc without error': function() {
+ var p = new expat.Parser("UTF-8");
+ expectWithParserAndStep("<start><first /><second>text</second>", [['startElement', 'start', {}], ['startElement', 'first', {}], ['endElement', 'first'], ['startElement', 'second', {}], ['text', "text"], ['endElement', 'second']], p, 1000);
+ p.reset();
+ expectWithParserAndStep("<restart><third>moretext</third><fourth /></restart>", [['startElement', 'restart', {}], ['startElement', 'third', {}], ['text', "moretext"], ['endElement', 'third'], ['startElement', 'fourth', {}], ['endElement', 'fourth'], ['endElement', 'restart']], p, 1000);
+ },
+ 'with doc error': function() {
+ var p = new expat.Parser("UTF-8");
+ expectWithParserAndStep("</end>", [["error"]], p, 1000);
+ p.reset();
+ expectWithParserAndStep("<restart><third>moretext</third><fourth /></restart>", [['startElement', 'restart', {}], ['startElement', 'third', {}], ['text', "moretext"], ['endElement', 'third'], ['startElement', 'fourth', {}], ['endElement', 'fourth'], ['endElement', 'restart']], p, 1000);
+ }
+ },
'stop and resume': {
topic: function() {
var cb = this.callback;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-expat.git
More information about the Pkg-javascript-commits
mailing list