|
| 1 | +/*jshint unused:false*/ |
| 2 | + |
| 3 | +/** |
| 4 | + * Test: Parser apiParam |
| 5 | + */ |
| 6 | + |
| 7 | +// node modules |
| 8 | +var should = require('should'); |
| 9 | + |
| 10 | +// lib modules |
| 11 | +var parser = require('../lib/parsers/api_body'); |
| 12 | + |
| 13 | +describe('Parser: apiBody', function() { |
| 14 | + |
| 15 | + // TODO: Add 1.000 more possible cases ;-) |
| 16 | + var testCases = [ |
| 17 | + { |
| 18 | + title: 'Simple fieldname only', |
| 19 | + content: 'simple', |
| 20 | + expected: { |
| 21 | + group: 'Body', |
| 22 | + type: undefined, |
| 23 | + size: undefined, |
| 24 | + allowedValues: undefined, |
| 25 | + optional: false, |
| 26 | + field: 'simple', |
| 27 | + defaultValue: undefined, |
| 28 | + description: '' |
| 29 | + } |
| 30 | + }, |
| 31 | + { |
| 32 | + title: 'Type, Fieldname, Description', |
| 33 | + content: '{String} name The users name.', |
| 34 | + expected: { |
| 35 | + group: 'Body', |
| 36 | + type: 'String', |
| 37 | + size: undefined, |
| 38 | + allowedValues: undefined, |
| 39 | + optional: false, |
| 40 | + field: 'name', |
| 41 | + defaultValue: undefined, |
| 42 | + description: 'The users name.' |
| 43 | + } |
| 44 | + }, |
| 45 | + { |
| 46 | + title: 'Type, Fieldname, Description', |
| 47 | + content: '{String|String[]} name The users name.', |
| 48 | + expected: { |
| 49 | + group: 'Body', |
| 50 | + type: 'String|String[]', |
| 51 | + size: undefined, |
| 52 | + allowedValues: undefined, |
| 53 | + optional: false, |
| 54 | + field: 'name', |
| 55 | + defaultValue: undefined, |
| 56 | + description: 'The users name.' |
| 57 | + } |
| 58 | + }, |
| 59 | + { |
| 60 | + title: '$Simple fieldname only', |
| 61 | + content: '$simple', |
| 62 | + expected: { |
| 63 | + group: 'Body', |
| 64 | + type: undefined, |
| 65 | + size: undefined, |
| 66 | + allowedValues: undefined, |
| 67 | + optional: false, |
| 68 | + field: '$simple', |
| 69 | + defaultValue: undefined, |
| 70 | + description: '' |
| 71 | + } |
| 72 | + }, |
| 73 | + { |
| 74 | + title: 'All options, with optional defaultValue', |
| 75 | + content: ' ( MyGroup ) { \\Object\\String.uni-code_char[] { 1..10 } = \'abc\', \'def\' } ' + |
| 76 | + '[ \\MyClass\\field.user_first-name = \'John Doe\' ] Some description.', |
| 77 | + expected: { |
| 78 | + group: 'MyGroup', |
| 79 | + type: '\\Object\\String.uni-code_char[]', |
| 80 | + size: '1..10', |
| 81 | + allowedValues: [ '\'abc\'', '\'def\'' ], |
| 82 | + optional: true, |
| 83 | + field: '\\MyClass\\field.user_first-name', |
| 84 | + defaultValue: 'John Doe', |
| 85 | + description: 'Some description.' |
| 86 | + } |
| 87 | + }, |
| 88 | + { |
| 89 | + title: 'All options, without optional-marker', |
| 90 | + content: ' ( MyGroup ) { \\Object\\String.uni-code_char[] { 1..10 } = \'abc\', \'def\' } ' + |
| 91 | + '\\MyClass\\field.user_first-name = \'John Doe\' Some description.', |
| 92 | + expected: { |
| 93 | + group: 'MyGroup', |
| 94 | + type: '\\Object\\String.uni-code_char[]', |
| 95 | + size: '1..10', |
| 96 | + allowedValues: [ '\'abc\'', '\'def\'' ], |
| 97 | + optional: false, |
| 98 | + field: '\\MyClass\\field.user_first-name', |
| 99 | + defaultValue: 'John Doe', |
| 100 | + description: 'Some description.' |
| 101 | + } |
| 102 | + }, |
| 103 | + { |
| 104 | + title: 'All options, without optional-marker, without default value quotes', |
| 105 | + content: ' ( MyGroup ) { \\Object\\String.uni-code_char[] { 1..10 } = \'abc\', \'def\' } ' + |
| 106 | + '\\MyClass\\field.user_first-name = John_Doe Some description.', |
| 107 | + expected: { |
| 108 | + group: 'MyGroup', |
| 109 | + type: '\\Object\\String.uni-code_char[]', |
| 110 | + size: '1..10', |
| 111 | + allowedValues: [ '\'abc\'', '\'def\'' ], |
| 112 | + optional: false, |
| 113 | + field: '\\MyClass\\field.user_first-name', |
| 114 | + defaultValue: 'John_Doe', |
| 115 | + description: 'Some description.' |
| 116 | + } |
| 117 | + }, |
| 118 | + ]; |
| 119 | + |
| 120 | + // create |
| 121 | + it('case 1: should pass all regexp test cases', function(done) { |
| 122 | + testCases.forEach(function(testCase) { |
| 123 | + var parsed = parser.parse(testCase.content); |
| 124 | + (parsed !== null).should.equal(true, 'Title: ' + testCase.title + ', Source: ' + testCase.content); |
| 125 | + parsed.should.eql(testCase.expected); |
| 126 | + }); |
| 127 | + done(); |
| 128 | + }); |
| 129 | + |
| 130 | +}); |
0 commit comments