meld-spec
Version:
Specification for the Meld scripting language
182 lines (181 loc) • 5.24 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.embedInvalidTests = void 0;
/**
* Invalid test cases for the @embed 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.embedInvalidTests = [
// Indentation errors
{
name: 'indented-directive',
input: ' @embed [file.md]',
expected: {
type: 'Error',
error: 'Directives must appear at the start of a line'
},
description: 'Directives cannot be indented'
},
// Empty paths
{
name: 'empty-path',
input: '@embed []',
expected: {
type: 'Error',
error: 'Empty path in @embed directive'
},
description: 'Path cannot be empty'
},
{
name: 'whitespace-path',
input: '@embed [ ]',
expected: {
type: 'Error',
error: 'Empty path in @embed directive'
},
description: 'Path cannot be only whitespace'
},
// Invalid section syntax
{
name: 'empty-section',
input: '@embed [file.md #]',
expected: {
type: 'Error',
error: 'Empty section name'
},
description: 'Section marker must be followed by text'
},
{
name: 'whitespace-section',
input: '@embed [file.md # ]',
expected: {
type: 'Error',
error: 'Empty section name'
},
description: 'Section name cannot be only whitespace'
},
{
name: 'missing-section-space',
input: '@embed [file.md #section]',
expected: {
type: 'Error',
error: 'Invalid section syntax: missing space after #'
},
description: 'Must have space after section marker'
},
// Invalid name syntax
{
name: 'invalid-name-hyphen',
input: '@embed { invalid-name } from [file.md]',
expected: {
type: 'Error',
error: 'Invalid identifier: invalid-name'
},
description: 'Names cannot contain hyphens'
},
{
name: 'invalid-name-number-start',
input: '@embed { 123name } from [file.md]',
expected: {
type: 'Error',
error: 'Invalid identifier: 123name'
},
description: 'Names cannot start with numbers'
},
{
name: 'invalid-name-special-chars',
input: '@embed { name! } from [file.md]',
expected: {
type: 'Error',
error: 'Invalid identifier: name!'
},
description: 'Names cannot contain special characters'
},
// Invalid header levels
{
name: 'too-many-hashes',
input: '@embed [file.md] as ######',
expected: {
type: 'Error',
error: 'Invalid header level: maximum is 6'
},
description: 'Header levels cannot exceed 6'
},
{
name: 'invalid-header-marker',
input: '@embed [file.md] as ##.#',
expected: {
type: 'Error',
error: 'Invalid header level syntax'
},
description: 'Header markers must be consecutive hashes'
},
// Syntax errors
{
name: 'missing-closing-bracket',
input: '@embed [file.md',
expected: {
type: 'Error',
error: 'Unclosed [ in @embed directive'
},
description: 'Must close brackets'
},
{
name: 'missing-opening-bracket',
input: '@embed file.md]',
expected: {
type: 'Error',
error: 'Missing [ in @embed directive'
},
description: 'Must open brackets'
},
{
name: 'missing-closing-brace',
input: '@embed { name from [file.md]',
expected: {
type: 'Error',
error: 'Unclosed { in @embed directive'
},
description: 'Must close braces'
},
// Invalid combinations
{
name: 'section-and-names',
input: '@embed { name } from [file.md # Section]',
expected: {
type: 'Error',
error: 'Cannot combine named embed with section'
},
description: 'Cannot use both named embed and section syntax'
},
{
name: 'header-and-names',
input: '@embed { name } from [file.md] as ##',
expected: {
type: 'Error',
error: 'Cannot combine named embed with header level'
},
description: 'Cannot use both named embed and header level'
},
// Path validation
{
name: 'absolute-path',
input: '@embed [/absolute/path.md]',
expected: {
type: 'Error',
error: 'Absolute paths not allowed in @embed'
},
description: 'Cannot use absolute paths'
},
{
name: 'parent-dir-path',
input: '@embed [../../outside.md]',
expected: {
type: 'Error',
error: 'Path attempts to access parent directory'
},
description: 'Cannot access parent directories'
}
];