diff --git a/src/devtools/tests.ts b/src/devtools/tests.ts index e0479a8..e73b4bc 100644 --- a/src/devtools/tests.ts +++ b/src/devtools/tests.ts @@ -6,6 +6,7 @@ import { scriptFramesInRange, type ActionRuntime, } from '@/lib/actions' +import { parseScript } from '@/lib/scriptDsl' import type { Action } from '@/types/scene' import { sampleLayer, lerpColor } from '@/lib/interpolate' import { snapToCandidates } from '@/lib/timelineSnap' @@ -3382,6 +3383,125 @@ export function registerAllTests(): void { }) }) + suite('scriptDsl — parser', () => { + test('parses bare commands', () => { + const { actions, errors } = parseScript('play\npause\nrewind') + expect(errors).toHaveLength(0) + expect(actions.map((a) => a.type)).toEqual(['play', 'pause', 'rewindToLoop']) + }) + + test('skips blank lines and comments', () => { + const src = [ + '// leading comment', + '', + 'play // trailing comment', + ' ', + 'pause', + ].join('\n') + const { actions, errors } = parseScript(src) + expect(errors).toHaveLength(0) + expect(actions.map((a) => a.type)).toEqual(['play', 'pause']) + }) + + test('jump accepts seconds, #frame, and @marker', () => { + const { actions, errors } = parseScript('jump 2.5\njump #60\njump @intro') + expect(errors).toHaveLength(0) + expect(actions[0]).toEqual({ type: 'jumpTo', time: 2.5 }) + expect(actions[1]).toEqual({ type: 'jumpToFrame', frame: 60 }) + expect(actions[2]).toEqual({ type: 'jumpToMarker', name: 'intro' }) + }) + + test('jump reports invalid arguments', () => { + const { actions, errors } = parseScript('jump\njump abc\njump #xx\njump @') + expect(actions).toHaveLength(0) + expect(errors).toHaveLength(4) + }) + + test('state requires btn: