提交 0a280639 编写于 作者: I isidor

debug: base debug view tests

上级 1670e102
......@@ -50,7 +50,7 @@ export function renderViewTree(container: HTMLElement): HTMLElement {
return treeContainer;
}
function replaceWhitespace(value: string): string {
export function replaceWhitespace(value: string): string {
const map: { [x: string]: string } = { '\n': '\\n', '\r': '\\r', '\t': '\\t' };
return value.replace(/[\n\r\t]/g, char => map[char]);
}
......@@ -98,7 +98,7 @@ export function renderExpressionValue(expressionOrValue: IExpression | string, c
}
}
export function renderVariable(tree: ITree, variable: Variable, data: IVariableTemplateData, showChanged: boolean): void {
export function renderVariable(variable: Variable, data: IVariableTemplateData, showChanged: boolean): void {
if (variable.available) {
data.name.textContent = replaceWhitespace(variable.name);
data.name.title = variable.type ? variable.type : variable.name;
......
......@@ -223,7 +223,7 @@ export class ReplExpressionsRenderer implements IRenderer {
public renderElement(tree: ITree, element: any, templateId: string, templateData: any): void {
if (templateId === ReplExpressionsRenderer.VARIABLE_TEMPLATE_ID) {
renderVariable(tree, element, templateData, false);
renderVariable(element, templateData, false);
} else if (templateId === ReplExpressionsRenderer.EXPRESSION_TEMPLATE_ID) {
this.renderExpression(tree, element, templateData);
} else if (templateId === ReplExpressionsRenderer.SIMPLE_REPL_ELEMENT_TEMPLATE_ID) {
......
......@@ -284,7 +284,7 @@ export class VariablesRenderer implements IRenderer {
}
});
} else {
renderVariable(tree, variable, templateData, true);
renderVariable(variable, templateData, true);
}
}
}
......
......@@ -284,7 +284,7 @@ class WatchExpressionsRenderer implements IRenderer {
if (templateId === WatchExpressionsRenderer.WATCH_EXPRESSION_TEMPLATE_ID) {
this.renderWatchExpression(tree, element, templateData);
} else {
renderVariable(tree, element, templateData, true);
renderVariable(element, templateData, true);
}
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { replaceWhitespace, renderExpressionValue, renderVariable } from 'vs/workbench/parts/debug/browser/baseDebugView';
import * as dom from 'vs/base/browser/dom';
import { Expression, Variable, Process, Scope, StackFrame, Thread } from 'vs/workbench/parts/debug/common/debugModel';
import { MockSession } from 'vs/workbench/parts/debug/test/common/mockDebug';
const $ = dom.$;
suite('Debug - Base Debug View', () => {
test('replace whitespace', () => {
assert.equal(replaceWhitespace('hey there'), 'hey there');
assert.equal(replaceWhitespace('hey there\n'), 'hey there\\n');
assert.equal(replaceWhitespace('hey \r there\n\t'), 'hey \\r there\\n\\t');
assert.equal(replaceWhitespace('hey \r\t\n\t\t\n there'), 'hey \\r\\t\\n\\t\\t\\n there');
});
test('render expression value', () => {
let container = $('.container');
renderExpressionValue('render \n me', container, { showHover: true, preserveWhitespace: true });
assert.equal(container.className, 'value');
assert.equal(container.title, 'render \n me');
assert.equal(container.textContent, 'render \n me');
const expression = new Expression('console');
expression.value = 'Object';
container = $('.container');
renderExpressionValue(expression, container, { colorize: true });
assert.equal(container.className, 'value unavailable error');
expression.available = true;
expression.value = '"string value"';
container = $('.container');
renderExpressionValue(expression, container, { colorize: true });
assert.equal(container.className, 'value string');
assert.equal(container.textContent, '"string value"');
expression.type = 'boolean';
container = $('.container');
renderExpressionValue(expression, container, { colorize: true });
assert.equal(container.className, 'value boolean');
assert.equal(container.textContent, expression.value);
expression.value = 'this is a long string';
container = $('.container');
renderExpressionValue(expression, container, { colorize: true, maxValueLength: 4 });
assert.equal(container.textContent, 'this...');
});
test('render variable', () => {
const rawSession = new MockSession();
const process = new Process({ name: 'mockProcess', type: 'node', request: 'launch' }, rawSession);
const thread = new Thread(process, 'mockthread', 1);
const stackFrame = new StackFrame(thread, 1, null, 'app.js', 'normal', { startLineNumber: 1, startColumn: 1, endLineNumber: undefined, endColumn: undefined }, 0);
const scope = new Scope(stackFrame, 1, 'local', 1, false, 10, 10);
let variable = new Variable(process, scope, 2, 'foo', 'bar.foo', undefined, 0, 0, {}, 'string');
let expression = $('.');
let name = $('.');
let value = $('.');
renderVariable(variable, { expression, name, value }, false);
assert.equal(name.textContent, 'foo');
assert.equal(value.textContent, '');
assert.equal(value.title, '');
variable.value = 'hey';
expression = $('.');
name = $('.');
value = $('.');
renderVariable(variable, { expression, name, value }, false);
assert.equal(value.textContent, 'hey');
assert.equal(name.textContent, 'foo:');
assert.equal(name.title, 'string');
variable = new Variable(process, scope, 2, 'console', 'console', '5', 0, 0, { kind: 'virtual' });
expression = $('.');
name = $('.');
value = $('.');
renderVariable(variable, { expression, name, value }, false);
assert.equal(name.className, 'virtual');
assert.equal(name.textContent, 'console:');
assert.equal(name.title, 'console');
assert.equal(value.className, 'value number');
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册