Files
jsonPrism/src/lib/__tests__/editor-language.test.ts
T
poli0981andClaude Opus 5.5 e3d0e8b917 feat: 2.1.0 — JSONC → JSON (#161)
JSONC (JSON with comments) converts to standard JSON as a new input-only format: hand-written parser, comments and trailing commas removed at the same offsets, token-level output that keeps every number and key as written. Input-only formats in the framework (meta.inputOnly), reverse errors with line/column, JSONC editor highlighting and lint, a one-click hint in the JSON → direction, strings in four locales, docs and the 2.1.0 version bump.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 12:56:58 +07:00

46 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import type { FormatId } from '@/converters/types';
import { ALL_FORMATS } from '@/converters/registry';
import { editorLanguageFor, outputLanguageFor } from '../editor-language';
/** Expected CodeMirror language for text written in each format. */
const FORMAT_LANGUAGE: Record<FormatId, string> = {
jsonl: 'jsonl',
jsonc: 'jsonc',
csv: 'plain',
tsv: 'plain',
yaml: 'yaml',
xml: 'xml',
toml: 'toml',
resx: 'xml',
markdown: 'markdown',
sql: 'sql',
bson: 'plain',
cbor: 'plain',
msgpack: 'plain',
};
describe('editorLanguageFor (input editor)', () => {
it('always highlights JSON going forward', () => {
for (const format of ALL_FORMATS) {
expect(editorLanguageFor(format, 'forward')).toBe('json');
}
});
it.each(ALL_FORMATS)('uses the %s grammar going back', (format) => {
expect(editorLanguageFor(format, 'reverse')).toBe(FORMAT_LANGUAGE[format]);
});
});
describe('outputLanguageFor (read-only output editor)', () => {
it.each(ALL_FORMATS)('uses the %s grammar going forward', (format) => {
expect(outputLanguageFor(format, 'forward')).toBe(FORMAT_LANGUAGE[format]);
});
it('always highlights JSON going back', () => {
for (const format of ALL_FORMATS) {
expect(outputLanguageFor(format, 'reverse')).toBe('json');
}
});
});