UNPKG

meld-spec

Version:

Specification for the Meld scripting language

190 lines (189 loc) 5.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.defineInvalidTests = void 0; /** * Invalid test cases for the @define directive that implementations must handle correctly. * These cases should either: * 1. Throw an error with a helpful message * 2. Return a partial AST marking the error */ exports.defineInvalidTests = [ // Invalid command body { name: 'non-run-directive', input: '@define cmd = @embed [file.md]', expected: { type: 'Error', error: 'Command body must be an @run directive' }, description: 'Cannot use other directives as command body' }, { name: 'string-body', input: '@define cmd = "hello"', expected: { type: 'Error', error: 'Command body must be an @run directive' }, description: 'Cannot use string as command body' }, // Invalid identifiers { name: 'empty-identifier', input: '@define = @run [echo "hello"]', expected: { type: 'Error', error: 'Command name cannot be empty' }, description: 'Command name is required' }, { name: 'invalid-identifier', input: '@define 123cmd = @run [echo "hello"]', expected: { type: 'Error', error: 'Invalid command name: must start with letter or underscore' }, description: 'Command name must be valid identifier' }, { name: 'special-chars', input: '@define cmd! = @run [echo "hello"]', expected: { type: 'Error', error: 'Invalid command name: cannot contain special characters' }, description: 'Command name cannot have special characters' }, // Invalid parameters { name: 'empty-param-list', input: '@define cmd() = @run [echo "hello"]', expected: { type: 'Error', error: 'Empty parameter list not allowed' }, description: 'Must have at least one parameter if using parentheses' }, { name: 'invalid-param-name', input: '@define cmd(123param) = @run [echo ${123param}]', expected: { type: 'Error', error: 'Invalid parameter name: must start with letter or underscore' }, description: 'Parameter names must be valid identifiers' }, { name: 'unused-param', input: '@define cmd(param) = @run [echo "hello"]', expected: { type: 'Error', error: 'Parameter param is not used in command body' }, description: 'All parameters must be used in command' }, { name: 'duplicate-params', input: '@define cmd(param, param) = @run [echo ${param}]', expected: { type: 'Error', error: 'Duplicate parameter name: param' }, description: 'Parameter names must be unique' }, // Invalid metadata fields { name: 'invalid-field', input: '@define cmd.invalid = "value"', expected: { type: 'Error', error: 'Invalid metadata field: must be risk, risk.high, risk.med, risk.low, about, or meta' }, description: 'Only specific metadata fields are allowed' }, { name: 'empty-field', input: '@define cmd. = "value"', expected: { type: 'Error', error: 'Empty metadata field' }, description: 'Metadata field cannot be empty' }, { name: 'invalid-risk-level', input: '@define cmd.risk.invalid = "value"', expected: { type: 'Error', error: 'Invalid risk level: must be high, med, or low' }, description: 'Only specific risk levels are allowed' }, { name: 'run-with-field', input: '@define cmd.risk = @run [echo "hello"]', expected: { type: 'Error', error: 'Metadata fields must have string values' }, description: 'Cannot use @run with metadata fields' }, // Syntax errors { name: 'missing-equals', input: '@define cmd @run [echo "hello"]', expected: { type: 'Error', error: 'Missing = in @define directive' }, description: 'Must have equals sign' }, { name: 'missing-closing-paren', input: '@define cmd(param = @run [echo ${param}]', expected: { type: 'Error', error: 'Unclosed ( in parameter list' }, description: 'Must close parameter list' }, { name: 'missing-param-comma', input: '@define cmd(param1 param2) = @run [echo ${param1} ${param2}]', expected: { type: 'Error', error: 'Missing comma between parameters' }, description: 'Parameters must be comma-separated' }, // Indentation errors { name: 'indented-directive', input: ' @define cmd = @run [echo "hello"]', expected: { type: 'Error', error: 'Directives must appear at the start of a line' }, description: 'Directives cannot be indented' }, // Variable errors { name: 'data-var-in-command', input: '@define cmd = @run [echo #{data}]', expected: { type: 'Error', error: 'Data variables not allowed in command arguments' }, description: 'Cannot use data variables in commands' }, { name: 'nested-var', input: '@define cmd(param) = @run [echo ${var${param}}]', expected: { type: 'Error', error: 'Nested variable interpolation not allowed' }, description: 'Cannot nest variable references' } ];