Path: blob/main/extensions/copilot/src/platform/parser/test/node/getStructure.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, describe, expect, test } from 'vitest';7import { _dispose } from '../../node/parserImpl';8import { WASMLanguage } from '../../node/treeSitterLanguages';9import { fromFixture, snapshotPathInFixture, srcWithAnnotatedStructure } from './getStructure.util';1011describe('getStructure - cpp', () => {12afterAll(() => _dispose());1314function cppStruct(source: string) {15return srcWithAnnotatedStructure(WASMLanguage.Cpp, source);16}1718test('source with different syntax constructs', async () => {1920const filename = 'test.cpp';2122const source = await fromFixture(filename);2324await expect(await cppStruct(source)).toMatchFileSnapshot(snapshotPathInFixture(filename));25});2627test('do not throw invalid range error', async () => {2829const filename = 'problem1.cpp';3031const source = await fromFixture(filename);3233await expect(await cppStruct(source)).toMatchFileSnapshot(snapshotPathInFixture(filename));34});3536test('do not throw invalid range error - 2', async () => {37const source = outdent`38void main() {39// Trigger servo movement based on the difference40if (remappedDifference > 0) {41Serial.println("Turning clockwise...");42controlServo(SERVO_CW); // Spin the servo clockwise43} else if (remappedDifference < 0) {44Serial.println("Turning counterclockwise...");45controlServo(SERVO_CCW); // Spin the servo counterclockwise46} /* else {47Serial.println("Stopping servo...");48controlServo(SERVO_STOP); // Stop the servo if the difference is zero49} */50}51`;5253expect(await cppStruct(source)).toMatchInlineSnapshot(`54"<FUNCTION_DEFINITION>void main() {55<COMMENT> // Trigger servo movement based on the difference56</COMMENT><IF_STATEMENT> if (remappedDifference > 0) {57<EXPRESSION_STATEMENT> Serial.println("Turning clockwise...");58</EXPRESSION_STATEMENT><EXPRESSION_STATEMENT-1> controlServo(SERVO_CW); // Spin the servo clockwise59</EXPRESSION_STATEMENT-1> } else<IF_STATEMENT-1> if (remappedDifference < 0) {60<EXPRESSION_STATEMENT-2> Serial.println("Turning counterclockwise...");61</EXPRESSION_STATEMENT-2><EXPRESSION_STATEMENT-3> controlServo(SERVO_CCW); // Spin the servo counterclockwise62</EXPRESSION_STATEMENT-3> }</IF_STATEMENT-1> /* else {63Serial.println("Stopping servo...");64controlServo(SERVO_STOP); // Stop the servo if the difference is zero65} */66</IF_STATEMENT>}</FUNCTION_DEFINITION>"67`);68});6970test('trailing semicolon after class declaration', async () => {71const source = `class A {};`;7273expect(await cppStruct(source)).toMatchInlineSnapshot(`"<CLASS_SPECIFIER>class A {};</CLASS_SPECIFIER>"`);74});75});767778