/* * Utilities: A classic collection of JavaScript utilities * Copyright 2112 Matthew Eernisse (mde@fleegix.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ var XML = require('../lib/xml').XML , assert = require('assert') , obj , xml , res , serialize , tests; serialize = function (o) { return XML.stringify(o, {whitespace: false}); }; tests = { 'test serialized object': function () { obj = {foo: 'bar'}; xml = serialize(obj); res = 'bar'; assert.equal(res, xml); } , 'test array of numbers': function () { obj = [1, 2, 3]; xml = serialize(obj); res = '123'; assert.equal(res, xml); } , 'test array of strings': function () { obj = ['foo', 'bar']; xml = serialize(obj); res = 'foobar'; assert.equal(res, xml); } , 'test array of mixed datatypes': function () { obj = ['foo', 1]; xml = serialize(obj); res = 'foo1'; assert.equal(res, xml); } , 'test array property of an object': function () { obj = {foo: ['bar', 'baz']}; xml = serialize(obj); res = 'barbaz'; assert.equal(res, xml); } , 'test setIndentLevel for xml': function () { var data = XML.setIndentLevel(5) , actual = 5; assert.equal(actual, data) } , 'test stringify with object for xml': function () { var data = XML.stringify({user: 'name'}) , actual = '\n\n name\n\n'; assert.equal(actual, data) } , 'test stringify with array for xml': function () { var data = XML.stringify(['user']) , actual = '\n\n\ user\n'; assert.equal(actual, data) } , 'test stringify with object and no whitespace for xml': function () { var data = XML.stringify({user: 'name'}, {whitespace: false}) , actual = 'name'; assert.equal(actual, data) } , 'test stringify with object and name for xml': function () { var data = XML.stringify({user: 'name'}, {name: 'omg'}) , actual = '\n\nname\n\n'; assert.equal(actual, data) } , 'test stringify with object and fragment for xml': function () { var data = XML.stringify({user: 'name'}, {fragment: true}) , actual = '\nname\n\n'; assert.equal(actual, data) } , 'test stringify with object for xml': function () { var data = XML.stringify({user: 'name'}, {level: 1}) , actual = '\n name\n'; assert.equal(actual, data) } , 'test stringify with array and no arrayRoot for xml': function () { var data = XML.stringify(['user'], {arrayRoot: false}) , actual = '\n\n\ user\n'; assert.equal(actual, data) } }; module.exports = tests;