Path: blob/main/extensions/copilot/src/platform/parser/test/node/getNodeToDocument.cpp.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 { outdent } from 'outdent';6import { afterAll, expect, suite, test } from 'vitest';7import {8_dispose9} from '../../node/parserImpl';10import { WASMLanguage } from '../../node/treeSitterLanguages';11import { srcWithAnnotatedNodeToDoc } from './getNodeToDocument.util';121314suite('getNodeToDocument - cpp', () => {1516afterAll(() => _dispose());1718async function run(annotatedSrc: string, includeSelection = false) {19return srcWithAnnotatedNodeToDoc(20WASMLanguage.Cpp,21annotatedSrc,22includeSelection,23);24}2526test('basic function', async () => {27const result = await run(28outdent`29void foo() {30<<>>31}32`,33true34);35expect(result).toMatchInlineSnapshot(`36"<FUNCTION_DEFINITION>void <IDENT>foo</IDENT>() {37<SELECTION></SELECTION>38}</FUNCTION_DEFINITION>"39`);40});4142test('function with qualified identifier and qualified return type - selection in body', async () => {43const result = await run(44outdent`45Foo::Bar baz::foo() {46<<>>47}48`,49true50);51expect(result).toMatchInlineSnapshot(`52"<FUNCTION_DEFINITION>Foo::Bar <IDENT>baz::foo</IDENT>() {53<SELECTION></SELECTION>54}</FUNCTION_DEFINITION>"55`);56});5758test('function with qualified identifier and qualified return type - selection on return type', async () => {59const result = await run(60outdent`61<<Foo::Bar>> baz::foo() {6263}64`65);66expect(result).toMatchInlineSnapshot(`67"<FUNCTION_DEFINITION>Foo::Bar <IDENT>baz::foo</IDENT>() {6869}</FUNCTION_DEFINITION>"70`);71});7273test('function with qualified identifier and qualified return type - selection on function qualified identifier', async () => {74const result = await run(75outdent`76Foo::Bar baz<<>>::foo() {7778}79`80);81expect(result).toMatchInlineSnapshot(`82"<FUNCTION_DEFINITION>Foo::Bar <IDENT>baz::foo</IDENT>() {8384}</FUNCTION_DEFINITION>"85`);86});87});888990