meld-spec
Version:
Specification for the Meld scripting language
64 lines (63 loc) • 2.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.transforms = void 0;
exports.generateVariations = generateVariations;
exports.generateInvalidCases = generateInvalidCases;
exports.generateBoundaryCases = generateBoundaryCases;
/**
* Generates variations of a base example by applying transformations
*/
function generateVariations(baseExample, transforms) {
return transforms.map(transform => ({
input: transform(baseExample.input),
ast: baseExample.ast,
description: `Variation: ${transform.name || 'anonymous'}`
}));
}
/**
* Common transformations that can be applied to examples
*/
exports.transforms = {
addLeadingSpace: (input) => ` ${input}`,
addTrailingSpace: (input) => `${input} `,
addExtraSpaces: (input) => input.replace(/\s+/g, ' '),
addNewlineBefore: (input) => `\n${input}`,
addNewlineAfter: (input) => `${input}\n`,
addComment: (input) => `${input} # comment`,
};
/**
* Generates invalid variations of an example that should fail validation
*/
function generateInvalidCases(baseExample) {
const invalidTransforms = [
// Structural changes that should make the example invalid
(input) => input.replace('@', ''), // Remove directive marker
(input) => input.replace('[', '('), // Change delimiter type
(input) => input.replace(']', ')'), // Change delimiter type
(input) => input.replace(/\s+/g, ''), // Remove all spaces
// Add invalid characters
(input) => `${input}!`,
(input) => input.replace('[', '[!'),
];
return invalidTransforms.map(transform => ({
input: transform(baseExample.input),
ast: baseExample.ast,
description: `Invalid case: ${transform.name || 'anonymous'}`
}));
}
/**
* Generates boundary test cases for numeric values in directives
*/
function generateBoundaryCases(template, field, boundaries) {
return boundaries.map(value => ({
input: template.replace('${value}', value.toString()),
ast: {
type: 'Directive',
directive: {
kind: 'text',
[field]: value
}
},
description: `Boundary case: ${field} = ${value}`
}));
}