Path: blob/main/src/vs/workbench/contrib/debug/test/browser/debugSource.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 { isWindows } from '../../../../../base/common/platform.js';7import { URI as uri } from '../../../../../base/common/uri.js';8import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';9import { NullLogService } from '../../../../../platform/log/common/log.js';10import { Source } from '../../common/debugSource.js';11import { mockUriIdentityService } from './mockDebugModel.js';1213suite('Debug - Source', () => {1415ensureNoDisposablesAreLeakedInTestSuite();1617test('from raw source', () => {18const source = new Source({19name: 'zz',20path: '/xx/yy/zz',21sourceReference: 0,22presentationHint: 'emphasize'23}, 'aDebugSessionId', mockUriIdentityService, new NullLogService());2425assert.strictEqual(source.presentationHint, 'emphasize');26assert.strictEqual(source.name, 'zz');27assert.strictEqual(source.inMemory, false);28assert.strictEqual(source.reference, 0);29assert.strictEqual(source.uri.toString(), uri.file('/xx/yy/zz').toString());30});3132test('from raw internal source', () => {33const source = new Source({34name: 'internalModule.js',35sourceReference: 11,36presentationHint: 'deemphasize'37}, 'aDebugSessionId', mockUriIdentityService, new NullLogService());3839assert.strictEqual(source.presentationHint, 'deemphasize');40assert.strictEqual(source.name, 'internalModule.js');41assert.strictEqual(source.inMemory, true);42assert.strictEqual(source.reference, 11);43assert.strictEqual(source.uri.toString(), 'debug:internalModule.js?session%3DaDebugSessionId%26ref%3D11');44});4546test('get encoded debug data', () => {47const checkData = (uri: uri, expectedName: string, expectedPath: string, expectedSourceReference: number | undefined, expectedSessionId?: string) => {48const { name, path, sourceReference, sessionId } = Source.getEncodedDebugData(uri);49assert.strictEqual(name, expectedName);50assert.strictEqual(path, expectedPath);51assert.strictEqual(sourceReference, expectedSourceReference);52assert.strictEqual(sessionId, expectedSessionId);53};5455checkData(uri.file('a/b/c/d'), 'd', isWindows ? '\\a\\b\\c\\d' : '/a/b/c/d', undefined, undefined);56checkData(uri.from({ scheme: 'file', path: '/my/path/test.js', query: 'ref=1&session=2' }), 'test.js', isWindows ? '\\my\\path\\test.js' : '/my/path/test.js', undefined, undefined);5758checkData(uri.from({ scheme: 'http', authority: 'www.example.com', path: '/my/path' }), 'path', 'http://www.example.com/my/path', undefined, undefined);59checkData(uri.from({ scheme: 'debug', authority: 'www.example.com', path: '/my/path', query: 'ref=100' }), 'path', '/my/path', 100, undefined);60checkData(uri.from({ scheme: 'debug', path: 'a/b/c/d.js', query: 'session=100' }), 'd.js', 'a/b/c/d.js', undefined, '100');61checkData(uri.from({ scheme: 'debug', path: 'a/b/c/d/foo.txt', query: 'session=100&ref=10' }), 'foo.txt', 'a/b/c/d/foo.txt', 10, '100');62});63});646566