Path: blob/main/extensions/copilot/src/platform/remoteSearch/test/node/utils.spec.ts
13405 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 { suite, test } from 'vitest';7import { formatScopingQuery } from '../../common/utils';89suite('formatScopingQuery', () => {10test('should format a scoping query with only a repo', () => {11const query = { repo: 'owner/repo' };12const result = formatScopingQuery(query);13assert.strictEqual(result, '(repo:owner/repo)');14});1516test('should format a scoping query with multiple repos', () => {17const query = { repo: ['owner/repo', 'owner/repo2'] };18const result = formatScopingQuery(query);19assert.strictEqual(result, '(repo:owner/repo OR repo:owner/repo2)');20});2122test('should format a scoping query with a repo and a language', () => {23const query = { repo: 'owner/repo', lang: ['typescript', 'javascript'] };24const result = formatScopingQuery(query);25assert.strictEqual(result, '(repo:owner/repo) (lang:typescript OR lang:javascript)');26});2728test('should format a scoping query with a repo and a notLang', () => {29const query = { repo: 'owner/repo', notLang: ['python', 'ruby'] };30const result = formatScopingQuery(query);31assert.strictEqual(result, '(repo:owner/repo) NOT (lang:python OR lang:ruby)');32});3334test('should format a scoping query with a repo and a path', () => {35const query = { repo: 'owner/repo', path: ['src', 'test'] };36const result = formatScopingQuery(query);37assert.strictEqual(result, '(repo:owner/repo) (path:src OR path:test)');38});3940test('should format a scoping query with a repo and a notPath', () => {41const query = { repo: 'owner/repo', notPath: ['node_modules', 'dist'] };42const result = formatScopingQuery(query);43assert.strictEqual(result, '(repo:owner/repo) NOT (path:node_modules OR path:dist)');44});4546test('should format a scoping query with all options', () => {47const query = {48repo: 'owner/repo',49lang: ['typescript', 'javascript'],50notLang: ['python', 'ruby'],51path: ['src', 'test'],52notPath: ['node_modules', 'dist']53};54const result = formatScopingQuery(query);55assert.strictEqual(56result,57'(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)'58);59});60});616263