Skip to content

Commit 912bc2f

Browse files
committed
Merge branch 'feature/tests'
2 parents 1cdad79 + 5546c36 commit 912bc2f

File tree

9 files changed

+380
-0
lines changed

9 files changed

+380
-0
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test/
2+
.travis.yml
3+
Makefile

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test:
2+
./node_modules/.bin/mocha
3+
4+
.PHONY: test

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
"temp": "0.8.1",
1717
"marked": "0.3.2"
1818
},
19+
"devDependencies": {
20+
"mocha": "2.1.0"
21+
},
22+
"scripts": {
23+
"test": "make test"
24+
},
1925
"keywords": [
2026
"documentation",
2127
"html",

test/fixtures/dox.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Escape the given `html`.
3+
*
4+
* @example
5+
* utils.escape('<script></script>')
6+
* // => '&lt;script&gt;&lt;/script&gt;'
7+
*
8+
* @param {String} html string to be escaped
9+
* @return {String} escaped html
10+
* @api public
11+
*/
12+
13+
exports.escape = function(html){
14+
return String(html)
15+
.replace(/&(?!\w+;)/g, '&amp;')
16+
.replace(/</g, '&lt;')
17+
.replace(/>/g, '&gt;');
18+
};

test/fixtures/dox.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[
2+
{
3+
"uid": "dox.js-exports.escape",
4+
"isPrivate": false,
5+
"type": "method",
6+
"name": "exports.escape()",
7+
"description": "Escape the given `html`.\n",
8+
"body": "",
9+
"tags": {
10+
"example": [
11+
" utils.escape('<script></script>')\n // => '&lt;script&gt;&lt;/script&gt;'\n"
12+
],
13+
"param": [
14+
{
15+
"name": "html",
16+
"isOptional": false,
17+
"types": [
18+
"String"
19+
],
20+
"description": "string to be escaped"
21+
}
22+
],
23+
"return": [
24+
{
25+
"types": [
26+
"String"
27+
],
28+
"description": "escaped html"
29+
}
30+
],
31+
"api": []
32+
}
33+
}
34+
]

test/fixtures/facade.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* Create a polygon object. Inherits all methods from <b>Facade.Entity</b>.
3+
*
4+
* var polygon = new Facade.Polygon({
5+
* x: 0,
6+
* y: 0,
7+
* points: [ [100, 0], [200, 100], [100, 200], [0, 100] ],
8+
* lineWidth: 10,
9+
* strokeStyle: '#333E4B',
10+
* fillStyle: '#1C73A8',
11+
* anchor: 'top/left'
12+
* });
13+
*
14+
* @param {Object} [options] Options to create the polygon with.
15+
* @param {String} [options.anchor] Position to anchor the polygon. <i>Default:</i> "top/left"<br><ul><li>top/left</li><li>top/center</li><li>top/right</li><li>center/left</li><li>center</li><li>center/right</li><li>bottom/left</li><li>bottom/center</li><li>bottom/right</li></ul>
16+
* @param {Boolean} [options.closePath] Boolean to determine if the polygon should be self closing or not. <i>Default:</i> true
17+
* @param {String} [options.fillStyle] Fill color for the polygon. Can be a text representation of a color, HEX, RGB(a), HSL(a). <i>Default:</i> "#000"<br><ul><li>HTML Colors: red, green, blue, etc.</li><li>HEX: #f00, #ff0000</li><li>RGB(a): rgb(255, 0, 0), rgba(0, 255, 0, 0.5)</li><li>HSL(a): hsl(100, 100%, 50%), hsla(100, 100%, 50%, 0.5)</li></ul>
18+
* @param {String} [options.lineCap] The style of line cap. <i>Default:</i> "butt"<br><ul><li>butt</li><li>round</li><li>square</li></ul>
19+
* @param {String} [options.lineJoin] The style of line join. <i>Default:</i> "miter"<br><ul><li>miter</li><li>round</li><li>bevel</li></ul>
20+
* @param {Integer} [options.lineWidth] Width of the stroke. <i>Default:</i> 0
21+
* @param {Integer} [options.opacity] Opacity of the polygon. Integer between 0 and 100. <i>Default:</i> 100
22+
* @param {Array} [options.points] Multi-dimensional array of points used to render a polygon. Point arrays with 2 values is rendered as a line, 5 values is rendered as an arc and 6 values is rendered as a bezier curve.
23+
* @param {Integer} [options.rotate] Degrees to rotate the polygon. <i>Default:</i> 0
24+
* @param {Integer} [options.scale] A float representing the scale of a polygon. <i>Default:</i> 1
25+
* @param {String} [options.strokeStyle] Color of a polygon's stroke. Can be a text representation of a color, HEX, RGB(a), HSL(a). <i>Default:</i> "#000"<br><ul><li>HTML Colors: red, green, blue, etc.</li><li>HEX: #f00, #ff0000</li><li>RGB(a): rgb(255, 0, 0), rgba(0, 255, 0, 0.5)</li><li>HSL(a): hsl(100, 100%, 50%), hsla(100, 100%, 50%, 0.5)</li></ul>
26+
* @param {Integer} [options.x] X coordinate to position the polygon. <i>Default:</i> 0
27+
* @param {Integer} [options.y] Y coordinate to position the polygon. <i>Default:</i> 0
28+
* @return {Object} New Facade.Polygon object.
29+
* @public
30+
*/
31+
32+
Facade.Polygon = function (options) {
33+
34+
if (!(this instanceof Facade.Polygon)) {
35+
36+
return new Facade.Polygon(options);
37+
38+
}
39+
40+
this._options = this._defaultOptions();
41+
this._metrics = this._defaultMetrics();
42+
43+
this.setOptions(options);
44+
45+
};
46+
47+
/*!
48+
* Extend from Facade.Entity
49+
*/
50+
51+
Facade.Polygon.prototype = Object.create(Facade.Entity.prototype);
52+
Facade.Polygon.constructor = Facade.Entity;
53+
54+
/**
55+
* Returns a default set of options common to all Facade.js polygon entities.
56+
*
57+
* @example console.log(Facade.Polygon.prototype._defaultOptions());
58+
* @param {Object} updated Additional options as key-value pairs.
59+
* @return {Object} Default set of options.
60+
* @private
61+
*/
62+
63+
Facade.Polygon.prototype._defaultOptions = function (updated) {
64+
65+
var options,
66+
keys,
67+
i,
68+
length;
69+
70+
options = Facade.Entity.prototype._defaultOptions({
71+
opacity: 100,
72+
points: [],
73+
fillStyle: '#000',
74+
strokeStyle: '',
75+
lineWidth: 0,
76+
lineCap: 'butt',
77+
lineJoin: 'miter',
78+
closePath: true
79+
});
80+
81+
if (updated) {
82+
83+
keys = Object.keys(updated);
84+
85+
for (i = 0, length = keys.length; i < length; i += 1) {
86+
87+
options[keys[i]] = updated[keys[i]];
88+
89+
}
90+
91+
}
92+
93+
return options;
94+
95+
};

test/fixtures/facade.json

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
[
2+
{
3+
"uid": "facade.js-facade.polygon",
4+
"isPrivate": false,
5+
"type": "method",
6+
"name": "Facade.Polygon()",
7+
"description": "Create a polygon object. Inherits all methods from <b>Facade.Entity</b>.",
8+
"body": " var polygon = new Facade.Polygon({\n x: 0,\n y: 0,\n points: [ [100, 0], [200, 100], [100, 200], [0, 100] ],\n lineWidth: 10,\n strokeStyle: '#333E4B',\n fillStyle: '#1C73A8',\n anchor: 'top/left'\n });\n",
9+
"tags": {
10+
"example": [],
11+
"param": [
12+
{
13+
"name": "options",
14+
"isOptional": true,
15+
"types": [
16+
"Object"
17+
],
18+
"description": "Options to create the polygon with."
19+
},
20+
{
21+
"name": "options.anchor",
22+
"isOptional": true,
23+
"types": [
24+
"String"
25+
],
26+
"description": "Position to anchor the polygon. <i>Default:</i> \"top/left\"<br><ul><li>top/left</li><li>top/center</li><li>top/right</li><li>center/left</li><li>center</li><li>center/right</li><li>bottom/left</li><li>bottom/center</li><li>bottom/right</li></ul>"
27+
},
28+
{
29+
"name": "options.closePath",
30+
"isOptional": true,
31+
"types": [
32+
"Boolean"
33+
],
34+
"description": "Boolean to determine if the polygon should be self closing or not. <i>Default:</i> true"
35+
},
36+
{
37+
"name": "options.fillStyle",
38+
"isOptional": true,
39+
"types": [
40+
"String"
41+
],
42+
"description": "Fill color for the polygon. Can be a text representation of a color, HEX, RGB(a), HSL(a). <i>Default:</i> \"#000\"<br><ul><li>HTML Colors: red, green, blue, etc.</li><li>HEX: #f00, #ff0000</li><li>RGB(a): rgb(255, 0, 0), rgba(0, 255, 0, 0.5)</li><li>HSL(a): hsl(100, 100%, 50%), hsla(100, 100%, 50%, 0.5)</li></ul>"
43+
},
44+
{
45+
"name": "options.lineCap",
46+
"isOptional": true,
47+
"types": [
48+
"String"
49+
],
50+
"description": "The style of line cap. <i>Default:</i> \"butt\"<br><ul><li>butt</li><li>round</li><li>square</li></ul>"
51+
},
52+
{
53+
"name": "options.lineJoin",
54+
"isOptional": true,
55+
"types": [
56+
"String"
57+
],
58+
"description": "The style of line join. <i>Default:</i> \"miter\"<br><ul><li>miter</li><li>round</li><li>bevel</li></ul>"
59+
},
60+
{
61+
"name": "options.lineWidth",
62+
"isOptional": true,
63+
"types": [
64+
"Integer"
65+
],
66+
"description": "Width of the stroke. <i>Default:</i> 0"
67+
},
68+
{
69+
"name": "options.opacity",
70+
"isOptional": true,
71+
"types": [
72+
"Integer"
73+
],
74+
"description": "Opacity of the polygon. Integer between 0 and 100. <i>Default:</i> 100"
75+
},
76+
{
77+
"name": "options.points",
78+
"isOptional": true,
79+
"types": [
80+
"Array"
81+
],
82+
"description": "Multi-dimensional array of points used to render a polygon. Point arrays with 2 values is rendered as a line, 5 values is rendered as an arc and 6 values is rendered as a bezier curve."
83+
},
84+
{
85+
"name": "options.rotate",
86+
"isOptional": true,
87+
"types": [
88+
"Integer"
89+
],
90+
"description": "Degrees to rotate the polygon. <i>Default:</i> 0"
91+
},
92+
{
93+
"name": "options.scale",
94+
"isOptional": true,
95+
"types": [
96+
"Integer"
97+
],
98+
"description": "A float representing the scale of a polygon. <i>Default:</i> 1"
99+
},
100+
{
101+
"name": "options.strokeStyle",
102+
"isOptional": true,
103+
"types": [
104+
"String"
105+
],
106+
"description": "Color of a polygon's stroke. Can be a text representation of a color, HEX, RGB(a), HSL(a). <i>Default:</i> \"#000\"<br><ul><li>HTML Colors: red, green, blue, etc.</li><li>HEX: #f00, #ff0000</li><li>RGB(a): rgb(255, 0, 0), rgba(0, 255, 0, 0.5)</li><li>HSL(a): hsl(100, 100%, 50%), hsla(100, 100%, 50%, 0.5)</li></ul>"
107+
},
108+
{
109+
"name": "options.x",
110+
"isOptional": true,
111+
"types": [
112+
"Integer"
113+
],
114+
"description": "X coordinate to position the polygon. <i>Default:</i> 0"
115+
},
116+
{
117+
"name": "options.y",
118+
"isOptional": true,
119+
"types": [
120+
"Integer"
121+
],
122+
"description": "Y coordinate to position the polygon. <i>Default:</i> 0"
123+
}
124+
],
125+
"return": [
126+
{
127+
"types": [
128+
"Object"
129+
],
130+
"description": "New Facade.Polygon object."
131+
}
132+
],
133+
"public": []
134+
}
135+
},
136+
{
137+
"uid": "facade.js-facade.polygon.prototype._defaultoptions",
138+
"isPrivate": true,
139+
"type": "method",
140+
"name": "Facade.Polygon._defaultOptions()",
141+
"description": "Returns a default set of options common to all Facade.js polygon entities.\n",
142+
"body": "",
143+
"tags": {
144+
"example": [
145+
"console.log(Facade.Polygon.prototype._defaultOptions());"
146+
],
147+
"param": [
148+
{
149+
"name": "updated",
150+
"isOptional": false,
151+
"types": [
152+
"Object"
153+
],
154+
"description": "Additional options as key-value pairs."
155+
}
156+
],
157+
"return": [
158+
{
159+
"types": [
160+
"Object"
161+
],
162+
"description": "Default set of options."
163+
}
164+
],
165+
"private": []
166+
}
167+
}
168+
]

test/utils.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
var assert = require('assert');
2+
3+
var fs = require('fs');
4+
var dox = require('dox');
5+
6+
var utils = require('../lib/utils');
7+
8+
describe('doxdox util methods', function () {
9+
10+
['dox', 'facade'].forEach(function (file) {
11+
12+
it('parseData on ' + file + '.js', function (done) {
13+
14+
fs.readFile(__dirname + '/fixtures/' + file + '.js', 'utf8', function (err, data) {
15+
16+
var methods = utils.parseData(
17+
dox.parseComments(data, { raw: true }),
18+
file + '.js'
19+
);
20+
21+
// fs.writeFileSync(__dirname + '/fixtures/' + file + '.json', JSON.stringify(methods, true, 4));
22+
23+
fs.readFile(__dirname + '/fixtures/' + file + '.json', 'utf8', function (err, data) {
24+
25+
assert.deepEqual(methods, JSON.parse(data));
26+
27+
done();
28+
29+
});
30+
31+
});
32+
33+
});
34+
35+
});
36+
37+
it('formatStringForName', function () {
38+
39+
assert.equal(utils.formatStringForName('Class.prototype.method()'), 'Class.method()');
40+
41+
});
42+
43+
it('formatStringForUID', function () {
44+
45+
assert.equal(utils.formatStringForUID('Class.prototype.method()'), 'class.prototype.method');
46+
47+
});
48+
49+
});

0 commit comments

Comments
 (0)