Files
Genarrative/src/services/llmParsers.test.ts
kdletters cbc27bad4a
Some checks failed
CI / verify (push) Has been cancelled
init with react+axum+spacetimedb
2026-04-26 18:06:23 +08:00

30 lines
747 B
TypeScript

import {describe, expect, it} from 'vitest';
import {parseJsonResponseText, parseLineListContent} from './llmParsers';
describe('llmParsers', () => {
it('parses fenced json payloads', () => {
expect(
parseJsonResponseText('```json\n{"storyText":"hello","options":[]}\n```'),
).toEqual({
storyText: 'hello',
options: [],
});
});
it('parses embedded json objects', () => {
expect(
parseJsonResponseText('prefix {"storyText":"hello","options":[]} suffix'),
).toEqual({
storyText: 'hello',
options: [],
});
});
it('extracts compact suggestion lines', () => {
expect(
parseLineListContent('- first\n2. second\nthird', 2),
).toEqual(['first', 'second']);
});
});