@clubedaentrega/test-spec
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -0,1 +1,4 @@ | ||
# 1.2.0 | ||
* Added: support function value syntax | ||
# 1.1.0 | ||
@@ -2,0 +5,0 @@ * Added: support for Node.js v0.12 |
@@ -66,2 +66,4 @@ 'use strict' | ||
return compileJS(value) | ||
} else if (value.subtype === 'function') { | ||
return compileFunction(value) | ||
} | ||
@@ -145,2 +147,15 @@ throw new Error('Invalid subtype: ' + value.subtype) | ||
/** | ||
* @param {Value} value | ||
* @returns {string} | ||
* @private | ||
*/ | ||
function compileFunction(value) { | ||
var name = '__' + (n++) | ||
code += '\n__pos.line = ' + value.line + ', __pos.size = ' + value.size | ||
code += '\nvar ' + name + ' = function (' + value.args + ') {\n' + value.body + '\n}' | ||
return name | ||
} | ||
/** | ||
* Convert a path string to a JS code for an array | ||
@@ -147,0 +162,0 @@ * Example: preparePath('users.0.name') -> "['users', 0, 'name']" |
@@ -13,3 +13,3 @@ /** @module */ | ||
* @property {string} type - always 'value' | ||
* @property {string} subtype - one of: 'array', 'object', 'mixin', 'js', 'compiled' | ||
* @property {string} subtype - one of: 'array', 'object', 'mixin', 'js', 'compiled', 'function' | ||
* @property {number} line | ||
@@ -25,2 +25,4 @@ * @property {number} size | ||
* @property {?function(Object):*} run - present for subtype 'compiled' | ||
* @property {string} args - present for subtype 'function' | ||
* @property {string} body - present for subtype 'function' | ||
*/ | ||
@@ -27,0 +29,0 @@ |
@@ -31,2 +31,3 @@ 'use strict' | ||
tryParseMixin(block, lines) || | ||
tryParseFunction(block, lines) || | ||
tryParseJS(block, lines))) { | ||
@@ -255,2 +256,36 @@ throwSyntaxError('Invalid value syntax', block.line, block.size) | ||
*/ | ||
function tryParseFunction(block, lines) { | ||
if (!lines.length || !lines[0].str.match(/^function( .*)?$/)) { | ||
// A function must start with 'function' | ||
return false | ||
} | ||
// Update block | ||
block.subtype = 'function' | ||
block.args = lines[0].str.substr('function '.length) | ||
block.body = '' | ||
var bodyLines = [] | ||
lines.slice(1).forEach(function (each) { | ||
var line = each.line, | ||
str = each.str | ||
if (str[0] === '\t') { | ||
// Body continuation | ||
bodyLines.push(str.substr(1)) | ||
} else { | ||
throwSyntaxError('Expected a tab', line) | ||
} | ||
}) | ||
block.body = bodyLines.join('\n') | ||
return true | ||
} | ||
/** | ||
* @param {Value} block | ||
* @param {Array<string>} lines | ||
* @returns {boolean} | ||
*/ | ||
function tryParseJS(block, lines) { | ||
@@ -257,0 +292,0 @@ if (lines.length !== 1) { |
{ | ||
"name": "@clubedaentrega/test-spec", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"author": "Sitegui <sitegui@sitegui.com.br>", | ||
@@ -5,0 +5,0 @@ "description": "A parser and runtime for markdown-inspired documentation and testing files", |
@@ -67,2 +67,10 @@ # Doc Syntax | ||
## Functions | ||
Define functions like: | ||
function a, b | ||
return a + b | ||
The function body may span multiple lines. The argument list may be empty. | ||
## Mixins | ||
@@ -69,0 +77,0 @@ Mixins are used to derive a similar object from a base one. Suppose `user = {name: 'John', pass: '123'}`. Then, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33710
941