Added tests for jsdoc/src.

This commit is contained in:
Michael Mathews 2010-06-27 20:57:11 +01:00
parent 34214405d5
commit f6f962e847
12 changed files with 75 additions and 68 deletions

View File

@ -1,6 +1,6 @@
{
"app": {
"name": "jsdoc-toolkit-3",
"version": "0.0.0+2010-06-07-2143"
"name": "jsdoc-3",
"version": "0.0.0+2010-06-27-2042"
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<project name="JSDoc Toolkit" default="about">
<project name="JSDoc-3" default="about">
<property file="build/build.properties" />
<property name="build.templates" location="build/templates" />
@ -20,5 +20,18 @@
</filterchain>
</copy>
</target>
<target name="jar">
<delete file="about.json" quiet="true"/>
<copy file="${build.templates}/about.json" tofile="about.json" >
<filterchain>
<replacetokens>
<token key="app.name" value="${app.name}" />
<token key="app.version" value="${app.version}" />
<token key="timestamp" value="${NOW}" />
</replacetokens>
</filterchain>
</copy>
</target>
</project>

View File

@ -1,2 +1,2 @@
app.name=jsdoc-toolkit-3
app.name=jsdoc-3
app.version=0.0.0

23
main.js
View File

@ -1,5 +1,5 @@
/**
* @overview JSDoc Toolkit Version 3
* @overview JSDoc 3
* @copyright 2010 (c) Michael Mathews <micmath@gmail.com>
* @license See LICENSE.md file included in this distribution.
*/
@ -64,17 +64,20 @@
java.lang.System.exit(0);
}
sourceFiles = jsdoc.src.getFilePaths(opts._);
if (opts._.length > 0) {
sourceFiles = jsdoc.src.getFilePaths(opts._);
jsdoc.parser.parseFiles(sourceFiles, opts.encoding);
if (opts.validate) {
var jsonSchema = require('sitepen/jsonSchema');
var jsdocSchema = require('jsdoc/schema').jsdocSchema;
var validation = jsonSchema.validate(jsdoc.parser.result.toObject(), jsdocSchema);
print('Validation: ' + validation.toSource());
jsdoc.parser.parseFiles(sourceFiles, opts.encoding);
if (opts.validate) {
var jsonSchema = require('sitepen/jsonSchema');
var jsdocSchema = require('jsdoc/schema').jsdocSchema;
var validation = jsonSchema.validate(jsdoc.parser.result.toObject(), jsdocSchema);
print('Validation: ' + validation.toSource());
}
print( jsdoc.parser.result.toString(opts.destination) );
}
print( jsdoc.parser.result.toString(opts.destination) );
})();
////

View File

@ -70,7 +70,7 @@
exports.ls = function(dir, recurse, _allFiles, _path) {
var files,
file;
if (typeof _path === 'undefined') { // initially
_allFiles = [];
_path = [dir];
@ -90,7 +90,7 @@
if ((new File(_path.join(slash) + slash + file)).list()) { // it's a directory
_path.push(file);
if (_path.length - 1 < recurse) {
exports.ls(_path.join(slash), recurse, _allFiles, _path);
}

View File

@ -23,10 +23,10 @@ jsdoc.src = (typeof exports === 'undefined')? {} : exports; // like commonjs
*/
jsdoc.src.getFilePaths = function(searchPaths, depth) {
var filePaths = [];
searchPaths = searchPaths || [];
depth = depth || 1;
searchPaths.forEach(function($) {
filePaths = filePaths.concat(fs.ls($, depth));
});

View File

@ -1,50 +0,0 @@
/**
@overview
@author Michael Mathews <micmath@gmail.com>
@license Apache License 2.0 - See file 'LICENSE.md' in this project.
*/
/**
Unit tests runner for JSDoc Toolkit.
@module jsdoc/test
*/
(function() {
exports.runAll = function() {
load(BASEDIR + 'lib/jsunity.js');
testSuites = [];
load(BASEDIR + 'tests/opts.js');
load(BASEDIR + 'tests/docset.js');
load(BASEDIR + 'tests/tag_namespace.js');
load(BASEDIR + 'tests/tag_constructor.js');
load(BASEDIR + 'tests/tag_const.js');
load(BASEDIR + 'tests/tag_enum.js');
load(BASEDIR + 'tests/tag_param.js');
load(BASEDIR + 'tests/tag_example.js');
jsUnity.attachAssertions();
jsUnity.log = function (s) { print(s); };
var results = jsUnity.run.apply(jsUnity, testSuites);
summarize(results);
}
function summarize(results) {
var colorStart,
colorEnd = '\033[m';
print('------------------');
print('Total: ' + results.total + ' tests');
if (results.failed === 0) {
colorStart = '\033[1;37;42m', // green
print(colorStart + 'ALL PASS' + colorEnd);
}
else {
colorStart = '\033[1;37;41m'; // red
print(colorStart + results.failed + 'FAILED' + colorEnd);
}
print('');
}
})();

View File

View File

0
test/samples/src/one.js Normal file
View File

0
test/samples/src/two.js Normal file
View File

View File

@ -16,6 +16,47 @@
expect(jsdoc.src).to(respond_to, 'getFilePaths');
});
});
describe('The return value of jsdoc.src#getFilePaths when called with no arguments', function() {
it('should return an empty array', function() {
var returnedValue = jsdoc.src.getFilePaths();
expect(returnedValue).to(be_an, Array);
expect(returnedValue).to(have_length, 0);
});
});
describe('The return value of jsdoc.src#getFilePaths when called with an array with one src dir and no depth', function() {
it('should return an array of 2 file paths', function() {
var returnedValue = jsdoc.src.getFilePaths(['test/samples/src']);
expect(returnedValue).to(be_an, Array);
expect(returnedValue).to(have_length, 2);
});
it('should contain both js files and not the txt file', function() {
var returnedValue = jsdoc.src.getFilePaths(['test/samples/src']);
expect( returnedValue.indexOf('test/samples/src/one.js') ).to(be_at_least, 0);
expect( returnedValue.indexOf('test/samples/src/two.js') ).to(be_at_least, 0);
expect( returnedValue.indexOf('test/samples/src/ignored.txt') ).to(be_less_than, 0);
});
});
describe('The return value of jsdoc.src#getFilePaths when called with an array with one src dir and depth of 2', function() {
it('should return an array of 3 file paths', function() {
var returnedValue = jsdoc.src.getFilePaths(['test/samples/src'], 2);
expect(returnedValue).to(be_an, Array);
expect(returnedValue).to(have_length, 3);
});
it('should contain all three js files and not the txt file', function() {
var returnedValue = jsdoc.src.getFilePaths(['test/samples/src'], 2);
expect( returnedValue.indexOf('test/samples/src/one.js') ).to(be_at_least, 0);
expect( returnedValue.indexOf('test/samples/src/two.js') ).to(be_at_least, 0);
expect( returnedValue.indexOf('test/samples/src/dir1/three.js') ).to(be_at_least, 0);
expect( returnedValue.indexOf('test/samples/src/ignored.txt') ).to(be_less_than, 0);
});
});
});
})();