UNPKG

meld-spec

Version:

Specification for the Meld scripting language

279 lines (278 loc) 8.23 kB
"use strict"; /// <reference types="jest" /> Object.defineProperty(exports, "__esModule", { value: true }); exports.embedTests = void 0; /** * Test cases for the @embed directive that all implementations must pass */ exports.embedTests = [ // Basic usage { name: 'basic-embed', input: '@embed [file.md]', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: 'file.md', normalized: './file.md', structured: { base: '.', segments: ['file.md'], variables: {}, cwd: true } } } }, description: 'Basic file embed' }, // Section embedding { name: 'section-embed', input: '@embed [file.md # Introduction]', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: 'file.md', normalized: './file.md', structured: { base: '.', segments: ['file.md'], variables: {}, cwd: true } }, section: 'Introduction' } }, description: 'Embed specific section' }, // Header level adjustment { name: 'header-level', input: '@embed [file.md] as ###', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: 'file.md', normalized: './file.md', structured: { base: '.', segments: ['file.md'], variables: {} } }, headerLevel: 3 } }, description: 'Embed with header level adjustment' }, // Section with header level { name: 'section-with-header', input: '@embed [file.md # Introduction] as ##', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: 'file.md', normalized: './file.md', structured: { base: '.', segments: ['file.md'], variables: {} } }, section: 'Introduction', headerLevel: 2 } }, description: 'Embed section with header level adjustment' }, // Named embed { name: 'named-embed', input: '@embed { config } from [config.json]', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: 'config.json', normalized: './config.json', structured: { base: '.', segments: ['config.json'], variables: {} } }, names: ['config'] } }, description: 'Named embed' }, // Multiple named embeds { name: 'multiple-names', input: '@embed { user, settings } from [data.json]', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: 'data.json', normalized: './data.json', structured: { base: '.', segments: ['data.json'], variables: {} } }, names: ['user', 'settings'] } }, description: 'Multiple named embeds' }, // Under header { name: 'under-header', input: '@embed [content.md] under My Section', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: 'content.md', normalized: './content.md', structured: { base: '.', segments: ['content.md'], variables: {} } }, underHeader: 'My Section' } }, description: 'Embed under header' }, // Complex paths { name: 'relative-path', input: '@embed [../path/to/file.md]', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: '../path/to/file.md', normalized: '../path/to/file.md', structured: { base: '..', segments: ['path', 'to', 'file.md'], variables: {} } } } }, description: 'Embed with relative path' }, // Variable interpolation { name: 'variable-path', input: '@embed [${file_path}]', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: '${file_path}', normalized: './${file_path}', structured: { base: '.', segments: ['${file_path}'], variables: { text: ['file_path'] }, cwd: true } } } }, description: 'Embed with variable in path' }, // Path with brackets { name: 'path-with-brackets', input: '@embed [path/with [brackets].md]', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: 'path/with [brackets].md', normalized: './path/with [brackets].md', structured: { base: '.', segments: ['path', 'with [brackets].md'], variables: {}, cwd: false } } } }, description: 'Embed with brackets in path' }, // Special path variables { name: 'home-path', input: '@embed [$~/docs/file.md]', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: '$~/docs/file.md', normalized: '$HOMEPATH/docs/file.md', structured: { base: '$~', segments: ['docs', 'file.md'], variables: { special: ['HOMEPATH'] } } } } }, description: 'Path with home alias' }, // Project path alias { name: 'project-path', input: '@embed [$./src/file.md]', expected: { type: 'Directive', directive: { kind: 'embed', path: { raw: '$./src/file.md', normalized: '$PROJECTPATH/src/file.md', structured: { base: '$.', segments: ['src', 'file.md'], variables: { special: ['PROJECTPATH'] } } } } }, description: 'Path with project alias' } ];