Path: blob/main/src/vs/workbench/contrib/debug/test/browser/debugHover.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';7import { NullLogService } from '../../../../../platform/log/common/log.js';8import { findExpressionInStackFrame } from '../../browser/debugHover.js';9import type { IExpression, IScope } from '../../common/debug.js';10import { Scope, StackFrame, Thread, Variable } from '../../common/debugModel.js';11import { Source } from '../../common/debugSource.js';12import { createTestSession } from './callStack.test.js';13import { createMockDebugModel, mockUriIdentityService } from './mockDebugModel.js';1415suite('Debug - Hover', () => {16const disposables = ensureNoDisposablesAreLeakedInTestSuite();1718test('find expression in stack frame', async () => {19const model = createMockDebugModel(disposables);20const session = disposables.add(createTestSession(model));2122const thread = new class extends Thread {23public override getCallStack(): StackFrame[] {24return [stackFrame];25}26}(session, 'mockthread', 1);2728const firstSource = new Source({29name: 'internalModule.js',30path: 'a/b/c/d/internalModule.js',31sourceReference: 10,32}, 'aDebugSessionId', mockUriIdentityService, new NullLogService());3334const stackFrame = new class extends StackFrame {35override getScopes(): Promise<IScope[]> {36return Promise.resolve([scope]);37}38}(thread, 1, firstSource, 'app.js', 'normal', { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 10 }, 1, true);394041const scope = new class extends Scope {42override getChildren(): Promise<IExpression[]> {43return Promise.resolve([variableA]);44}45}(stackFrame, 1, 'local', 1, false, 10, 10);4647const variableA = new class extends Variable {48override getChildren(): Promise<IExpression[]> {49return Promise.resolve([variableB]);50}51}(session, 1, scope, 2, 'A', 'A', undefined, 0, 0, undefined, {}, 'string');52const variableB = new Variable(session, 1, scope, 2, 'B', 'A.B', undefined, 0, 0, undefined, {}, 'string');5354assert.strictEqual(await findExpressionInStackFrame(stackFrame, []), undefined);55assert.strictEqual(await findExpressionInStackFrame(stackFrame, ['A']), variableA);56assert.strictEqual(await findExpressionInStackFrame(stackFrame, ['doesNotExist', 'no']), undefined);57assert.strictEqual(await findExpressionInStackFrame(stackFrame, ['a']), undefined);58assert.strictEqual(await findExpressionInStackFrame(stackFrame, ['B']), undefined);59assert.strictEqual(await findExpressionInStackFrame(stackFrame, ['A', 'B']), variableB);60assert.strictEqual(await findExpressionInStackFrame(stackFrame, ['A', 'C']), undefined);6162// We do not search in expensive scopes63scope.expensive = true;64assert.strictEqual(await findExpressionInStackFrame(stackFrame, ['A']), undefined);65});66});676869