|
| 1 | +import { |
| 2 | + ensureSyntaxTree, |
| 3 | + StreamLanguage, |
| 4 | + type StreamParser, |
| 5 | + syntaxTree, |
| 6 | +} from '@codemirror/language'; |
| 7 | +import { EditorState } from '@codemirror/state'; |
| 8 | + |
| 9 | +import { commonMode, fluentMode, webextMode } from './editFieldModes'; |
| 10 | + |
| 11 | +const LONG_DOC = `<a ${'x '.repeat(300)}\n${'y '.repeat(30)}>`; |
| 12 | + |
| 13 | +function fullyParsed(mode: StreamParser<any>, doc: string): EditorState { |
| 14 | + const state = EditorState.create({ |
| 15 | + doc, |
| 16 | + extensions: [StreamLanguage.define(mode)], |
| 17 | + }); |
| 18 | + ensureSyntaxTree(state, state.doc.length, 5000); |
| 19 | + return state; |
| 20 | +} |
| 21 | + |
| 22 | +describe.each([ |
| 23 | + ['fluent', fluentMode], |
| 24 | + ['common', commonMode], |
| 25 | + ['webext', webextMode], |
| 26 | +])('%s mode', (_name, mode: StreamParser<any>) => { |
| 27 | + test('applies an edit resuming from a parser state snapshot (#4438)', () => { |
| 28 | + let state = fullyParsed(mode, LONG_DOC); |
| 29 | + state = state.update({ |
| 30 | + changes: { from: state.doc.length, insert: 'X' }, |
| 31 | + }).state; |
| 32 | + ensureSyntaxTree(state, state.doc.length, 5000); |
| 33 | + |
| 34 | + expect(state.doc.toString()).toBe(`${LONG_DOC}X`); |
| 35 | + expect(syntaxTree(state).toString()).toBe( |
| 36 | + syntaxTree(fullyParsed(mode, `${LONG_DOC}X`)).toString(), |
| 37 | + ); |
| 38 | + }); |
| 39 | +}); |
0 commit comments