|
| 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 { replaceWhitespace, renderExpressionValue, renderVariable } from 'vs/workbench/parts/debug/browser/baseDebugView'; |
| 8 | +import * as dom from 'vs/base/browser/dom'; |
| 9 | +import { Expression, Variable, Process, Scope, StackFrame, Thread } from 'vs/workbench/parts/debug/common/debugModel'; |
| 10 | +import { MockSession } from 'vs/workbench/parts/debug/test/common/mockDebug'; |
| 11 | +const $ = dom.$; |
| 12 | + |
| 13 | +suite('Debug - Base Debug View', () => { |
| 14 | + |
| 15 | + test('replace whitespace', () => { |
| 16 | + assert.equal(replaceWhitespace('hey there'), 'hey there'); |
| 17 | + assert.equal(replaceWhitespace('hey there\n'), 'hey there\\n'); |
| 18 | + assert.equal(replaceWhitespace('hey \r there\n\t'), 'hey \\r there\\n\\t'); |
| 19 | + assert.equal(replaceWhitespace('hey \r\t\n\t\t\n there'), 'hey \\r\\t\\n\\t\\t\\n there'); |
| 20 | + }); |
| 21 | + |
| 22 | + test('render expression value', () => { |
| 23 | + let container = $('.container'); |
| 24 | + renderExpressionValue('render \n me', container, { showHover: true, preserveWhitespace: true }); |
| 25 | + assert.equal(container.className, 'value'); |
| 26 | + assert.equal(container.title, 'render \n me'); |
| 27 | + assert.equal(container.textContent, 'render \n me'); |
| 28 | + |
| 29 | + const expression = new Expression('console'); |
| 30 | + expression.value = 'Object'; |
| 31 | + container = $('.container'); |
| 32 | + renderExpressionValue(expression, container, { colorize: true }); |
| 33 | + assert.equal(container.className, 'value unavailable error'); |
| 34 | + |
| 35 | + expression.available = true; |
| 36 | + expression.value = '"string value"'; |
| 37 | + container = $('.container'); |
| 38 | + renderExpressionValue(expression, container, { colorize: true }); |
| 39 | + assert.equal(container.className, 'value string'); |
| 40 | + assert.equal(container.textContent, '"string value"'); |
| 41 | + |
| 42 | + expression.type = 'boolean'; |
| 43 | + container = $('.container'); |
| 44 | + renderExpressionValue(expression, container, { colorize: true }); |
| 45 | + assert.equal(container.className, 'value boolean'); |
| 46 | + assert.equal(container.textContent, expression.value); |
| 47 | + |
| 48 | + expression.value = 'this is a long string'; |
| 49 | + container = $('.container'); |
| 50 | + renderExpressionValue(expression, container, { colorize: true, maxValueLength: 4 }); |
| 51 | + assert.equal(container.textContent, 'this...'); |
| 52 | + }); |
| 53 | + |
| 54 | + test('render variable', () => { |
| 55 | + const rawSession = new MockSession(); |
| 56 | + const process = new Process({ name: 'mockProcess', type: 'node', request: 'launch' }, rawSession); |
| 57 | + const thread = new Thread(process, 'mockthread', 1); |
| 58 | + const stackFrame = new StackFrame(thread, 1, null, 'app.js', 'normal', { startLineNumber: 1, startColumn: 1, endLineNumber: undefined, endColumn: undefined }, 0); |
| 59 | + const scope = new Scope(stackFrame, 1, 'local', 1, false, 10, 10); |
| 60 | + |
| 61 | + let variable = new Variable(process, scope, 2, 'foo', 'bar.foo', undefined, 0, 0, {}, 'string'); |
| 62 | + let expression = $('.'); |
| 63 | + let name = $('.'); |
| 64 | + let value = $('.'); |
| 65 | + renderVariable(variable, { expression, name, value }, false); |
| 66 | + |
| 67 | + assert.equal(name.textContent, 'foo'); |
| 68 | + assert.equal(value.textContent, ''); |
| 69 | + assert.equal(value.title, ''); |
| 70 | + |
| 71 | + variable.value = 'hey'; |
| 72 | + expression = $('.'); |
| 73 | + name = $('.'); |
| 74 | + value = $('.'); |
| 75 | + renderVariable(variable, { expression, name, value }, false); |
| 76 | + assert.equal(value.textContent, 'hey'); |
| 77 | + assert.equal(name.textContent, 'foo:'); |
| 78 | + assert.equal(name.title, 'string'); |
| 79 | + |
| 80 | + variable = new Variable(process, scope, 2, 'console', 'console', '5', 0, 0, { kind: 'virtual' }); |
| 81 | + expression = $('.'); |
| 82 | + name = $('.'); |
| 83 | + value = $('.'); |
| 84 | + renderVariable(variable, { expression, name, value }, false); |
| 85 | + assert.equal(name.className, 'virtual'); |
| 86 | + assert.equal(name.textContent, 'console:'); |
| 87 | + assert.equal(name.title, 'console'); |
| 88 | + assert.equal(value.className, 'value number'); |
| 89 | + }); |
| 90 | +}); |
0 commit comments