Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/debug/test/browser/watchExpressionView.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as assert from 'assert';
7
import * as dom from '../../../../../base/browser/dom.js';
8
import { HighlightedLabel } from '../../../../../base/browser/ui/highlightedlabel/highlightedLabel.js';
9
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
10
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
11
import { TestInstantiationService } from '../../../../../platform/instantiation/test/common/instantiationServiceMock.js';
12
import { WatchExpressionsRenderer } from '../../browser/watchExpressionsView.js';
13
import { Scope, StackFrame, Thread, Variable } from '../../common/debugModel.js';
14
import { MockDebugService, MockSession } from '../common/mockDebug.js';
15
import { workbenchInstantiationService } from '../../../../test/browser/workbenchTestServices.js';
16
import { IHoverService } from '../../../../../platform/hover/browser/hover.js';
17
import { NullHoverService } from '../../../../../platform/hover/test/browser/nullHoverService.js';
18
import { IDebugService, IViewModel } from '../../common/debug.js';
19
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
20
import { TestConfigurationService } from '../../../../../platform/configuration/test/common/testConfigurationService.js';
21
import { DebugExpressionRenderer } from '../../browser/debugExpressionRenderer.js';
22
const $ = dom.$;
23
24
function assertWatchVariable(disposables: Pick<DisposableStore, "add">, watchExpressionsRenderer: WatchExpressionsRenderer, displayType: boolean) {
25
const session = new MockSession();
26
const thread = new Thread(session, 'mockthread', 1);
27
const range = {
28
startLineNumber: 1,
29
startColumn: 1,
30
endLineNumber: undefined!,
31
endColumn: undefined!
32
};
33
const stackFrame = new StackFrame(thread, 1, null!, 'app.js', 'normal', range, 0, true);
34
const scope = new Scope(stackFrame, 1, 'local', 1, false, 10, 10);
35
const node = {
36
element: new Variable(session, 1, scope, 2, 'foo', 'bar.foo', undefined, 0, 0, undefined, {}, 'string'),
37
depth: 0,
38
visibleChildrenCount: 1,
39
visibleChildIndex: -1,
40
collapsible: false,
41
collapsed: false,
42
visible: true,
43
filterData: undefined,
44
children: []
45
};
46
const expression = $('.');
47
const name = $('.');
48
const type = $('.');
49
const value = $('.');
50
const label = disposables.add(new HighlightedLabel(name));
51
const lazyButton = $('.');
52
const inputBoxContainer = $('.');
53
const elementDisposable = disposables.add(new DisposableStore());
54
const templateDisposable = disposables.add(new DisposableStore());
55
const currentElement = undefined;
56
const data = {
57
expression,
58
name,
59
type,
60
value,
61
label,
62
lazyButton,
63
inputBoxContainer,
64
elementDisposable,
65
templateDisposable,
66
currentElement
67
};
68
watchExpressionsRenderer.renderElement(node, 0, data);
69
assert.strictEqual(value.textContent, '');
70
assert.strictEqual(label.element.textContent, displayType ? 'foo: ' : 'foo =');
71
72
node.element.value = 'xpto';
73
watchExpressionsRenderer.renderElement(node, 0, data);
74
assert.strictEqual(value.textContent, 'xpto');
75
assert.strictEqual(type.textContent, displayType ? 'string =' : '');
76
assert.strictEqual(label.element.textContent, displayType ? 'foo: ' : 'foo =');
77
}
78
79
suite('Debug - Watch Debug View', () => {
80
const disposables = ensureNoDisposablesAreLeakedInTestSuite();
81
let watchExpressionsRenderer: WatchExpressionsRenderer;
82
let instantiationService: TestInstantiationService;
83
let configurationService: TestConfigurationService;
84
let expressionRenderer: DebugExpressionRenderer;
85
86
setup(() => {
87
instantiationService = workbenchInstantiationService(undefined, disposables);
88
configurationService = instantiationService.createInstance(TestConfigurationService);
89
instantiationService.stub(IConfigurationService, configurationService);
90
expressionRenderer = instantiationService.createInstance(DebugExpressionRenderer);
91
const debugService = new MockDebugService();
92
instantiationService.stub(IHoverService, NullHoverService);
93
debugService.getViewModel = () => <IViewModel>{ focusedStackFrame: undefined, getSelectedExpression: () => undefined };
94
debugService.getViewModel().getSelectedExpression = () => undefined;
95
instantiationService.stub(IDebugService, debugService);
96
});
97
98
test('watch expressions with display type', () => {
99
configurationService.setUserConfiguration('debug', { showVariableTypes: true });
100
instantiationService.stub(IConfigurationService, configurationService);
101
watchExpressionsRenderer = instantiationService.createInstance(WatchExpressionsRenderer, expressionRenderer);
102
assertWatchVariable(disposables, watchExpressionsRenderer, true);
103
});
104
105
test('watch expressions', () => {
106
configurationService.setUserConfiguration('debug', { showVariableTypes: false });
107
instantiationService.stub(IConfigurationService, configurationService);
108
watchExpressionsRenderer = instantiationService.createInstance(WatchExpressionsRenderer, expressionRenderer);
109
assertWatchVariable(disposables, watchExpressionsRenderer, false);
110
});
111
});
112
113