Skip to content

Commit

Permalink
Change quoting.
Browse files Browse the repository at this point in the history
  • Loading branch information
rottmann committed Nov 7, 2014
1 parent 906010a commit 9ab9e12
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 46 deletions.
6 changes: 3 additions & 3 deletions lib/parsers/api_param.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var regExp = {

oType: { // optional type: {string}
b: "\\s*(?:\\{\\s*", // starting with '{', optional surrounding spaces
type: "([a-zA-Z0-9\.\/\\\\\\[\\]_-]+)", // 2
type: "([a-zA-Z0-9\\.\\/\\\\\\[\\]_-]+)", // 2
oSize: { // optional size within type: {string{1..4}}
b: "\\s*(?:\\{\\s*", // starting with '{', optional surrounding spaces
size: "(.+?)", // 3
Expand All @@ -37,7 +37,7 @@ var regExp = {

wName: {
b: "(\\[?\\s*", // 5 optional optional-marker
name: "([a-zA-Z0-9\.\/\\\\\\[\\]_-]+)", // 6
name: "([a-zA-Z0-9\\.\\/\\\\\\[\\]_-]+)", // 6
oDefaultValue: { // optional defaultValue
b: "(?:\\s*=\\s*(?:", // starting with '=', optional surrounding spaces
withDoubleQuote: "\"([^\"]*)\"", // 7
Expand Down Expand Up @@ -93,7 +93,7 @@ function parse(content, source, defaultGroup)
var allowedValuesMatch;
var list = [];
while (allowedValuesMatch = regExp.exec(allowedValues)) {
if (typeof allowedValuesMatch == 'string')
if (typeof allowedValuesMatch === "string")
list.push(allowedValuesMatch);
else
list.push(allowedValuesMatch[0]);
Expand Down
89 changes: 46 additions & 43 deletions test/parser_api_param_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,98 @@
*/

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

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

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

// TODO: Add 1.000 more possible cases ;-)
var testCases = [
{
title: 'Simple fieldname only',
content: 'simple',
title: "Simple fieldname only",
content: "simple",
expected: {
group: 'Parameter',
group: "Parameter",
type: undefined,
size: undefined,
allowedValues: undefined,
optional: false,
field: 'simple',
field: "simple",
defaultValue: undefined,
description: ''
description: ""
}
},
{
title: 'Type, Fieldname, Description',
content: '{String} name The users name.',
title: "Type, Fieldname, Description",
content: "{String} name The users name.",
expected: {
group: 'Parameter',
type: 'String',
group: "Parameter",
type: "String",
size: undefined,
allowedValues: undefined,
optional: false,
field: 'name',
field: "name",
defaultValue: undefined,
description: 'The users name.'
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.',
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"' ],
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.'
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.',
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"' ],
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.'
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.',
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"' ],
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.'
field: "\\MyClass\\field.user_first-name",
defaultValue: "John_Doe",
description: "Some description."
}
},
];

// create
it('case 1: should pass all regexp test cases', function(done) {
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 !== null).should.equal(true, "Title: " + testCase.title + ", Source: " + testCase.content);
parsed.should.eql(testCase.expected);
});
done();
Expand Down

0 comments on commit 9ab9e12

Please sign in to comment.