meld-spec
Version:
Specification for the Meld scripting language
172 lines (171 loc) • 4.97 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.pathInvalidTests = void 0;
/**
* Invalid test cases for the @path 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.pathInvalidTests = [
// Invalid identifiers
{
name: 'empty-identifier',
input: '@path = [docs]',
expected: {
type: 'Error',
error: 'Path identifier cannot be empty'
},
description: 'Path identifier is required'
},
{
name: 'invalid-identifier',
input: '@path 123path = [docs]',
expected: {
type: 'Error',
error: 'Invalid identifier: must start with letter or underscore'
},
description: 'Path identifier must be valid'
},
// Invalid path syntax
{
name: 'empty-path',
input: '@path docs = []',
expected: {
type: 'Error',
error: 'Empty path value'
},
description: 'Path value cannot be empty'
},
{
name: 'missing-brackets',
input: '@path docs = path/to/file',
expected: {
type: 'Error',
error: 'Path value must be enclosed in []'
},
description: 'Path must be in brackets'
},
{
name: 'unclosed-brackets',
input: '@path docs = [path/to/file',
expected: {
type: 'Error',
error: 'Unclosed [ in path value'
},
description: 'Path brackets must be closed'
},
// Invalid special variables
{
name: 'bare-homepath',
input: '@path docs = [$HOMEPATH]',
expected: {
type: 'Error',
error: 'Special path variables must be followed by /'
},
description: 'HOMEPATH requires path segment'
},
{
name: 'bare-projectpath',
input: '@path src = [$PROJECTPATH]',
expected: {
type: 'Error',
error: 'Special path variables must be followed by /'
},
description: 'PROJECTPATH requires path segment'
},
{
name: 'bare-home-alias',
input: '@path docs = [$~]',
expected: {
type: 'Error',
error: 'Special path variables must be followed by /'
},
description: 'Home alias requires path segment'
},
{
name: 'bare-project-alias',
input: '@path src = [$.]',
expected: {
type: 'Error',
error: 'Special path variables must be followed by /'
},
description: 'Project alias requires path segment'
},
// Invalid variable usage
{
name: 'nested-variable',
input: '@path docs = [$HOMEPATH/${path${inner}}]',
expected: {
type: 'Error',
error: 'Nested variable interpolation not allowed'
},
description: 'Cannot nest variable references'
},
{
name: 'data-variable',
input: '@path docs = [$HOMEPATH/#{data}]',
expected: {
type: 'Error',
error: 'Data variables not allowed in path'
},
description: 'Cannot use data variables in path'
},
{
name: 'format-operator',
input: '@path docs = [$HOMEPATH/${var>>(upper)}]',
expected: {
type: 'Error',
error: 'Format operator not allowed in path'
},
description: 'Cannot use format operator in path'
},
// Invalid path segments
{
name: 'absolute-path',
input: '@path docs = [/absolute/path]',
expected: {
type: 'Error',
error: 'Absolute paths not allowed'
},
description: 'Cannot use absolute paths'
},
{
name: 'parent-traversal',
input: '@path docs = [../parent]',
expected: {
type: 'Error',
error: 'Parent directory traversal not allowed'
},
description: 'Cannot traverse to parent directory'
},
// Indentation errors
{
name: 'indented-directive',
input: ' @path docs = [path]',
expected: {
type: 'Error',
error: 'Directives must appear at start of line'
},
description: 'Directives cannot be indented'
},
// Syntax errors
{
name: 'missing-equals',
input: '@path docs [path]',
expected: {
type: 'Error',
error: 'Missing = in path assignment'
},
description: 'Path assignment requires equals sign'
},
{
name: 'extra-tokens',
input: '@path docs = [path] extra',
expected: {
type: 'Error',
error: 'Unexpected tokens after path value'
},
description: 'No extra tokens allowed after value'
}
];