From 1a6002c530ed21c627fa89011d6a198fd2bb1a6d Mon Sep 17 00:00:00 2001 From: Fabrice Weinberg Date: Wed, 20 Aug 2014 21:27:40 +0200 Subject: [PATCH 1/6] Implement #25 --- src/annotation/annotations/prop.js | 29 +++++++++++++++++++++++++++++ test/annotations/prop.test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/annotation/annotations/prop.js create mode 100644 test/annotations/prop.test.js diff --git a/src/annotation/annotations/prop.js b/src/annotation/annotations/prop.js new file mode 100644 index 00000000..e55a8f16 --- /dev/null +++ b/src/annotation/annotations/prop.js @@ -0,0 +1,29 @@ +'use strict'; + +var reqRegEx = /\s*(?:\{(.*)\})?\s*(?:(\$?[^\s]+))?\s*(?:\((.*)\))?\s*(?:-?\s*(.*?))\s*$/; + +module.exports = { + + parse: function (text) { + var match = reqRegEx.exec(text.trim()); + + var obj = { + type: match[1] || 'Map' + }; + + if (match[2]){ + obj.path = match[2]; + } + + if (match[3]){ + obj.default = match[3]; + } + + if (match[4]){ + obj.description = match[4]; + } + + return obj; + } + +}; diff --git a/test/annotations/prop.test.js b/test/annotations/prop.test.js new file mode 100644 index 00000000..9b1786c3 --- /dev/null +++ b/test/annotations/prop.test.js @@ -0,0 +1,27 @@ +/* global describe, it */ +'use strict'; + +var assert = require('assert'); + +describe('#prop', function () { + var prop = require('../../src/annotation').prop; + + it('should parse the prop annotation', function () { + assert.deepEqual(prop.parse('base'), { + type : 'Map', + path : 'base' + }); + + assert.deepEqual(prop.parse('{Function} base.default - description'), { + type : 'Function', + path : 'base.default', + description : 'description' + }); + + assert.deepEqual(prop.parse('{Function} base.default - description'), { + type : 'Function', + path : 'base.default', + description : 'description' + }); + }); +}); From 0fb49427b98ca8e0b275448b0de3cc0c6a090bfd Mon Sep 17 00:00:00 2001 From: Fabrice Weinberg Date: Wed, 20 Aug 2014 21:29:04 +0200 Subject: [PATCH 2/6] Add another test --- test/annotations/prop.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/annotations/prop.test.js b/test/annotations/prop.test.js index 9b1786c3..330430d9 100644 --- a/test/annotations/prop.test.js +++ b/test/annotations/prop.test.js @@ -23,5 +23,12 @@ describe('#prop', function () { path : 'base.default', description : 'description' }); + + assert.deepEqual(prop.parse('{Function} base.default (default) - description'), { + type : 'Function', + path : 'base.default', + default : 'default', + description : 'description' + }); }); }); From 6999f5cd6209ba73a92f48b93cba7b587b2255a9 Mon Sep 17 00:00:00 2001 From: Fabrice Weinberg Date: Wed, 20 Aug 2014 21:36:32 +0200 Subject: [PATCH 3/6] Test with no description --- test/annotations/prop.test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/annotations/prop.test.js b/test/annotations/prop.test.js index 330430d9..1f27374b 100644 --- a/test/annotations/prop.test.js +++ b/test/annotations/prop.test.js @@ -12,10 +12,9 @@ describe('#prop', function () { path : 'base' }); - assert.deepEqual(prop.parse('{Function} base.default - description'), { + assert.deepEqual(prop.parse('{Function} base.default'), { type : 'Function', - path : 'base.default', - description : 'description' + path : 'base.default' }); assert.deepEqual(prop.parse('{Function} base.default - description'), { From 2456f1336598f004e6edd5084ffda456236006db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Galliat?= Date: Sun, 24 Aug 2014 19:41:13 +0200 Subject: [PATCH 4/6] Add test case for description with parens and fix the regex --- src/annotation/annotations/prop.js | 2 +- test/annotations/prop.test.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/annotation/annotations/prop.js b/src/annotation/annotations/prop.js index e55a8f16..5cc42e7b 100644 --- a/src/annotation/annotations/prop.js +++ b/src/annotation/annotations/prop.js @@ -1,6 +1,6 @@ 'use strict'; -var reqRegEx = /\s*(?:\{(.*)\})?\s*(?:(\$?[^\s]+))?\s*(?:\((.*)\))?\s*(?:-?\s*(.*?))\s*$/; +var reqRegEx = /\s*(?:\{(.*)\})?\s*(?:(\$?[^\s]+))?\s*(?:\(([^\)]*)\))?\s*(?:-?\s*(.*?))\s*$/; module.exports = { diff --git a/test/annotations/prop.test.js b/test/annotations/prop.test.js index 1f27374b..d5f83b87 100644 --- a/test/annotations/prop.test.js +++ b/test/annotations/prop.test.js @@ -29,5 +29,13 @@ describe('#prop', function () { default : 'default', description : 'description' }); + + assert.deepEqual(prop.parse('{Function} base.default (default) - description (with parens)'), { + type : 'Function', + path : 'base.default', + default : 'default', + description : 'description (with parens)' + }); + }); }); From 60ea3820b12c325ce3c7da3e6706dca6c9c6f854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Galliat?= Date: Sun, 24 Aug 2014 19:48:40 +0200 Subject: [PATCH 5/6] Rename `path` in `name` to be consistent --- src/annotation/annotations/prop.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/annotation/annotations/prop.js b/src/annotation/annotations/prop.js index 5cc42e7b..f4ee1e0b 100644 --- a/src/annotation/annotations/prop.js +++ b/src/annotation/annotations/prop.js @@ -12,7 +12,7 @@ module.exports = { }; if (match[2]){ - obj.path = match[2]; + obj.name = match[2]; } if (match[3]){ From b532e5902f15cce064ca80f9ade18d30b31bc37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Galliat?= Date: Sun, 24 Aug 2014 19:54:11 +0200 Subject: [PATCH 6/6] Update tests according to previous commit --- test/annotations/prop.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/annotations/prop.test.js b/test/annotations/prop.test.js index d5f83b87..dd66b5f5 100644 --- a/test/annotations/prop.test.js +++ b/test/annotations/prop.test.js @@ -9,30 +9,30 @@ describe('#prop', function () { it('should parse the prop annotation', function () { assert.deepEqual(prop.parse('base'), { type : 'Map', - path : 'base' + name : 'base' }); assert.deepEqual(prop.parse('{Function} base.default'), { type : 'Function', - path : 'base.default' + name : 'base.default' }); assert.deepEqual(prop.parse('{Function} base.default - description'), { type : 'Function', - path : 'base.default', + name : 'base.default', description : 'description' }); assert.deepEqual(prop.parse('{Function} base.default (default) - description'), { type : 'Function', - path : 'base.default', + name : 'base.default', default : 'default', description : 'description' }); assert.deepEqual(prop.parse('{Function} base.default (default) - description (with parens)'), { type : 'Function', - path : 'base.default', + name : 'base.default', default : 'default', description : 'description (with parens)' });