Path: blob/main/src/vs/workbench/contrib/debug/test/browser/debugUtils.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 { IConfig } from '../../common/debug.js';8import { formatPII, getExactExpressionStartAndEnd, getVisibleAndSorted } from '../../common/debugUtils.js';910suite('Debug - Utils', () => {11ensureNoDisposablesAreLeakedInTestSuite();1213test('formatPII', () => {14assert.strictEqual(formatPII('Foo Bar', false, {}), 'Foo Bar');15assert.strictEqual(formatPII('Foo {key} Bar', false, {}), 'Foo {key} Bar');16assert.strictEqual(formatPII('Foo {key} Bar', false, { 'key': 'yes' }), 'Foo yes Bar');17assert.strictEqual(formatPII('Foo {_0} Bar {_0}', true, { '_0': 'yes' }), 'Foo yes Bar yes');18assert.strictEqual(formatPII('Foo {0} Bar {1}{2}', false, { '0': 'yes' }), 'Foo yes Bar {1}{2}');19assert.strictEqual(formatPII('Foo {0} Bar {1}{2}', false, { '0': 'yes', '1': 'undefined' }), 'Foo yes Bar undefined{2}');20assert.strictEqual(formatPII('Foo {_key0} Bar {key1}{key2}', true, { '_key0': 'yes', 'key1': '5', 'key2': 'false' }), 'Foo yes Bar {key1}{key2}');21assert.strictEqual(formatPII('Foo {_key0} Bar {key1}{key2}', false, { '_key0': 'yes', 'key1': '5', 'key2': 'false' }), 'Foo yes Bar 5false');22assert.strictEqual(formatPII('Unable to display threads:"{e}"', false, { 'e': 'detached from process' }), 'Unable to display threads:"detached from process"');23});2425test('getExactExpressionStartAndEnd', () => {26assert.deepStrictEqual(getExactExpressionStartAndEnd('foo', 1, 2), { start: 1, end: 3 });27assert.deepStrictEqual(getExactExpressionStartAndEnd('!foo', 2, 3), { start: 2, end: 4 });28assert.deepStrictEqual(getExactExpressionStartAndEnd('foo', 1, 3), { start: 1, end: 3 });29assert.deepStrictEqual(getExactExpressionStartAndEnd('foo', 1, 4), { start: 1, end: 3 });30assert.deepStrictEqual(getExactExpressionStartAndEnd('this.name = "John"', 1, 10), { start: 1, end: 9 });31assert.deepStrictEqual(getExactExpressionStartAndEnd('this.name = "John"', 6, 10), { start: 1, end: 9 });32// Hovers over "address" should pick up this->address33assert.deepStrictEqual(getExactExpressionStartAndEnd('this->address = "Main street"', 6, 10), { start: 1, end: 13 });34// Hovers over "name" should pick up a.b.c.d.name35assert.deepStrictEqual(getExactExpressionStartAndEnd('var t = a.b.c.d.name', 16, 20), { start: 9, end: 20 });36assert.deepStrictEqual(getExactExpressionStartAndEnd('MyClass::StaticProp', 10, 20), { start: 1, end: 19 });37assert.deepStrictEqual(getExactExpressionStartAndEnd('largeNumber = myVar?.prop', 21, 25), { start: 15, end: 25 });3839// For example in expression 'a.b.c.d', hover was under 'b', 'a.b' should be the exact range40assert.deepStrictEqual(getExactExpressionStartAndEnd('var t = a.b.c.d.name', 11, 12), { start: 9, end: 11 });4142assert.deepStrictEqual(getExactExpressionStartAndEnd('var t = a.b;c.d.name', 16, 20), { start: 13, end: 20 });43assert.deepStrictEqual(getExactExpressionStartAndEnd('var t = a.b.c-d.name', 16, 20), { start: 15, end: 20 });4445assert.deepStrictEqual(getExactExpressionStartAndEnd('var aøñéå文 = a.b.c-d.name', 5, 5), { start: 5, end: 10 });46assert.deepStrictEqual(getExactExpressionStartAndEnd('aøñéå文.aøñéå文.aøñéå文', 9, 9), { start: 1, end: 13 });4748// Spread syntax should extract just the identifier49assert.deepStrictEqual(getExactExpressionStartAndEnd('[...bar]', 5, 7), { start: 5, end: 7 });50assert.deepStrictEqual(getExactExpressionStartAndEnd('...variable', 5, 5), { start: 4, end: 11 });51});5253test('config presentation', () => {54const configs: IConfig[] = [];55configs.push({56type: 'node',57request: 'launch',58name: 'p'59});60configs.push({61type: 'node',62request: 'launch',63name: 'a'64});65configs.push({66type: 'node',67request: 'launch',68name: 'b',69presentation: {70hidden: false71}72});73configs.push({74type: 'node',75request: 'launch',76name: 'c',77presentation: {78hidden: true79}80});81configs.push({82type: 'node',83request: 'launch',84name: 'd',85presentation: {86group: '2_group',87order: 588}89});90configs.push({91type: 'node',92request: 'launch',93name: 'e',94presentation: {95group: '2_group',96order: 5297}98});99configs.push({100type: 'node',101request: 'launch',102name: 'f',103presentation: {104group: '1_group',105order: 500106}107});108configs.push({109type: 'node',110request: 'launch',111name: 'g',112presentation: {113group: '5_group',114order: 500115}116});117configs.push({118type: 'node',119request: 'launch',120name: 'h',121presentation: {122order: 700123}124});125configs.push({126type: 'node',127request: 'launch',128name: 'i',129presentation: {130order: 1000131}132});133134const sorted = getVisibleAndSorted(configs);135assert.strictEqual(sorted.length, 9);136assert.strictEqual(sorted[0].name, 'f');137assert.strictEqual(sorted[1].name, 'd');138assert.strictEqual(sorted[2].name, 'e');139assert.strictEqual(sorted[3].name, 'g');140assert.strictEqual(sorted[4].name, 'h');141assert.strictEqual(sorted[5].name, 'i');142assert.strictEqual(sorted[6].name, 'b');143assert.strictEqual(sorted[7].name, 'p');144assert.strictEqual(sorted[8].name, 'a');145146});147});148149150