Skip to content

Commit

Permalink
Change RegEx for apiParam. Add size and allowedValues. Add test cases…
Browse files Browse the repository at this point in the history
… for apiParam.
  • Loading branch information
rottmann committed Nov 7, 2014
1 parent 6e9ad1b commit 7f2e4b1
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = function(grunt)
ui: "bdd",
reporter: "spec"
},
all: { src: ["test/apidoc_test.js"] }
all: { src: ["test/*_test.js"] }
} // simplemocha
}); // grunt.initConfig

Expand Down
100 changes: 100 additions & 0 deletions test/parser_api_param_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Test: Parser apiParam
*/

// Node Module
var should = require('should');

// Lib Module
var parser = require('../lib/parsers/api_param');

/* --------------------------------------------------------------------------------
* Tests
* -------------------------------------------------------------------------------- */
describe('Parser apiParam', function() {

// TODO: Add 1.000 more possible cases ;-)
var testCases = [
{
title: 'Simple fieldname only',
content: 'simple',
expected: {
group: 'Parameter',
type: undefined,
size: undefined,
allowedValues: undefined,
optional: false,
field: 'simple',
defaultValue: undefined,
description: ''
}
},
{
title: 'Type, Fieldname, Description',
content: '{String} name The users name.',
expected: {
group: 'Parameter',
type: 'String',
size: undefined,
allowedValues: undefined,
optional: false,
field: 'name',
defaultValue: undefined,
description: 'The users name.'
}
},
{
title: 'All options, with optional defaultValue',
content: ' ( MyGroup ) { \\Object\\String.uni-code_char[] { 1..10 } = "abc", "def" } [ \\MyClass\\field.user_first-name = "John Doe" ] Some description.',
expected: {
group: 'MyGroup',
type: '\\Object\\String.uni-code_char[]',
size: '1..10',
allowedValues: [ '"abc"', '"def"' ],
optional: true,
field: '\\MyClass\\field.user_first-name',
defaultValue: 'John Doe',
description: 'Some description.'
}
},
{
title: 'All options, without optional-marker',
content: ' ( MyGroup ) { \\Object\\String.uni-code_char[] { 1..10 } = "abc", "def" } \\MyClass\\field.user_first-name = "John Doe" Some description.',
expected: {
group: 'MyGroup',
type: '\\Object\\String.uni-code_char[]',
size: '1..10',
allowedValues: [ '"abc"', '"def"' ],
optional: false,
field: '\\MyClass\\field.user_first-name',
defaultValue: 'John Doe',
description: 'Some description.'
}
},
{
title: 'All options, without optional-marker, without default value quotes',
content: ' ( MyGroup ) { \\Object\\String.uni-code_char[] { 1..10 } = "abc", "def" } \\MyClass\\field.user_first-name = John_Doe Some description.',
expected: {
group: 'MyGroup',
type: '\\Object\\String.uni-code_char[]',
size: '1..10',
allowedValues: [ '"abc"', '"def"' ],
optional: false,
field: '\\MyClass\\field.user_first-name',
defaultValue: 'John_Doe',
description: 'Some description.'
}
},
];

// create
it('case 1: should pass all regexp test cases', function(done) {
testCases.forEach(function(testCase) {
var parsed = parser.parse(testCase.content);
(parsed !== null).should.equal(true, 'Title: ' + testCase.title + ', Source: ' + testCase.content);
parsed.should.eql(testCase.expected);
});
done();
}); // it

}); // describe

0 comments on commit 7f2e4b1

Please sign in to comment.