[Pkg-javascript-commits] [node-expat] 164/371: integrate stream expat-bench.js into test.js
Jonas Smedegaard
dr at jones.dk
Sun Feb 28 09:59:58 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 5e8a4f1ce0bfb4602bf038864ed3c4009fcf9c99
Author: Astro <astro at spaceboyz.net>
Date: Fri Jun 22 03:15:06 2012 +0200
integrate stream expat-bench.js into test.js
---
expat-bench.js | 10 --------
mystic-library.xml => test-mystic-library.xml | 0
test.js | 36 +++++++++++++++++++++++++++
3 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/expat-bench.js b/expat-bench.js
deleted file mode 100644
index dde437b..0000000
--- a/expat-bench.js
+++ /dev/null
@@ -1,10 +0,0 @@
-var util = require('util'),
- fs = require('fs'),
- expat = require('./lib/node-expat');
-
-var p = expat.createParser();
-var mystic = fs.createReadStream(__dirname + '/mystic-library.xml');
-mystic.pipe(p);
-p.on('startElement', function(name, attr) {
- console.log(name + ' ' + attr)
-})
diff --git a/mystic-library.xml b/test-mystic-library.xml
similarity index 100%
rename from mystic-library.xml
rename to test-mystic-library.xml
diff --git a/test.js b/test.js
index 8b28781..e3c5e2d 100644
--- a/test.js
+++ b/test.js
@@ -2,6 +2,7 @@ var expat = require('./lib/node-expat');
var Buffer = require('buffer').Buffer;
var vows = require('vows');
var assert = require('assert');
+var fs = require('fs');
function collapseTexts(evs) {
var r = [];
@@ -303,5 +304,40 @@ vows.describe('node-expat').addBatch({
p.parse(" ");
assert.equal(p.getCurrentByteIndex(), 2);
},
+ },
+ 'Stream interface': {
+ 'read file': {
+ topic: function() {
+ var p = expat.createParser();
+ this.startTags = 0;
+ p.on('startElement', function(name) {
+ this.startTags++;
+ }.bind(this));
+ this.endTags = 0;
+ p.on('endElement', function(name) {
+ this.endTags++;
+ }.bind(this));
+ p.on('end', function() {
+ this.ended = true;
+ }.bind(this));
+ p.on('close', function() {
+ this.closed = true;
+ this.callback();
+ }.bind(this));
+
+ var mystic = fs.createReadStream(__dirname + '/test-mystic-library.xml');
+ mystic.pipe(p);
+ },
+ 'startElement and endElement events': function() {
+ assert.ok(this.startTags > 0, 'startElement events at all');
+ assert.ok(this.startTags == this.endTags, 'equal amount');
+ },
+ 'end event': function() {
+ assert.ok(this.ended, 'emit end event');
+ },
+ 'close event': function() {
+ assert.ok(this.closed, 'emit close event');
+ }
+ }
}
}).export(module);
--
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