meld-spec
Version:
Specification for the Meld scripting language
180 lines (179 loc) • 5.48 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dataTests = void 0;
/**
* Test cases for the @data directive that all implementations must pass
*/
exports.dataTests = [
// Basic value assignments
{
name: 'object-literal',
input: '@data config = {{ name: "test", version: 1 }}',
expected: {
type: 'Directive',
directive: {
kind: 'data',
identifier: 'config',
value: {
name: 'test',
version: 1
},
source: 'literal'
}
},
description: 'Object literal assignment'
},
// Schema validation
{
name: 'with-schema',
input: '@data config : ConfigSchema = {{ name: "test" }}',
expected: {
type: 'Directive',
directive: {
kind: 'data',
identifier: 'config',
schema: 'ConfigSchema',
value: {
name: 'test'
},
source: 'literal'
}
},
description: 'Value with schema validation'
},
// @embed source
{
name: 'embed-source',
input: '@data config = @embed [config.json]',
expected: {
type: 'Directive',
directive: {
kind: 'data',
identifier: 'config',
source: 'embed',
embed: {
kind: 'embed',
path: {
raw: 'config.json',
normalized: './config.json',
structured: {
base: '.',
segments: ['config.json'],
variables: {},
cwd: true
}
}
}
}
},
description: 'Data from embed directive'
},
{
name: 'embed-with-schema',
input: '@data config : ConfigSchema = @embed [config.json]',
expected: {
type: 'Directive',
directive: {
kind: 'data',
identifier: 'config',
schema: 'ConfigSchema',
source: 'embed',
embed: {
kind: 'embed',
path: {
raw: 'config.json',
normalized: './config.json',
structured: {
base: '.',
segments: ['config.json'],
variables: {},
cwd: true
}
}
}
}
},
description: 'Data from embed with schema'
},
// @run source
{
name: 'run-source',
input: '@data output = @run [echo "{\\"key\\": \\"value\\"}"]',
expected: {
type: 'Directive',
directive: {
kind: 'data',
identifier: 'output',
source: 'run',
run: {
kind: 'run',
command: 'echo "{\\"key\\": \\"value\\"}"'
}
}
},
description: 'Data from run directive'
},
// @call source
{
name: 'call-source',
input: '@data response = @call api.get [/data]',
expected: {
type: 'Directive',
directive: {
kind: 'data',
identifier: 'response',
source: 'call',
call: {
kind: 'call',
api: 'api',
method: 'get',
path: '/data'
}
}
},
description: 'Data from API call'
},
// Complex object with variables
{
name: 'complex-object',
input: '@data user = {{\n name: ${name},\n age: 30,\n settings: {\n theme: ${theme},\n enabled: true\n },\n tags: [${tag1}, ${tag2}]\n }}',
expected: {
type: 'Directive',
directive: {
kind: 'data',
identifier: 'user',
value: {
name: '${name}',
age: 30,
settings: {
theme: '${theme}',
enabled: true
},
tags: ['${tag1}', '${tag2}']
},
source: 'literal'
}
},
description: 'Complex object with nested structures and variables'
},
// Special values
{
name: 'special-values',
input: '@data values = {{\n null_value: null,\n bool_true: true,\n bool_false: false,\n number: 42.5\n }}',
expected: {
type: 'Directive',
directive: {
kind: 'data',
identifier: 'values',
value: {
null_value: null,
bool_true: true,
bool_false: false,
number: 42.5
},
source: 'literal'
}
},
description: 'Object with special JSON values'
}
];