From 9ab9e12fb67483f04448d089f2465ce564365ca2 Mon Sep 17 00:00:00 2001 From: Peter Rottmann Date: Fri, 7 Nov 2014 14:43:51 +0100 Subject: [PATCH] Change quoting. --- lib/parsers/api_param.js | 6 +-- test/parser_api_param_test.js | 89 ++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 46 deletions(-) diff --git a/lib/parsers/api_param.js b/lib/parsers/api_param.js index 3ee9467a..6dece3de 100644 --- a/lib/parsers/api_param.js +++ b/lib/parsers/api_param.js @@ -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 @@ -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 @@ -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]); diff --git a/test/parser_api_param_test.js b/test/parser_api_param_test.js index d0f8f42a..908f84cd 100644 --- a/test/parser_api_param_test.js +++ b/test/parser_api_param_test.js @@ -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();