Skip to content

Commit 5306599

Browse files
committed
adding test
1 parent f6c10ac commit 5306599

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/views/live-watch/live-watch.test.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/* eslint-disable @typescript-eslint/no-explicit-any */
1818
import * as vscode from 'vscode';
1919
import { debugSessionFactory, extensionContextFactory } from '../../__test__/vscode.factory';
20-
import { LiveWatchValue, LiveWatchTreeDataProvider } from './live-watch';
20+
import { LiveWatchValue, LiveWatchTreeDataProvider, LiveWatchNode } from './live-watch';
2121
import { GDBTargetDebugSession, GDBTargetDebugTracker } from '../../debug-session';
2222
import { gdbTargetConfiguration } from '../../debug-configuration/debug-configuration.factory';
2323
import { GDBTargetConfiguration } from '../../debug-configuration';
@@ -31,8 +31,8 @@ describe('LiveWatchTreeDataProvider', () => {
3131
let debugConfig: GDBTargetConfiguration;
3232

3333
// Helper: create a dummy node
34-
function makeNode(expression = 'x', value: LiveWatchValue = { result: '1', variablesReference: 0 }, id = 1) {
35-
return { id, expression, value, parent: undefined, children: [] };
34+
function makeNode(expression = 'x', value: LiveWatchValue = { result: '1', variablesReference: 0 }, id = 1, parent?: LiveWatchNode) {
35+
return { id, expression, value, parent: parent, children: [] };
3636
}
3737

3838
beforeEach(() => {
@@ -193,12 +193,30 @@ describe('LiveWatchTreeDataProvider', () => {
193193
expect(node.expression).toBe('node-1-renamed');
194194
});
195195

196-
it('copy copies node expression to clipboard', async () => {
196+
it('copies node expression to clipboard', async () => {
197197
const node = makeNode('node-to-copy', { result: '1', variablesReference: 0 }, 1);
198198
(liveWatchTreeDataProvider as any).roots = [node];
199199
await (liveWatchTreeDataProvider as any).handleCopyCommand(node);
200200
expect(vscode.env.clipboard.writeText).toHaveBeenCalledWith('node-to-copy');
201201
});
202+
203+
it('copies evaluateName of children to clipboard when present', async () => {
204+
const child = makeNode('childName', {
205+
result: '42',
206+
variablesReference: 0,
207+
evaluateName: 'parent.childName'
208+
}, 2);
209+
(liveWatchTreeDataProvider as any).roots = [child];
210+
await (liveWatchTreeDataProvider as any).handleCopyCommand(child);
211+
expect(vscode.env.clipboard.writeText).toHaveBeenCalledWith('parent.childName');
212+
});
213+
214+
it('copies expression to clipboard when evaluateName not present', async () => {
215+
const node = makeNode('myExpression', { result: '123', variablesReference: 0 }, 1);
216+
(liveWatchTreeDataProvider as any).roots = [node];
217+
await (liveWatchTreeDataProvider as any).handleCopyCommand(node);
218+
expect(vscode.env.clipboard.writeText).toHaveBeenCalledWith('myExpression');
219+
});
202220

203221
it('AddFromSelection adds selected text as new live watch expression to roots', async () => {
204222
jest.spyOn(liveWatchTreeDataProvider as any, 'evaluate').mockResolvedValue({ result: '5678', variablesReference: 0 });

src/views/live-watch/live-watch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import * as vscode from 'vscode';
1818
import { DebugProtocol } from '@vscode/debugprotocol';
1919
import { GDBTargetDebugSession, GDBTargetDebugTracker } from '../../debug-session';
2020

21-
interface LiveWatchNode {
21+
export interface LiveWatchNode {
2222
id: number;
2323
expression: string;
2424
parent: LiveWatchNode | undefined; // if undefined, it's a root node

0 commit comments

Comments
 (0)