'use strict';

/**
 * Run package tests.
 * (C) 2013 Alex Fernández.
 */

// requires
var testing = require('testing');


/**
 * Test that a new object is clean: has no functions.
 * Same for string and array.
 */
function testCleanObjects(callback)
{
	var object = {};
	for (var key in object)
	{
		testing.fail('New object has attribute %s', key, callback);
	}
	var string = '';
	for (key in string)
	{
		testing.fail('New string has attribute %s', key, callback);
	}
	testing.success(callback);
}

/**
 * Run all module tests.
 */
exports.test = function(callback)
{
	var tests = {
		cleanObjects: testCleanObjects,
	};
	var files = [ 'core', 'string', 'array', 'math', 'object' ];
	files.forEach(function(file)
	{
		tests[file] = require('./test/' + file + '.js').test;
	});
	testing.run(tests, callback);
};

// run tests if invoked directly
if (__filename == process.argv[1])
{
	exports.test(testing.show);
}


'use strict';

/**
 * Run package tests.
 * (C) 2013 Alex Fernández.
 */

// requires
var testing = require('testing');
var _prettyPrint = require('util').inspect;


/**
 * Test that new objects, strings, arrays, numbers
 * and regular expressions have no enumerable properties.
 */
function testCleanObjects(callback)
{
	_assertIsClean({}, callback);
	_assertIsClean('', callback);
	_assertIsClean([], callback);
	_assertIsClean(41.5, callback);
	_assertIsClean(/abc/, callback);

	testing.success(callback);
}

function _assertIsClean(newObject, callback) {
    for (var key in newObject) {
		testing.failure('New object ' +
			_prettyPrint(newObject) +
			' has enumerable property %s', key, callback);
    }
}

/**
 * Run all module tests.
 */
exports.test = function(callback)
{
	var tests = {
		cleanObjects: testCleanObjects,
	};
	var files = [ 'core', 'string', 'array', 'math', 'object' ];
	files.forEach(function(file)
	{
		tests[file] = require('./test/' + file + '.js').test;
	});
	testing.run(tests, callback);
};

// run tests if invoked directly
if (__filename == process.argv[1])
{
	exports.test(testing.show);
}


Complete tests for checking that no new enumerable properties are being added to new objects.
Complete tests for checking that no new enumerable properties are being added to new objects.

Added tests for array, number and regexp.
Extracted assertion to its own method.
