Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

integrate stream expat-bench.js into test.js

  • Loading branch information...
commit 5e8a4f1ce0bfb4602bf038864ed3c4009fcf9c99 1 parent 844aaf8
@astro astro authored
View
10 expat-bench.js
@@ -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)
-})
View
0  mystic-library.xml → test-mystic-library.xml
File renamed without changes
View
36 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);
Please sign in to comment.
Something went wrong with that request. Please try again.