xml-writer
Version:
Native and full Javascript implementation of the classic XMLWriter class
57 lines (49 loc) • 1.61 kB
JavaScript
var XMLWriter = require('../');
exports['setUp'] = function (callback) {
this.xw = new XMLWriter();
callback();
};
exports['t01'] = function (test) {
this.xw.startElement(function() {return 'toto'}).text(function() {return 'titi'});
test.equal(this.xw.toString(), '<toto>titi</toto>');
test.done();
};
exports['t02'] = function (test) {
test.throws(function(){this.xw.startElement('<>')});
test.done();
};
exports['t03'] = function (test) {
this.xw.startElement('foo').text('<toto>');
test.equal(this.xw.toString(), '<foo><toto></foo>');
test.done();
};
exports['t03b'] = function (test) {
this.xw.startElement('foo').text('un & deux & troie');
test.equal(this.xw.toString(), '<foo>un & deux & troie</foo>');
test.done();
};
exports['t04'] = function (test) {
this.xw.startElement('foo').writeAttribute('toto','"');
test.equal(this.xw.toString(), '<foo toto="""/>');
test.done();
};
exports['t05'] = function (test) {
this.xw.startElement('foo').writeAttribute('toto','&');
test.equal(this.xw.toString(), '<foo toto="&"/>');
test.done();
};
exports['t06'] = function (test) {
this.xw.startElement('foo').writeAttribute('toto','&');
test.equal(this.xw.toString(), '<foo toto="&"/>');
test.done();
};
exports['t07'] = function (test) {
this.xw.startElement('foo').writeAttribute('toto','"&');
test.equal(this.xw.toString(), '<foo toto=""&"/>');
test.done();
};
exports['t08'] = function (test) {
this.xw.startElement('foo').text('<to&to>');
test.equal(this.xw.toString(), '<foo><to&to></foo>');
test.done();
};