Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/remoteSearch/test/node/utils.spec.ts
13405 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 { suite, test } from 'vitest';
8
import { formatScopingQuery } from '../../common/utils';
9
10
suite('formatScopingQuery', () => {
11
test('should format a scoping query with only a repo', () => {
12
const query = { repo: 'owner/repo' };
13
const result = formatScopingQuery(query);
14
assert.strictEqual(result, '(repo:owner/repo)');
15
});
16
17
test('should format a scoping query with multiple repos', () => {
18
const query = { repo: ['owner/repo', 'owner/repo2'] };
19
const result = formatScopingQuery(query);
20
assert.strictEqual(result, '(repo:owner/repo OR repo:owner/repo2)');
21
});
22
23
test('should format a scoping query with a repo and a language', () => {
24
const query = { repo: 'owner/repo', lang: ['typescript', 'javascript'] };
25
const result = formatScopingQuery(query);
26
assert.strictEqual(result, '(repo:owner/repo) (lang:typescript OR lang:javascript)');
27
});
28
29
test('should format a scoping query with a repo and a notLang', () => {
30
const query = { repo: 'owner/repo', notLang: ['python', 'ruby'] };
31
const result = formatScopingQuery(query);
32
assert.strictEqual(result, '(repo:owner/repo) NOT (lang:python OR lang:ruby)');
33
});
34
35
test('should format a scoping query with a repo and a path', () => {
36
const query = { repo: 'owner/repo', path: ['src', 'test'] };
37
const result = formatScopingQuery(query);
38
assert.strictEqual(result, '(repo:owner/repo) (path:src OR path:test)');
39
});
40
41
test('should format a scoping query with a repo and a notPath', () => {
42
const query = { repo: 'owner/repo', notPath: ['node_modules', 'dist'] };
43
const result = formatScopingQuery(query);
44
assert.strictEqual(result, '(repo:owner/repo) NOT (path:node_modules OR path:dist)');
45
});
46
47
test('should format a scoping query with all options', () => {
48
const query = {
49
repo: 'owner/repo',
50
lang: ['typescript', 'javascript'],
51
notLang: ['python', 'ruby'],
52
path: ['src', 'test'],
53
notPath: ['node_modules', 'dist']
54
};
55
const result = formatScopingQuery(query);
56
assert.strictEqual(
57
result,
58
'(repo:owner/repo) (lang:typescript OR lang:javascript) NOT (lang:python OR lang:ruby) (path:src OR path:test) NOT (path:node_modules OR path:dist)'
59
);
60
});
61
});
62
63