Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #88 from stephenmathieson/master

fix properties (ctx.string)
  • Loading branch information...
commit 1c4032e43ad59b02ca116d0f607b516f26f51885 2 parents e88f133 + 65d8090
@tj authored
Showing with 75 additions and 21 deletions.
  1. +5 −1 lib/dox.js
  2. +47 −20 test/dox.test.js
  3. +23 −0 test/fixtures/prototypes.js
View
6 lib/dox.js
@@ -270,7 +270,7 @@ exports.parseCodeContext = function(str){
, cons: RegExp.$1
, name: RegExp.$2
, value: RegExp.$3
- , string: RegExp.$1 + '.prototype' + RegExp.$2
+ , string: RegExp.$1 + '.prototype.' + RegExp.$2
};
// method
} else if (/^([\w.]+)\.(\w+)[ \t]*=[ \t]*function/.exec(str)) {
@@ -297,5 +297,9 @@ exports.parseCodeContext = function(str){
, value: RegExp.$2
, string: RegExp.$1
};
+ // result of iffe
+ // amaze.lib.indexOf = (function () {
+ } else if (/[ \t]*=[ \t]*\(function/.exec(str)) {
+
}
};
View
67 test/dox.test.js
@@ -15,7 +15,7 @@ module.exports = {
'test .version': function(){
dox.version.should.match(/^\d+\.\d+\.\d+$/);
},
-
+
'test .parseComments() blocks': function(done){
fixture('a.js', function(err, str){
var comments = dox.parseComments(str)
@@ -35,7 +35,7 @@ module.exports = {
done();
});
},
-
+
'test .parseComments() tags': function(done){
fixture('b.js', function(err, str){
var comments = dox.parseComments(str);
@@ -111,14 +111,14 @@ module.exports = {
parseComment.description.body.should.equal('<h2>The comment object returned contains the following</h2>\n\n<ul>\n<li><code>tags</code> array of tag objects</li>\n<li><code>description</code> the first line of the comment</li>\n<li><code>body</code> lines following the description</li>\n<li><code>content</code> both the description and the body</li>\n<li><code>isPrivate</code> true when "@api private" is used</li>\n</ul>');
var parseTag = comments.shift();
-
+
// Should be the comment be parsed ?
var shouldNotFail = comments.shift();
var parseTagTypes = comments.shift();
parseTagTypes.tags.should.have.length(3);
parseTagTypes.description.full.should.equal('<p>Parse tag type string \"{Array|Object}\" etc.</p>');
-
+
var escape = comments.pop();
escape.tags.should.have.length(3);
escape.description.full.should.equal('<p>Escape the given <code>html</code>.</p>');
@@ -127,7 +127,34 @@ module.exports = {
done();
});
},
-
+
+ 'test .parseComments() prototypes': function (done){
+ fixture('prototypes.js', function(err, str){
+ var comments = dox.parseComments(str)
+
+ comments.should.be.an.instanceOf(Array);
+ comments.should.have.lengthOf(3);
+
+ // constructor
+ comments[0].description.full.should.equal('<p>Does a lot of foo</p>');
+ comments[0].ctx.type.should.be.equal('function');
+ comments[0].ctx.name.should.be.equal('Foo');
+ comments[0].ctx.string.should.be.equal('Foo()');
+
+ comments[1].description.full.should.equal('<p>A property of an instance of Foo</p>');
+ comments[1].ctx.type.should.be.equal('property');
+ comments[1].ctx.name.should.be.equal('property');
+ comments[1].ctx.string.should.be.equal('Foo.prototype.property');
+
+ comments[2].description.full.should.equal('<p>A method of an instance of Foo</p>');
+ comments[2].ctx.type.should.be.equal('method');
+ comments[2].ctx.name.should.be.equal('method');
+ comments[2].ctx.string.should.be.equal('Foo.prototype.method()');
+
+ done();
+ });
+ },
+
'test .parseComments() tags': function (done){
fixture('d.js', function(err, str){
var comments = dox.parseComments(str);
@@ -143,7 +170,7 @@ module.exports = {
done();
});
},
-
+
'test .parseComments() code': function(done){
fixture('b.js', function(err, str){
var comments = dox.parseComments(str)
@@ -171,20 +198,20 @@ module.exports = {
ctx.type.should.equal('function');
ctx.name.should.equal('foo');
},
-
+
'test .parseCodeContext() function expression': function(){
var ctx = dox.parseCodeContext('var foo = function(){\n\n}');
ctx.type.should.equal('function');
ctx.name.should.equal('foo');
},
-
+
'test .parseCodeContext() prototype method': function(){
var ctx = dox.parseCodeContext('User.prototype.save = function(){}');
ctx.type.should.equal('method');
ctx.constructor.should.equal('User');
ctx.name.should.equal('save');
},
-
+
'test .parseCodeContext() prototype property': function(){
var ctx = dox.parseCodeContext('Database.prototype.enabled = true;\nasdf');
ctx.type.should.equal('property');
@@ -192,14 +219,14 @@ module.exports = {
ctx.name.should.equal('enabled');
ctx.value.should.equal('true');
},
-
+
'test .parseCodeContext() method': function(){
var ctx = dox.parseCodeContext('user.save = function(){}');
ctx.type.should.equal('method');
ctx.receiver.should.equal('user');
ctx.name.should.equal('save');
},
-
+
'test .parseCodeContext() property': function(){
var ctx = dox.parseCodeContext('user.name = "tj";\nasdf');
ctx.type.should.equal('property');
@@ -207,7 +234,7 @@ module.exports = {
ctx.name.should.equal('name');
ctx.value.should.equal('"tj"');
},
-
+
'test .parseCodeContext() declaration': function(){
var ctx = dox.parseCodeContext('var name = "tj";\nasdf');
ctx.type.should.equal('declaration');
@@ -219,35 +246,35 @@ module.exports = {
var tag = dox.parseTag('@constructor');
tag.type.should.equal('constructor');
},
-
+
'test .parseTag() @see': function(){
var tag = dox.parseTag('@see http://google.com');
tag.type.should.equal('see');
tag.title.should.equal('');
tag.url.should.equal('http://google.com');
-
+
var tag = dox.parseTag('@see Google http://google.com');
tag.type.should.equal('see');
tag.title.should.equal('Google');
tag.url.should.equal('http://google.com');
-
+
var tag = dox.parseTag('@see exports.parseComment');
tag.type.should.equal('see');
tag.local.should.equal('exports.parseComment');
},
-
+
'test .parseTag() @api': function(){
var tag = dox.parseTag('@api private');
tag.type.should.equal('api');
tag.visibility.should.equal('private');
},
-
+
'test .parseTag() @type': function(){
var tag = dox.parseTag('@type {String}');
tag.type.should.equal('type');
tag.types.should.eql(['String']);
},
-
+
'test .parseTag() @param': function(){
var tag = dox.parseTag('@param {String|Buffer}');
tag.type.should.equal('param');
@@ -255,7 +282,7 @@ module.exports = {
tag.name.should.equal('');
tag.description.should.equal('');
},
-
+
'test .parseTag() @return': function(){
var tag = dox.parseTag('@return {String} a normal string');
tag.type.should.equal('return');
@@ -287,7 +314,7 @@ module.exports = {
tag.type.should.equal('memberOf')
tag.parent.should.equal('Foo.bar')
},
-
+
'test .parseTag() default': function(){
var tag = dox.parseTag('@hello universe is better than world');
tag.type.should.equal('hello');
View
23 test/fixtures/prototypes.js
@@ -0,0 +1,23 @@
+
+/**
+ * Does a lot of foo
+ *
+ * @param {String} bar
+ */
+function Foo(bar) {
+ this.bar = bar
+}
+
+/**
+ * A property of an instance of Foo
+ * @type {String}
+ */
+Foo.prototype.property = 'this is a property'
+
+/**
+ * A method of an instance of Foo
+ * @return {Boolean}
+ */
+Foo.prototype.method = function () {
+ return false
+}
Please sign in to comment.
Something went wrong with that request. Please try again.