Added JSpec tests.

This commit is contained in:
Michael Mathews 2010-06-27 16:58:20 +01:00
parent e5cf855194
commit 0c577940df
19 changed files with 2071 additions and 1067 deletions

View File

@ -1,7 +1,7 @@
License
=======
JSDoc Toolkit Version 3 is free software.
JSDoc 3 is free software.
Copyright 2010 (c) Michael Mathews <micmath@gmail.com>
@ -21,7 +21,7 @@ In Addition
===========
Third party software is included, used-by or distributed along
with JSDoc Toolkit Version 3. Each is provided under its own license
with JSDoc 3. Each is provided under its own license
and has source available from other locations.
Rhino
@ -81,22 +81,40 @@ http://creativecommons.org/licenses/LGPL/2.1/
http://goessner.net/
http://goessner.net/download/prj/jsonxml/
jsUnity
JSpec
-------
jsUnity is Copyright (c) 2009 Ates Goral
Universal JavaScript Testing Framework v0.6 http://jsunity.com/
JSpec is copyright (c) 2008 - 2010 TJ Holowaychuk tj@vision-media.ca
http://github.com/atesgoral/jsunity
http://github.com/visionmedia/jspec
Licensed under the MIT license
http://www.opensource.org/licenses/mit-license.php
Licensed under the MIT license.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
JSONSchema Validator
--------------------
JSONSchema is copyright (c) 2007 Kris Zyp SitePen (www.sitepen.com)
Licensed under the MIT (MIT-LICENSE.txt) license.
http://github.com/kriszyp/commonjs-utils/blob/master/lib/json-schema.js
http://www.sitepen.com/blog/2010/03/02/commonjs-utilities/
http://www.sitepen.com/blog/2010/03/02/commonjs-utilities/
Licensed under the MIT license.

View File

@ -1,10 +1,13 @@
<project default="clean-build">
<?xml version="1.0" encoding="UTF-8"?>
<project default="clean-install">
<target name="clean">
<delete dir="build"/>
<delete dir="build" />
<delete file="../jsdoc.jar" />
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<mkdir dir="build/classes" />
<javac
srcdir="src" destdir="build/classes"
classpath="./classes/js.jar"
@ -12,14 +15,19 @@
</target>
<target name="jar">
<mkdir dir="build/jar"/>
<mkdir dir="build/jar" />
<jar destfile="build/jar/jsdoc.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="Run"/>
<attribute name="Class-Path" value="./java/classes/js.jar"/>
<attribute name="Main-Class" value="Run" />
<attribute name="Class-Path" value="./java/classes/js.jar" />
</manifest>
</jar>
</target>
<target name="clean-build" depends="clean,compile,jar"/>
<target name="install">
<copy file="build/jar/jsdoc.jar" tofile="../jsdoc.jar" overwrite="true" />
</target>
<target name="clean-install" depends="clean,compile,jar,install" />
</project>

BIN
jsdoc.jar

Binary file not shown.

View File

@ -1,391 +0,0 @@
//<%
/**
* jsUnity Universal JavaScript Testing Framework v0.6
* http://jsunity.com/
*
* Copyright (c) 2009 Ates Goral
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*/
jsUnity = (function () {
function fmt(str) {
var a = Array.prototype.slice.call(arguments, 1);
return str.replace(/\?/g, function () { return a.shift(); });
}
function hash(v) {
if (v instanceof Object) {
var arr = [];
for (var p in v) {
arr.push(p);
arr.push(hash(v[p]));
}
return arr.join("#");
} else {
return String(v);
}
}
var defaultAssertions = {
assertException: function (fn, message) {
try {
fn instanceof Function && fn();
} catch (e) {
return;
}
throw fmt("?: (?) does not raise an exception or not a function",
message || "assertException", fn);
},
assertTrue: function (actual, message) {
if (!actual) {
throw fmt("?: (?) does not evaluate to true",
message || "assertTrue", actual);
}
},
assertFalse: function (actual, message) {
if (actual) {
throw fmt("?: (?) does not evaluate to false",
message || "assertFalse", actual);
}
},
assertIdentical: function (expected, actual, message) {
if (expected !== actual) {
throw fmt("?: (?) is not identical to (?)",
message || "assertIdentical", actual, expected);
}
},
assertNotIdentical: function (expected, actual, message) {
if (expected === actual) {
throw fmt("?: (?) is identical to (?)",
message || "assertNotIdentical", actual, expected);
}
},
assertEqual: function (expected, actual, message) {
if (hash(expected) != hash(actual)) {
throw fmt("?: (?) is not equal to (?)",
message || "assertEqual", actual, expected);
}
},
assertNotEqual: function (expected, actual, message) {
if (hash(expected) == hash(actual)) {
throw fmt("?: (?) is equal to (?)",
message || "assertNotEqual", actual, expected);
}
},
assertMatch: function (re, actual, message) {
if (!re.test(actual)) {
throw fmt("?: (?) does not match (?)",
message || "assertMatch", actual, re);
}
},
assertNotMatch: function (re, actual, message) {
if (re.test(actual)) {
throw fmt("?: (?) matches (?)",
message || "assertNotMatch", actual, re);
}
},
assertTypeOf: function (typ, actual, message) {
if (typeof actual !== typ) {
throw fmt("?: (?) is not of type (?)",
message || "assertTypeOf", actual, typ);
}
},
assertNotTypeOf: function (typ, actual, message) {
if (typeof actual === typ) {
throw fmt("?: (?) is of type (?)",
message || "assertNotTypeOf", actual, typ);
}
},
assertInstanceOf: function (cls, actual, message) {
if (!(actual instanceof cls)) {
throw fmt("?: (?) is not an instance of (?)",
message || "assertInstanceOf", actual, cls);
}
},
assertNotInstanceOf: function (cls, actual, message) {
if (actual instanceof cls) {
throw fmt("?: (?) is an instance of (?)",
message || "assertNotInstanceOf", actual, cls);
}
},
assertNull: function (actual, message) {
if (actual !== null) {
throw fmt("?: (?) is not null",
message || "assertNull", actual);
}
},
assertNotNull: function (actual, message) {
if (actual === null) {
throw fmt("?: (?) is null",
message || "assertNotNull", actual);
}
},
assertUndefined: function (actual, message) {
if (actual !== undefined) {
throw fmt("?: (?) is not undefined",
message || "assertUndefined", actual);
}
},
assertNotUndefined: function (actual, message) {
if (actual === undefined) {
throw fmt("?: (?) is undefined",
message || "assertNotUndefined", actual);
}
},
assertNaN: function (actual, message) {
if (!isNaN(actual)) {
throw fmt("?: (?) is not NaN",
message || "assertNaN", actual);
}
},
assertNotNaN: function (actual, message) {
if (isNaN(actual)) {
throw fmt("?: (?) is NaN",
message || "assertNotNaN", actual);
}
},
fail: function (message) {
throw message || "fail";
}
};
function plural(cnt, unit) {
return cnt + " " + unit + (cnt == 1 ? "" : "s");
}
function splitFunction(fn) {
var tokens =
/^[\s\r\n]*function[\s\r\n]*([^\(\s\r\n]*?)[\s\r\n]*\([^\)\s\r\n]*\)[\s\r\n]*\{((?:[^}]*\}?)+)\}[\s\r\n]*$/
.exec(fn);
if (!tokens) {
throw "Invalid function.";
}
return {
name: tokens[1].length ? tokens[1] : undefined,
body: tokens[2]
};
}
var probeOutside = function () {
try {
return eval(
[ "typeof ", " === \"function\" && ", "" ].join(arguments[0]));
} catch (e) {
return false;
}
};
function parseSuiteString(str) {
var obj = {};
var probeInside = new Function(
splitFunction(probeOutside).body + str);
var tokenRe = /(\w+)/g; // todo: wiser regex
var tokens;
while ((tokens = tokenRe.exec(str))) {
var token = tokens[1];
var fn;
if (!obj[token]
&& (fn = probeInside(token))
&& fn != probeOutside(token)) {
obj[token] = fn;
}
}
return parseSuiteObject(obj);
}
function parseSuiteFunction(fn) {
var fnParts = splitFunction(fn);
var suite = parseSuiteString(fnParts.body);
suite.suiteName = fnParts.name;
return suite;
}
function parseSuiteArray(tests) {
var obj = {};
for (var i = 0; i < tests.length; i++) {
var item = tests[i];
if (!obj[item]) {
switch (typeof item) {
case "function":
var fnParts = splitFunction(item);
obj[fnParts.name] = item;
break;
case "string":
var fn;
if (fn = probeOutside(item)) {
obj[item] = fn;
}
}
}
}
return parseSuiteObject(obj);
}
function parseSuiteObject(obj) {
var suite = new jsUnity.TestSuite(obj.suiteName, obj);
for (var name in obj) {
if (obj.hasOwnProperty(name)) {
var fn = obj[name];
if (typeof fn === "function") {
if (/^test/.test(name)) {
suite.tests.push({ name: name, fn: fn });
} else if (/^setUp|tearDown$/.test(name)) {
suite[name] = fn;
}
}
}
}
return suite;
}
return {
TestSuite: function (suiteName, scope) {
this.suiteName = suiteName;
this.scope = scope;
this.tests = [];
this.setUp = undefined;
this.tearDown = undefined;
},
TestResults: function () {
this.suiteName = undefined;
this.total = 0;
this.passed = 0;
this.failed = 0;
this.duration = 0;
},
assertions: defaultAssertions,
env: {
defaultScope: this,
getDate: function () {
return new Date();
}
},
attachAssertions: function (scope) {
scope = scope || this.env.defaultScope;
for (var fn in jsUnity.assertions) {
scope[fn] = jsUnity.assertions[fn];
}
},
log: function () {},
error: function (s) { this.log("[ERROR] " + s); },
compile: function (v) {
if (v instanceof jsUnity.TestSuite) {
return v;
} else if (v instanceof Function) {
return parseSuiteFunction(v);
} else if (v instanceof Array) {
return parseSuiteArray(v);
} else if (v instanceof Object) {
return parseSuiteObject(v);
} else if (typeof v === "string") {
return parseSuiteString(v);
} else {
throw "Argument must be a function, array, object, string or "
+ "TestSuite instance.";
}
},
run: function () {
var results = new jsUnity.TestResults();
var suiteNames = [];
var start = jsUnity.env.getDate();
for (var i = 0; i < arguments.length; i++) {
try {
var suite = jsUnity.compile(arguments[i]);
} catch (e) {
this.error("Invalid test suite: " + e);
return false;
}
var cnt = suite.tests.length;
this.log("Running "
+ (suite.suiteName || "unnamed test suite"));
this.log(plural(cnt, "test") + " found");
suiteNames.push(suite.suiteName);
results.total += cnt;
for (var j = 0; j < cnt; j++) {
var test = suite.tests[j];
try {
suite.setUp && suite.setUp();
test.fn.call(suite.scope);
suite.tearDown && suite.tearDown();
results.passed++;
this.log("[PASSED] " + test.name);
} catch (e) {
suite.tearDown && suite.tearDown();
this.log("[FAILED] " + test.name + ": " + e);
}
}
}
results.suiteName = suiteNames.join(",");
results.failed = results.total - results.passed;
results.duration = jsUnity.env.getDate() - start;
this.log(plural(results.passed, "test") + " passed");
this.log(plural(results.failed, "test") + " failed");
this.log(plural(results.duration, "millisecond") + " elapsed");
return results;
}
};
})();
//%>

View File

@ -58,7 +58,9 @@
java.lang.System.exit(0);
}
else if (opts.test) {
require('jsdoc/test').runAll();
//require('jsdoc/test').runAll();
load(BASEDIR+'/test/lib/jspec.js');
load(BASEDIR + '/test/runall.js');
java.lang.System.exit(0);
}

View File

@ -30,7 +30,7 @@ var json2xml = (typeof exports === 'undefined')? {} : exports; // like commonjs
if (hasChild) {
for (var m in v) {
if (m == "#text")
xml += lines(v[m]);
xml += makeSafe(v[m]);
else if (m == "#cdata")
xml += "<![CDATA[" + lines(v[m]) + "]]>";
else if (m.charAt(0) != "@")
@ -40,7 +40,7 @@ var json2xml = (typeof exports === 'undefined')? {} : exports; // like commonjs
}
}
else { // added special-character transform, but this needs to be better handled [micmath]
xml += ind + "<" + name + ">" + makeSafe(lines(v.toString())) + "</" + name + ">\n";
xml += ind + "<" + name + ">" + makeSafe(v.toString()) + "</" + name + ">\n";
}
return xml;
},
@ -64,7 +64,7 @@ var json2xml = (typeof exports === 'undefined')? {} : exports; // like commonjs
// xml special charaters
str = str.replace(/</g, '&lt;').replace(/&/g, '&amp;');
return str;
return lines(str);
}
})();

1893
test/lib/jspec.js Executable file

File diff suppressed because it is too large Load Diff

9
test/runall.js Normal file
View File

@ -0,0 +1,9 @@
load(BASEDIR + '/test/tests/01_jsdoc_opts.js');
load(BASEDIR + '/test/tests/02_jsdoc_src.js');
// see http://visionmedia.github.com/jspec/
JSpec.run({
reporter: JSpec.reporters.Terminal,
failuresOnly: false
})
.report();

View File

@ -0,0 +1,98 @@
(function() {
var jsdoc;
JSpec.describe('jsdoc/opts.js', function() {
before_each(function() {
jsdoc = { opts: require('jsdoc/opts') };
});
describe('The object exported by the jsdoc/opts module', function() {
it('should be an object', function() {
expect(jsdoc.opts).to(be_an, Object);
});
it('should have a set method', function() {
expect(jsdoc.opts).to(respond_to, 'set');
});
});
describe('The jsdoc.opts#set method', function() {
it('should return an object', function() {
var returnedValue = jsdoc.opts.set('main.js');
expect(returnedValue).to(be_an, Object);
});
});
describe('The return value of jsdoc.opts#set when called with no arguments', function() {
it('should have a property named `destination`', function() {
var returnedValue = jsdoc.opts.set();
expect(returnedValue).to(have_property, 'destination', 'jsdoc.xml');
});
it('should have a property named `template`', function() {
var returnedValue = jsdoc.opts.set();
expect(returnedValue).to(have_property, 'template', 'default');
});
it('should have a property named `_`', function() {
var returnedValue = jsdoc.opts.set();
expect(returnedValue).to(have_property, '_');
});
});
describe('The default value for the property named `opts._`', function() {
it('should be an empty array', function() {
var returnedValue = jsdoc.opts.set();
expect(returnedValue._).to(be_a, Array);
expect(returnedValue._).to(have_length, 0);
});
});
//// setting the destination option
describe('The return value of jsdoc.opts#set when called with `["-d", "foo/bar.json"]`', function() {
it('should have a property `destination` set to "foo/bar.json"', function() {
var returnedValue = jsdoc.opts.set(['-d', 'foo/bar.json']);
expect(returnedValue.destination).to(be, 'foo/bar.json');
});
});
describe('The return value of jsdoc.opts#set when called with `["--destination", "flib/flub.json"]`', function() {
it('should have a property `destination` set to "flib/flub.json"', function() {
var returnedValue = jsdoc.opts.set(['--destination', 'flib/flub.json']);
expect(returnedValue.destination).to(be, 'flib/flub.json');
});
});
describe('The return value of jsdoc.opts#set when called with `["-d", ""]`', function() {
it('should have a property `destination` set to ""', function() {
var returnedValue = jsdoc.opts.set(['-d', '']);
expect(returnedValue.destination).to(be, '');
});
});
//// setting the template option
describe('The return value of jsdoc.opts#set when called with `["-t", "mytemplate"]`', function() {
it('should have a property `template` set to "mytemplate"', function() {
var returnedValue = jsdoc.opts.set(['-t', 'mytemplate']);
expect(returnedValue.template).to(be, 'mytemplate');
});
});
describe('The return value of jsdoc.opts#set when called with `["--template", "mytemplate"]`', function() {
it('should have a property `template` set to "mytemplate"', function() {
var returnedValue = jsdoc.opts.set(['--template', 'mytemplate']);
expect(returnedValue.template).to(be, 'mytemplate');
});
});
//// setting the _ option
describe('The return value of jsdoc.opts#set when called with `["one", "two"]`', function() {
it('should have a property `_` set to ["one", "two"]', function() {
var returnedValue = jsdoc.opts.set(["one", "two"]);
expect(returnedValue._).to(eql, ["one", "two"]);
});
});
});
})();

View File

@ -0,0 +1,21 @@
(function() {
var jsdoc;
JSpec.describe('jsdoc/src.js', function() {
before_each(function() {
jsdoc = { src: require('jsdoc/src') };
});
describe('The object exported by the jsdoc/src module', function() {
it('should be an object', function() {
expect(jsdoc.src).to(be_an, Object);
});
it('should have a `getFilePaths` method', function() {
expect(jsdoc.src).to(respond_to, 'getFilePaths');
});
});
});
})();

View File

@ -1,77 +0,0 @@
(function() {
var jsdoc = { parser: require('jsdoc/parser') };
jsdoc.parser.parseFiles(BASEDIR + 'tests/docset.js');
var docset = jsdoc.parser.result;
var testSuite = {
suiteName: 'docset',
setUp: function() {
},
tearDown: function() {
},
testDocsetGetMethodDocsByPath: function() {
var docs = docset.getDocsByPath('Shape');
assertEqual(docs.length, 1, 'All constructor doclets by that path name are found.');
assertEqual(docs[0].tagText('isa'), 'constructor', 'The found constructor doclet has the correct isa.');
assertEqual(docs[0].tagText('name'), 'Shape', 'The found constructor doclet has the correct name.');
assertEqual(docs[0].tagText('memberof'), '', 'The found constructor doclet has the correct memberof.');
docs = docset.getDocsByPath('Shape#init');
assertEqual(docs.length, 1, 'All instance method doclets by that path name are found.');
assertEqual(docs[0].tagText('isa'), 'method', 'The found instance method doclet has the correct isa.');
assertEqual(docs[0].tagText('name'), 'init', 'The found instance method doclet has the correct name.');
assertEqual(docs[0].tagText('memberof'), 'Shape#', 'The found instance method doclet has the correct memberof.');
docs = docset.getDocsByPath('Shape.validate');
assertEqual(docs.length, 1, 'All static method doclets by that path name are found.');
assertEqual(docs[0].tagText('isa'), 'method', 'The found static method doclet has the correct isa.');
assertEqual(docs[0].tagText('name'), 'validate', 'The found static method doclet has the correct name.');
assertEqual(docs[0].tagText('memberof'), 'Shape', 'The found static method doclet has the correct memberof.');
},
testDocsetGetEventDocsByPath: function() {
var docs = docset.getDocsByPath('Shape#event:init');
assertEqual(docs.length, 1, 'All instance event doclets by that path name are found.');
assertEqual(docs[0].tagText('isa'), 'event', 'The found instance event doclet has the correct isa.');
assertEqual(docs[0].tagText('name'), 'init', 'The found instance event doclet has the correct name.');
assertEqual(docs[0].tagText('memberof'), 'Shape#', 'The found instance event doclet has the correct memberof.');
docs = docset.getDocsByPath('Shape.event:validate');
assertEqual(docs.length, 1, 'All static event doclets by that path name are found.');
assertEqual(docs[0].tagText('isa'), 'event', 'The found static event doclet has the correct isa.');
assertEqual(docs[0].tagText('name'), 'validate', 'The static instance event doclet has the correct name.');
assertEqual(docs[0].tagText('memberof'), 'Shape', 'The static instance event doclet has the correct memberof.');
}
};
testSuites.push(testSuite);
})();
function sample() {
/** @constructor */
function Shape() {
}
/** @method */
Shape.validate = function(shape) {};
/** @event Shape.validate */
addEvent(Shape, 'validate');
/** @method */
Shape.prototype.init = function(opts) {};
/** @event Shape#event:init */
addEvent(Shape.prototype, 'init');
}

View File

@ -1,35 +0,0 @@
(function() {
var jsdoc = { opts: require('jsdoc/opts') };
var testSuite = {
suiteName: 'jsdoc/opts',
setUp: function() {
},
tearDown: function() {
},
testOptsApi: function() {
assertEqual(typeof jsdoc.opts.set, 'function');
},
testOptsSetDefault: function() {
var opts = jsdoc.opts.set();
assertEqual(typeof opts, 'object');
assertEqual(typeof opts.destination, 'string');
assertEqual(opts.destination, 'jsdoc.xml');
},
testOptsSet: function() {
var opts = jsdoc.opts.set(['-d', 'mydestination.json']);
assertEqual(typeof opts, 'object');
assertEqual(typeof opts.destination, 'string');
assertEqual(opts.destination, 'mydestination.json');
}
};
testSuites.push(testSuite);
})();

View File

@ -1,78 +0,0 @@
(function() {
var jsdoc = { parser: require('jsdoc/parser') };
jsdoc.parser.parseFiles(BASEDIR + 'tests/tag_const.js');
var docset = jsdoc.parser.result;
var testSuite = {
suiteName: 'tag_const',
setUp: function() {
},
tearDown: function() {
},
testConstDocs: function() {
assertEqual(typeof docset, 'object');
},
testConstCompactTag: function() {
var docs = docset.getDocsByPath('pi');
assertEqual(docs.length, 1, '1 doclet by that name is found.');
var doc = docs[0].toObject();
assertEqual(typeof doc, 'object', 'The found doclet is an object.');
assertEqual(doc.path, 'pi', 'The found doclet has the expected path.');
assertEqual(doc.type, 'number', 'The found doclet has the expected type.');
assertEqual(doc.desc, "The ratio of any circle's circumference to its diameter.", 'The found doclet has the expected desc.');
},
testConstCompactVerbose: function() {
var doc = docset.getDocsByPath('e');
assertEqual(doc.length, 1, '1 doclet by that name is found.');
doc = doc[0];
assertEqual(typeof doc, 'object', 'The found doclet is an object.');
assertEqual(doc.tagText('path'), 'e', 'The found doclet has the expected path.');
assertEqual(doc.tagText('type'), 'number', 'The found doclet has the expected type.');
assertEqual(doc.tagText('desc'), "Euler's number.", 'The found doclet has the expected desc.');
},
testConstCodename: function() {
var doc = docset.getDocsByPath('c');
assertEqual(doc.length, 1, '1 doclet by that name is found.');
doc = doc[0];
assertEqual(typeof doc, 'object', 'The found doclet is an object.');
assertEqual(doc.tagText('path'), 'c', 'The found doclet has the expected path.');
assertEqual(doc.tagText('type'), 'number', 'The found doclet has the expected type.');
assertEqual(doc.tagText('desc'), "Speed of light(m/s)", 'The found doclet has the expected desc.');
}
};
testSuites.push(testSuite);
})();
function sample() {
/**
* @const {number} pi The ratio of any circle's circumference to its diameter.
*/
/**
* Euler's number.
* @const {number} e
*/
/**
* Speed of light(m/s)
* @const {number}
*
*/
var c = 299792458; // <- name will be found here
}

View File

@ -1,113 +0,0 @@
(function() {
var jsdoc = { parser: require('jsdoc/parser') };
jsdoc.parser.parseFiles(BASEDIR + 'tests/tag_constructor.js');
var docset = jsdoc.parser.result;
var testSuite = {
suiteName: 'tag_constructor',
setUp: function() {
},
tearDown: function() {
},
testConstructorDocs: function() {
assertEqual(typeof docset, 'object');
},
testConstructorCompactTag: function() {
var doc = docset.getDocsByPath('Triangle');
assertEqual(doc.length, 1, '1 doclet by that name is found.');
doc = doc[0];
assertEqual(typeof doc, 'object', 'The found doclet is an object.');
assertEqual(doc.tagText('name'), 'Triangle', 'The found doclet has the expected name.');
assertEqual(doc.tagText('path'), 'Triangle', 'The found doclet has the expected path.');
assertEqual(doc.tagText('isa'), 'constructor', 'The found doclet has the expected isa.');
assertEqual(doc.tagText('desc'), 'A three-sided polygon.', 'The found doclet has the expected desc.');
},
testConstructorFromCode: function() {
var doc = docset.getDocsByPath('shapes.Quadrilateral');
assertEqual(doc.length, 1, '1 doclet by that name is found.');
doc = doc[0];
assertEqual(typeof doc, 'object', 'The found doclet is an object.');
assertEqual(doc.tagText('path'), 'shapes.Quadrilateral', 'The found doclet has the expected path.');
assertEqual(doc.tagText('name'), 'Quadrilateral', 'The found doclet has the expected name.');
assertEqual(doc.tagText('memberof'), 'shapes', 'The found doclet has the expected memberof.');
assertEqual(doc.tagText('desc'), '', 'The found doclet has the expected desc.');
},
testConstructorBeforeVar: function() {
var doc = docset.getDocsByPath('Polygon');
assertEqual(doc.length, 1, '1 doclet by that name is found.');
doc = doc[0];
assertEqual(typeof doc, 'object', 'The found doclet is an object.');
assertEqual(doc.tagText('path'), 'Polygon', 'The found doclet has the expected path.');
assertEqual(doc.tagText('name'), 'Polygon', 'The found doclet has the expected name.');
assertEqual(doc.tagText('memberof'), '', 'The found doclet has the expected memberof.');
assertEqual(doc.tagText('desc'), 'Jsdoc is before the `var`.', 'The found doclet has the expected desc.');
},
testConstructorNested: function() {
var doc = docset.getDocsByPath('Polygon#Rhombus');
assertEqual(doc.length, 1, '1 doclet by that name is found.');
doc = doc[0];
assertEqual(typeof doc, 'object', 'The found doclet is an object.');
assertEqual(doc.tagText('path'), 'Polygon#Rhombus', 'The found doclet has the expected path.');
assertEqual(doc.tagText('name'), 'Rhombus', 'The found doclet has the expected name.');
assertEqual(doc.tagText('memberof'), 'Polygon#', 'The found doclet has the expected memberof.');
assertEqual(doc.tagText('isa'), 'constructor', 'The found doclet has the expected isa.');
},
testConstructorInVarList: function() {
var doc = docset.getDocsByPath('Trapezoid');
assertEqual(doc.length, 1, '1 doclet by that name is found.');
doc = doc[0];
assertEqual(typeof doc, 'object', 'The found doclet is an object.');
}
};
testSuites.push(testSuite);
})();
function sample() {
/**@constructor Triangle A three-sided polygon.*/
/**
* A four-sided polygon having equal-length sides meeting at right angles.
* @constructor
* @name Square
*/
someIgnoredCode = function() {}
/** @constructor */
shapes.Quadrilateral = new Klass("shapes", "Quadrilateral");
/**
Jsdoc is before the `var`.
@constructor
*/
var Polygon = function() {
/** A nested constructor
@constructor
*/
this.Rhombus = function () {}
},
/**
In a list of vars.
@constructor
*/
Trapezoid = function() {};
}

View File

@ -1,89 +0,0 @@
(function() {
var jsdoc = { parser: require('jsdoc/parser') };
jsdoc.parser.parseFiles(BASEDIR + 'tests/tag_enum.js');
var docset = jsdoc.parser.result;
var testSuite = {
suiteName: 'tag_enum',
setUp: function() {
},
tearDown: function() {
},
testEnumDocs: function() {
assertEqual(typeof docset, 'object');
},
testEnumCompactTag: function() {
var doc = docset.getDocsByPath('buttons');
assertEqual(doc.length, 1, '1 doclet by that name is found.');
doc = doc[0];
assertEqual(typeof doc, 'object', 'The found doclet is an object.');
assertEqual(doc.tagText('path'), 'buttons', 'The found doclet has the expected path.');
assertEqual(doc.tagText('type'), 'string', 'The found doclet has the expected type.');
assertEqual(doc.tagText('desc'), 'Text equivalents for editor buttons.', 'The found doclet has the expected desc.');
},
testEnumCompactMembers: function() {
var doc = docset.getDocsByPath('replies');
assertEqual(doc.length, 1, '1 doclet by that name replies is found.');
doc = docset.getDocsByPath('replies.YES');
assertEqual(doc.length, 1, '1 doclet by that name YES is found.');
doc = doc[0];
assertEqual(doc.tagText('memberof'), 'replies', 'The found doclet is a member of the enum.');
doc = docset.getDocsByPath('replies.NO');
assertEqual(doc.length, 1, '1 doclet by that name NO is found.');
},
testEnumThis: function() {
var doc = docset.getDocsByPath('Chart#colors');
assertEqual(doc.length, 1, '1 doclet by that name is found.');
}
};
testSuites.push(testSuite);
})();
function sample() {
/** @enum {string} buttons Text equivalents for editor buttons. */
this['buttons'] = { BOLD: 'B', ITALIC: 'I', CLOSE: 'X' };
/**
Valid replies.
@enum
*/
var replies = {
/** A positive response. */
YES: 1,
/** A negative response. */
NO: -1,
/** An uncertain response */
MAYBE: 0
}
/** @constructor */
function Chart() {
/**
Valid colors.
@enum {string}
*/
this.colors = {
RED: '#F00',
BLUE: '#00F',
GREEN: '#0F0'
}
}
}

View File

@ -1,47 +0,0 @@
(function() {
var jsdoc = { parser: require('jsdoc/parser') };
jsdoc.parser.parseFiles(BASEDIR + 'tests/tag_example.js');
var docset = jsdoc.parser.result;
var testSuite = {
suiteName: 'tag_example',
setUp: function() {
},
tearDown: function() {
},
testExample: function() {
var docs = docset.getDocsByPath('rotate');
assertEqual(docs.length, 1, 'All doclets by that path name are found.');
var doc = docs[0].toObject(),
examples = doc.example;
assertEqual(typeof examples, 'object', 'The doclet has examples.');
assertEqual(examples.length, 2, 'The doclet has the expected number of examples.');
assertEqual(examples[0], ' var myShape = new Shape();\n rotate(myShape, 90, {0, 0});\n', 'The doclet has the expected text.');
assertEqual(examples[1], '{key: rotate(myShape, -45) } // thats not a type expression\n', 'The doclet has the expected text when braces are at the start.');
}
};
testSuites.push(testSuite);
})();
function sample() {
/**
* @method
* @example
* var myShape = new Shape();
* rotate(myShape, 90, {0, 0});
* @example {key: rotate(myShape, -45) } // thats not a type expression
*/
function rotate(shape, deg, axis) {
}
}

View File

@ -1,41 +0,0 @@
(function() {
var jsdoc = { parser: require('jsdoc/parser') };
jsdoc.parser.parseFiles(BASEDIR + 'tests/tag_namespace.js');
var docset = jsdoc.parser.result;
var testSuite = {
suiteName: 'tag_namespace',
setUp: function() {
},
tearDown: function() {
},
testNsDocs: function() {
assertEqual(typeof docset, 'object');
},
testNsCompactTag: function() {
var doc = docset.getDocsByPath('polygons');
assertEqual(doc.length, 1, '1 doclet by that name is found.');
},
testNsNested: function() {
var doc = docset.getDocsByPath('polygons.quadrilaterals');
assertEqual(doc.length, 1, '1 doclet by that name is found.');
}
};
testSuites.push(testSuite);
})();
function sample() {
/** @namespace polygons Closed figure made by joining line segments. */
this['polygons'] = {};
/** @namespace */
polygons.quadrilaterals = {};
}

View File

@ -1,131 +0,0 @@
(function() {
var jsdoc = { parser: require('jsdoc/parser') };
jsdoc.parser.parseFiles(BASEDIR + 'tests/tag_param.js');
var docset = jsdoc.parser.result;
var testSuite = {
suiteName: 'tag_param',
setUp: function() {
},
tearDown: function() {
},
testParamWithSimpleType: function() {
var docs = docset.getDocsByPath('Shape');
assertEqual(docs.length, 1, 'All constructor doclets by that path name are found.');
var doc = docs[0].toObject(),
params = doc.param;
//print('>>> doc is '+doc.toSource());
//print('>>> params is '+params.toSource());
assertEqual(params[0].name, 'top', 'The found parameter has the correct name.');
assertEqual(typeof params[0].type, 'object', 'The found parameter has types.');
assertEqual(params[0].type.length, 1, 'The found parameter has the correct number of types.');
assertEqual(params[0].type[0], 'number', 'The found parameter has the correct type value.');
},
testParamWithNullableType: function() {
var docs = docset.getDocsByPath('Shape');
assertEqual(docs.length, 1, 'All constructor doclets by that path name are found.');
var doc = docs[0].toObject(),
params = doc.param;
assertEqual(params[1].name, 'left', 'The found parameter has the correct name.');
assertEqual(typeof params[1].type, 'object', 'The found parameter has types.');
assertEqual(params[1].type.length, 1, 'The found parameter has the correct number of types.');
assertEqual(params[1].type[0], 'number', 'The found parameter has the correct type value.');
assertEqual(params[1].nullable, false, 'The found parameter has the correct !nullable value.');
assertEqual(params[2].nullable, true, 'The found parameter has the correct ?nullable value.');
},
testParamWithOptionalType: function() {
var docs = docset.getDocsByPath('Shape');
assertEqual(docs.length, 1, 'All doclets by that path name are found.');
var doc = docs[0].toObject(),
params = doc.param;
assertEqual(params[3].name, 'fixed', 'The found parameter has the correct name.');
assertEqual(typeof params[1].type, 'object', 'The found parameter has types.');
assertEqual(params[3].type.length, 1, 'The found parameter has the correct number of types.');
assertEqual(params[3].type[0], 'boolean', 'The found parameter has the correct type value.');
assertEqual(params[3].nullable, undefined, 'The found parameter has the default nullable value.');
assertEqual(params[3].optional, true, 'The found parameter has the correct optional value.');
},
testParamWithMultipleType: function() {
var docs = docset.getDocsByPath('rotate');
assertEqual(docs.length, 1, 'All doclets by that path name are found.');
var doc = docs[0].toObject(),
params = doc.param;
assertEqual(params[0].name, 'deg', 'The found parameter has the correct name.');
assertEqual(typeof params[0].type, 'object', 'The found parameter has types.');
assertEqual(params[0].type.length, 2, 'The found parameter has the correct number of types.');
assertEqual(params[0].type[0], 'Degree', 'The found parameter has the correct type[0] value.');
assertEqual(params[0].type[1], 'number', 'The found parameter has the correct type[1] value.');
assertEqual(params[1].name, 'axis', 'The found parameter has the correct name.');
assertEqual(params[1].optional, true, 'The found parameter has the correct optional.');
},
testParamDesc: function() {
var docs = docset.getDocsByPath('label');
assertEqual(docs.length, 1, 'All doclets by that path name are found.');
var doc = docs[0].toObject(),
param = doc.param;
assertEqual(typeof param, 'object', 'The found parameter has the expected type.');
assertEqual(param.name, 'labelText', 'The found parameter has the correct name.');
assertEqual(typeof param.type, 'object', 'The found parameter has types.');
assertEqual(param.type.length, 2, 'The found parameter has the correct number of types.');
assertEqual(param.type[0], 'Function', 'The found parameter has the correct type[0] value.');
assertEqual(param.type[1], 'string', 'The found parameter has the correct type[1] value.');
assertEqual(param.desc, 'A number\n or a function.', 'The found parameter has the expected description.');
assertEqual(param.defaultvalue, '"hello world"', 'The found parameter has the expected defaultvalue.');
}
};
testSuites.push(testSuite);
})();
function sample() {
/** @constructor
@param {number} top
@param {!number} left
@param {?number} sides
@param {boolean=} fixed
*/
function Shape(top, left, sides, fixed) {
}
/** @method
@param {Degree|number} deg
@param [axis]
*/
function rotate(deg, axis) {
}
/** @method
@param { Function | string } [ labelText = "hello world" ] A number
or a function.
*/
function label(labelText) {
}
}

View File

@ -1,43 +0,0 @@
(function() {
var jsdoc = { parser: require('jsdoc/parser') };
jsdoc.parser.parseFiles(BASEDIR + 'tests/tag_returns.js');
var docset = jsdoc.parser.result;
var testSuite = {
suiteName: 'tag_returns',
setUp: function() {
},
tearDown: function() {
},
testExample: function() {
var docs = docset.getDocsByPath('data');
assertEqual(docs.length, 1, 'All doclets by that path name are found.');
var doc = docs[0].toObject(),
returns = doc.returns;
assertEqual(typeof returns, 'object', 'The doclet has examples.');
assertEqual(returns.length, 2, 'The doclet has the expected number of examples.');
assertEqual(returns[0].text, 'blah blah', 'The tag has the expected text.');
assertEqual(returns[1].type, 'boolean', 'The tag has the expected type.');
}
};
testSuites.push(testSuite);
})();
function sample() {
/**
* @method
* @returns {boolean}
*/
function data(name, value) {
}
}