Permalink
Browse files

Updated test grouping and added partially stacked events tests.

  • Loading branch information...
1 parent d40e8c5 commit b81a98181945e48a87382f28abbea22a21e7d7cf @lucsky committed Oct 5, 2013
Showing with 66 additions and 9 deletions.
  1. +3 −0 test/fixtures/simple.xml
  2. +63 −9 test/test.js
View
@@ -3,4 +3,7 @@
<node attr1="node1.attr1" attr2="node1.attr2" />
<node attr1="node2.attr1" attr2="node2.attr2" />
<node attr1="node3.attr1" attr2="node3.attr2" />
+ <node attr1="node4.attr1" attr2="node4.attr2">
+ <subnode />
+ </node>
</root>
View
@@ -6,13 +6,13 @@ var SIMPLE_XML = fs.readFileSync(__dirname + '/fixtures/simple.xml'),
CDATA_XML = fs.readFileSync(__dirname + '/fixtures/cdata.xml'),
MIXED_XML = fs.readFileSync(__dirname + '/fixtures/mixed.xml');
-module.exports.exml = {
+module.exports['node events'] = {
setUp: function(callback) {
this.parser = new exml.Parser();
callback();
},
- 'locale node events': function(test) {
+ 'local': function(test) {
var parser = this.parser;
parser.on('root', function(name, attributes) {
test.equal(name, 'root');
@@ -24,14 +24,17 @@ module.exports.exml = {
test.equal(attributes.attr1, 'node' + nodeIndex + '.attr1');
test.equal(attributes.attr2, 'node' + nodeIndex + '.attr2');
nodeIndex++;
+ parser.on('subnode', function(name) {
+ test.equal(name, 'subnode');
+ });
});
});
parser.end(SIMPLE_XML);
test.done();
},
- 'stacked node events': function(test) {
+ 'stacked': function(test) {
this.parser.on('root', function(name, attributes) {
test.equal(name, 'root');
test.equal(attributes.attr1, 'root.attr1');
@@ -46,11 +49,48 @@ module.exports.exml = {
nodeIndex++;
});
+ this.parser.on('root', 'node', 'subnode', function(name) {
+ test.equal(name, 'subnode');
+ });
+
+ this.parser.end(SIMPLE_XML);
+ test.done();
+ },
+
+ 'partially stacked 1': function(test) {
+ var parser = this.parser;
+ parser.on('root', 'node', function(name, attributes) {
+ test.equal(name, 'node');
+ parser.on('subnode', function(name) {
+ test.equal(name, 'subnode');
+ });
+ });
+
+ this.parser.end(SIMPLE_XML);
+ test.done();
+ },
+
+ 'partially stacked 2': function(test) {
+ var parser = this.parser;
+ parser.on('root', function(name, attributes) {
+ test.equal(name, 'root');
+ parser.on('node', 'subnode', function(name) {
+ test.equal(name, 'subnode');
+ });
+ });
+
this.parser.end(SIMPLE_XML);
test.done();
+ }
+};
+
+module.exports['text events'] = {
+ setUp: function(callback) {
+ this.parser = new exml.Parser();
+ callback();
},
- 'local text events': function(test) {
+ 'local': function(test) {
var parser = this.parser,
index = 1;
@@ -68,7 +108,7 @@ module.exports.exml = {
test.done();
},
- 'stacked text events': function(test) {
+ 'stacked': function(test) {
var index = 1;
this.parser.on('root', 'node', '$text', function(text) {
test.equal(text, 'text content ' + index);
@@ -77,9 +117,16 @@ module.exports.exml = {
this.parser.end(TEXT_XML);
test.done();
+ }
+};
+
+module.exports['cdata events'] = {
+ setUp: function(callback) {
+ this.parser = new exml.Parser();
+ callback();
},
- 'local cdata events': function(test) {
+ 'local': function(test) {
var parser = this.parser,
index = 1;
@@ -97,7 +144,7 @@ module.exports.exml = {
test.done();
},
- 'stacked cdata events': function(test) {
+ 'stacked': function(test) {
var index = 1;
this.parser.on('root', 'node', '$cdata', function(text) {
test.equal(text, 'CDATA content ' + index);
@@ -106,9 +153,16 @@ module.exports.exml = {
this.parser.end(CDATA_XML);
test.done();
+ }
+};
+
+module.exports['mixed content events'] = {
+ setUp: function(callback) {
+ this.parser = new exml.Parser();
+ callback();
},
- 'local mixed content events': function(test) {
+ 'local': function(test) {
var parser = this.parser,
index = 1;
@@ -126,7 +180,7 @@ module.exports.exml = {
test.done();
},
- 'stacked mixed content events': function(test) {
+ 'stacked': function(test) {
var index = 1;
this.parser.on('root', 'node', '$content', function(content) {
test.equal(content, 'Text content followed by some CDATA content ' + index);

0 comments on commit b81a981

Please sign in to comment.