meld-spec
Version:
Specification for the Meld scripting language
211 lines (210 loc) • 6.72 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.apiInvalidTests = void 0;
/**
* Invalid test cases for the @api 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.apiInvalidTests = [
// Invalid identifiers
{
name: 'empty-identifier',
input: '@api = {{ baseUrl: "https://api.com" }}',
expected: {
type: 'Error',
error: 'API identifier cannot be empty'
},
description: 'API identifier is required'
},
{
name: 'invalid-identifier',
input: '@api 123api = {{ baseUrl: "https://api.com" }}',
expected: {
type: 'Error',
error: 'Invalid identifier: must start with letter or underscore'
},
description: 'API identifier must be valid'
},
{
name: 'invalid-endpoint-segment',
input: '@api api.123endpoint = {{ path: "/test" }}',
expected: {
type: 'Error',
error: 'Invalid endpoint identifier segment: must be valid identifier'
},
description: 'Endpoint path segments must be valid identifiers'
},
// Missing required fields
{
name: 'missing-baseurl',
input: '@api github = {{ timeout: 5000 }}',
expected: {
type: 'Error',
error: 'API configuration requires baseUrl'
},
description: 'baseUrl is required for API configuration'
},
{
name: 'empty-baseurl',
input: '@api github = {{ baseUrl: "" }}',
expected: {
type: 'Error',
error: 'baseUrl cannot be empty'
},
description: 'baseUrl must have value'
},
// Invalid URL formats
{
name: 'invalid-baseurl',
input: '@api github = {{ baseUrl: "not a url" }}',
expected: {
type: 'Error',
error: 'Invalid baseUrl: must be valid URL'
},
description: 'baseUrl must be valid URL'
},
{
name: 'relative-baseurl',
input: '@api github = {{ baseUrl: "/api" }}',
expected: {
type: 'Error',
error: 'Invalid baseUrl: must be absolute URL'
},
description: 'baseUrl must be absolute'
},
// Invalid endpoint paths
{
name: 'absolute-endpoint-path',
input: '@api github.issues = {{ path: "https://api.github.com/issues" }}',
expected: {
type: 'Error',
error: 'Endpoint path must be relative'
},
description: 'Endpoint paths must be relative'
},
{
name: 'empty-endpoint-path',
input: '@api github.issues = {{ path: "" }}',
expected: {
type: 'Error',
error: 'Endpoint path cannot be empty'
},
description: 'Endpoint path must have value'
},
// Invalid methods
{
name: 'invalid-method',
input: '@api github.issues = {{ path: "/issues", methods: ["INVALID"] }}',
expected: {
type: 'Error',
error: 'Invalid HTTP method: must be GET, POST, PUT, PATCH, or DELETE'
},
description: 'Methods must be valid HTTP methods'
},
{
name: 'empty-methods',
input: '@api github.issues = {{ path: "/issues", methods: [] }}',
expected: {
type: 'Error',
error: 'Methods array cannot be empty'
},
description: 'Methods must contain at least one method'
},
{
name: 'duplicate-methods',
input: '@api github.issues = {{ path: "/issues", methods: ["GET", "GET"] }}',
expected: {
type: 'Error',
error: 'Duplicate HTTP method in methods array'
},
description: 'Methods must be unique'
},
// Invalid object syntax
{
name: 'missing-braces',
input: '@api github = baseUrl: "https://api.github.com"',
expected: {
type: 'Error',
error: 'API configuration must be object literal'
},
description: 'Configuration must be in braces'
},
{
name: 'unclosed-braces',
input: '@api github = {{ baseUrl: "https://api.github.com"',
expected: {
type: 'Error',
error: 'Unclosed object literal'
},
description: 'Object literal must be closed'
},
// Invalid field values
{
name: 'invalid-timeout',
input: '@api github = {{ baseUrl: "https://api.github.com", timeout: "5000" }}',
expected: {
type: 'Error',
error: 'timeout must be a number'
},
description: 'Numeric fields must be numbers'
},
{
name: 'invalid-retries',
input: '@api github = {{ baseUrl: "https://api.github.com", retries: -1 }}',
expected: {
type: 'Error',
error: 'retries must be non-negative'
},
description: 'Retries must be non-negative'
},
// Invalid headers
{
name: 'invalid-header-name',
input: '@api github = {{ baseUrl: "https://api.github.com", headers: { "Invalid:Name": "value" } }}',
expected: {
type: 'Error',
error: 'Invalid header name: cannot contain colon'
},
description: 'Header names must be valid'
},
{
name: 'non-string-header',
input: '@api github = {{ baseUrl: "https://api.github.com", headers: { Accept: 123 } }}',
expected: {
type: 'Error',
error: 'Header values must be strings'
},
description: 'Headers must have string values'
},
// Indentation errors
{
name: 'indented-directive',
input: ' @api github = {{ baseUrl: "https://api.github.com" }}',
expected: {
type: 'Error',
error: 'Directives must appear at start of line'
},
description: 'Directives cannot be indented'
},
// Syntax errors
{
name: 'missing-equals',
input: '@api github {{ baseUrl: "https://api.github.com" }}',
expected: {
type: 'Error',
error: 'Missing = in API assignment'
},
description: 'API assignment requires equals sign'
},
{
name: 'extra-tokens',
input: '@api github = {{ baseUrl: "https://api.github.com" }} extra',
expected: {
type: 'Error',
error: 'Unexpected tokens after API configuration'
},
description: 'No extra tokens allowed after configuration'
}
];