Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/debug/test/browser/debugSource.test.ts
3296 views
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 assert from 'assert';
7
import { isWindows } from '../../../../../base/common/platform.js';
8
import { URI as uri } from '../../../../../base/common/uri.js';
9
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
10
import { NullLogService } from '../../../../../platform/log/common/log.js';
11
import { Source } from '../../common/debugSource.js';
12
import { mockUriIdentityService } from './mockDebugModel.js';
13
14
suite('Debug - Source', () => {
15
16
ensureNoDisposablesAreLeakedInTestSuite();
17
18
test('from raw source', () => {
19
const source = new Source({
20
name: 'zz',
21
path: '/xx/yy/zz',
22
sourceReference: 0,
23
presentationHint: 'emphasize'
24
}, 'aDebugSessionId', mockUriIdentityService, new NullLogService());
25
26
assert.strictEqual(source.presentationHint, 'emphasize');
27
assert.strictEqual(source.name, 'zz');
28
assert.strictEqual(source.inMemory, false);
29
assert.strictEqual(source.reference, 0);
30
assert.strictEqual(source.uri.toString(), uri.file('/xx/yy/zz').toString());
31
});
32
33
test('from raw internal source', () => {
34
const source = new Source({
35
name: 'internalModule.js',
36
sourceReference: 11,
37
presentationHint: 'deemphasize'
38
}, 'aDebugSessionId', mockUriIdentityService, new NullLogService());
39
40
assert.strictEqual(source.presentationHint, 'deemphasize');
41
assert.strictEqual(source.name, 'internalModule.js');
42
assert.strictEqual(source.inMemory, true);
43
assert.strictEqual(source.reference, 11);
44
assert.strictEqual(source.uri.toString(), 'debug:internalModule.js?session%3DaDebugSessionId%26ref%3D11');
45
});
46
47
test('get encoded debug data', () => {
48
const checkData = (uri: uri, expectedName: string, expectedPath: string, expectedSourceReference: number | undefined, expectedSessionId?: string) => {
49
const { name, path, sourceReference, sessionId } = Source.getEncodedDebugData(uri);
50
assert.strictEqual(name, expectedName);
51
assert.strictEqual(path, expectedPath);
52
assert.strictEqual(sourceReference, expectedSourceReference);
53
assert.strictEqual(sessionId, expectedSessionId);
54
};
55
56
checkData(uri.file('a/b/c/d'), 'd', isWindows ? '\\a\\b\\c\\d' : '/a/b/c/d', undefined, undefined);
57
checkData(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);
58
59
checkData(uri.from({ scheme: 'http', authority: 'www.example.com', path: '/my/path' }), 'path', 'http://www.example.com/my/path', undefined, undefined);
60
checkData(uri.from({ scheme: 'debug', authority: 'www.example.com', path: '/my/path', query: 'ref=100' }), 'path', '/my/path', 100, undefined);
61
checkData(uri.from({ scheme: 'debug', path: 'a/b/c/d.js', query: 'session=100' }), 'd.js', 'a/b/c/d.js', undefined, '100');
62
checkData(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');
63
});
64
});
65
66