MCPcopy
hub / github.com/VSCodeVim/Vim / testIt

Function testIt

test/testSimplifier.ts:236–332  ·  view source on GitHub ↗
(testObj: ITestObject)

Source from the content-addressed store, hash-verified

234}
235
236export async function testIt(testObj: ITestObject): Promise<ModeHandler> {
237 const editor = vscode.window.activeTextEditor;
238 assert(editor, 'Expected an active editor');
239
240 const start = DocState.parse(testObj.start);
241 const end = DocState.parse(testObj.end);
242
243 if (testObj.editorOptions) {
244 editor.options = testObj.editorOptions;
245 }
246
247 await applyDocState(editor, start);
248
249 if (testObj.saveDocBeforeTest) {
250 assert.ok(await editor.document.save(), 'Save failed');
251 }
252
253 // Generate a brand new ModeHandler for this editor
254 ModeHandlerMap.clear();
255 const [modeHandler, _] = await ModeHandlerMap.getOrCreate(editor);
256
257 assertDocState(modeHandler.vimState, start);
258
259 globalState.lastInvokedMacro = undefined;
260 globalState.jumpTracker.clearJumps();
261
262 Register.clearAllRegisters();
263
264 if (testObj.stub) {
265 const confirmStub = sinon
266 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
267 .stub(testObj.stub.stubClass.prototype, testObj.stub.methodName)
268 .resolves(testObj.stub.returnValue);
269 await modeHandler.handleMultipleKeyEvents(tokenizeKeySequence(testObj.keysPressed), false);
270 confirmStub.restore();
271 } else {
272 // Assumes key presses are single characters for now
273 await modeHandler.handleMultipleKeyEvents(tokenizeKeySequence(testObj.keysPressed), false);
274 }
275
276 assertDocState(modeHandler.vimState, end);
277
278 if (testObj.endMode !== undefined) {
279 assert.equal(
280 Mode[modeHandler.vimState.currentMode],
281 Mode[testObj.endMode],
282 "Didn't enter correct mode.",
283 );
284 }
285
286 if (testObj.endFsPath !== undefined) {
287 assert.equal(
288 vscode.window.activeTextEditor?.document.uri.fsPath,
289 typeof testObj.endFsPath === 'string' ? testObj.endFsPath : testObj.endFsPath(),
290 'Active document is wrong.',
291 );
292 }
293

Callers 1

resolveTestFunction · 0.90

Calls 15

applyDocStateFunction · 0.85
assertDocStateFunction · 0.85
tokenizeKeySequenceFunction · 0.85
stripBarFunction · 0.85
getOrCreateMethod · 0.80
clearJumpsMethod · 0.80
clearAllRegistersMethod · 0.80
getTextMethod · 0.80
findMethod · 0.80
getMethod · 0.65
parseMethod · 0.45

Tested by 1

resolveTestFunction · 0.72