meld-spec
Version:
Specification for the Meld scripting language
202 lines (201 loc) • 5.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dataInvalidTests = void 0;
/**
* Invalid test cases for the @data 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.dataInvalidTests = [
// Invalid identifiers
{
name: 'empty-identifier',
input: '@data = {{ value: 1 }}',
expected: {
type: 'Error',
error: 'Data identifier cannot be empty'
},
description: 'Data identifier is required'
},
{
name: 'invalid-identifier',
input: '@data 123data = {{ value: 1 }}',
expected: {
type: 'Error',
error: 'Invalid identifier: must start with letter or underscore'
},
description: 'Data identifier must be valid'
},
// Invalid object literals
{
name: 'unclosed-object',
input: '@data config = {{ name: "test"',
expected: {
type: 'Error',
error: 'Unclosed object literal'
},
description: 'Object literals must be closed'
},
{
name: 'invalid-key',
input: '@data config = {{ 123: "value" }}',
expected: {
type: 'Error',
error: 'Invalid object key: must be valid identifier'
},
description: 'Object keys must be valid identifiers'
},
{
name: 'missing-colon',
input: '@data config = {{ name "value" }}',
expected: {
type: 'Error',
error: 'Missing : in object property'
},
description: 'Object properties require colon'
},
// Invalid array literals
{
name: 'unclosed-array',
input: '@data list = [[ 1, 2, 3',
expected: {
type: 'Error',
error: 'Unclosed array literal'
},
description: 'Array literals must be closed'
},
{
name: 'missing-comma',
input: '@data list = [[ 1 2 3 ]]',
expected: {
type: 'Error',
error: 'Missing comma between array elements'
},
description: 'Array elements must be comma-separated'
},
// Schema errors
{
name: 'invalid-schema',
input: '@data config : 123Schema = {{ value: 1 }}',
expected: {
type: 'Error',
error: 'Invalid schema identifier'
},
description: 'Schema must be valid identifier'
},
{
name: 'missing-schema-equals',
input: '@data config : Schema {{ value: 1 }}',
expected: {
type: 'Error',
error: 'Missing = after schema'
},
description: 'Schema must be followed by equals'
},
// Invalid embed source
{
name: 'invalid-embed',
input: '@data config = @embed config.json',
expected: {
type: 'Error',
error: 'Invalid embed syntax: missing []'
},
description: 'Embed source must use proper syntax'
},
{
name: 'empty-embed-path',
input: '@data config = @embed []',
expected: {
type: 'Error',
error: 'Empty path in embed source'
},
description: 'Embed path cannot be empty'
},
// Invalid run source
{
name: 'invalid-run',
input: '@data output = @run echo "hello"',
expected: {
type: 'Error',
error: 'Invalid run syntax: missing []'
},
description: 'Run source must use proper syntax'
},
{
name: 'empty-run-command',
input: '@data output = @run []',
expected: {
type: 'Error',
error: 'Empty command in run source'
},
description: 'Run command cannot be empty'
},
// Invalid call source
{
name: 'invalid-call',
input: '@data response = @call api',
expected: {
type: 'Error',
error: 'Invalid call syntax: missing method and path'
},
description: 'Call source must specify method and path'
},
{
name: 'invalid-call-method',
input: '@data response = @call api.invalid [/path]',
expected: {
type: 'Error',
error: 'Invalid HTTP method in call source'
},
description: 'Call method must be valid HTTP method'
},
// Invalid values
{
name: 'invalid-json',
input: '@data config = {{ function() {} }}',
expected: {
type: 'Error',
error: 'Invalid value: must be valid JSON'
},
description: 'Values must be valid JSON'
},
{
name: 'undefined-value',
input: '@data config = {{ value: undefined }}',
expected: {
type: 'Error',
error: 'Invalid value: undefined not allowed'
},
description: 'Undefined not allowed in values'
},
// Indentation errors
{
name: 'indented-directive',
input: ' @data config = {{ value: 1 }}',
expected: {
type: 'Error',
error: 'Directives must appear at start of line'
},
description: 'Directives cannot be indented'
},
// Syntax errors
{
name: 'missing-equals',
input: '@data config {{ value: 1 }}',
expected: {
type: 'Error',
error: 'Missing = in data assignment'
},
description: 'Data assignment requires equals sign'
},
{
name: 'extra-tokens',
input: '@data config = {{ value: 1 }} extra',
expected: {
type: 'Error',
error: 'Unexpected tokens after data value'
},
description: 'No extra tokens allowed after value'
}
];