UNPKG

meld-spec

Version:

Specification for the Meld scripting language

191 lines (190 loc) 5.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.callInvalidTests = void 0; /** * Invalid test cases for the @call 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.callInvalidTests = [ // Invalid API references { name: 'undefined-api', input: '@call undefined_api.get [/test]', expected: { type: 'Error', error: 'API undefined_api not defined' }, description: 'Cannot call undefined API' }, { name: 'invalid-api-name', input: '@call 123api.get [/test]', expected: { type: 'Error', error: 'Invalid API identifier: must start with letter or underscore' }, description: 'API name must be valid identifier' }, // Invalid methods { name: 'invalid-method', input: '@call api.invalid [/test]', expected: { type: 'Error', error: 'Invalid HTTP method: must be GET, POST, PUT, PATCH, or DELETE' }, description: 'Method must be valid HTTP method' }, { name: 'missing-method', input: '@call api [/test]', expected: { type: 'Error', error: 'Missing HTTP method in API call' }, description: 'Method is required' }, // Invalid paths { name: 'missing-path-brackets', input: '@call api.get /test', expected: { type: 'Error', error: 'Path must be enclosed in []' }, description: 'Path must be in brackets' }, { name: 'empty-path', input: '@call api.get []', expected: { type: 'Error', error: 'Empty path in API call' }, description: 'Path cannot be empty' }, { name: 'invalid-path-start', input: '@call api.get [test]', expected: { type: 'Error', error: 'Path must start with /' }, description: 'Path must be absolute' }, // Invalid endpoints { name: 'undefined-endpoint', input: '@call api.undefined.get', expected: { type: 'Error', error: 'Endpoint undefined not defined for API api' }, description: 'Cannot call undefined endpoint' }, { name: 'invalid-endpoint-segment', input: '@call api.123endpoint.get', expected: { type: 'Error', error: 'Invalid endpoint segment: must be valid identifier' }, description: 'Endpoint segments must be valid identifiers' }, { name: 'endpoint-with-path', input: '@call api.users.get [/extra]', expected: { type: 'Error', error: 'Cannot specify path when using endpoint' }, description: 'Endpoint calls cannot have path' }, // Invalid payloads { name: 'invalid-payload-syntax', input: '@call api.post [/test] { invalid }', expected: { type: 'Error', error: 'Payload must be object literal with {{ }}' }, description: 'Payload must use proper syntax' }, { name: 'get-with-payload', input: '@call api.get [/test] {{ data: true }}', expected: { type: 'Error', error: 'GET requests cannot have payload' }, description: 'GET cannot have payload' }, { name: 'delete-with-payload', input: '@call api.delete [/test] {{ data: true }}', expected: { type: 'Error', error: 'DELETE requests cannot have payload' }, description: 'DELETE cannot have payload' }, { name: 'unclosed-payload', input: '@call api.post [/test] {{ data: true', expected: { type: 'Error', error: 'Unclosed payload object' }, description: 'Payload must be closed' }, // Invalid variable usage { name: 'nested-variable', input: '@call api.get [/users/${id${nested}}]', expected: { type: 'Error', error: 'Nested variable interpolation not allowed' }, description: 'Cannot nest variables' }, { name: 'format-in-path', input: '@call api.get [/users/${id>>(number)}]', expected: { type: 'Error', error: 'Format operator not allowed in path' }, description: 'Cannot use format in path' }, // Indentation errors { name: 'indented-directive', input: ' @call api.get [/test]', expected: { type: 'Error', error: 'Directives must appear at start of line' }, description: 'Directives cannot be indented' }, // Syntax errors { name: 'missing-api', input: '@call .get [/test]', expected: { type: 'Error', error: 'Missing API identifier' }, description: 'API identifier is required' }, { name: 'extra-tokens', input: '@call api.get [/test] extra', expected: { type: 'Error', error: 'Unexpected tokens after API call' }, description: 'No extra tokens allowed' } ];