Path: blob/main/extensions/copilot/src/platform/parser/test/node/getTestableNode.js.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 { _dispose } from '../../node/parserWithCaching';8import { WASMLanguage } from '../../node/treeSitterLanguages';9import { srcWithAnnotatedTestableNode } from './getTestableNode.util';1011suite('getTestableNode - js', () => {12afterAll(() => _dispose());1314function run(annotatedSrc: string) {15return srcWithAnnotatedTestableNode(16WASMLanguage.JavaScript,17annotatedSrc,18);19}2021test('function declaration', async () => {22const result = await run(23outdent`24function <<add>>(a: number, b: number): number {25return a + b;26}27`,28);29expect(result).toMatchInlineSnapshot(`30"<NODE(function_declaration)>function <IDENT>add</IDENT>(a: number, b: number): number {31return a + b;32}</NODE(function_declaration)>"33`);34});3536test('method', async () => {37const result = await run(38outdent`39class Foo {40<<method>>(a: number, b: number): number {41return a + b;42}43}44`,45);46expect(result).toMatchInlineSnapshot(`47"class Foo {48<NODE(method_definition)><IDENT>method</IDENT>(a: number, b: number): number {49return a + b;50}</NODE(method_definition)>51}"52`);53});5455test('public method', async () => {56const result = await run(57outdent`58class Foo {59<<method>>(a: number, b: number): number {60return a + b;61}62}63`,64);65expect(result).toMatchInlineSnapshot(`66"class Foo {67<NODE(method_definition)><IDENT>method</IDENT>(a: number, b: number): number {68return a + b;69}</NODE(method_definition)>70}"71`);72});7374test('does not capture private method', async () => {75const result = await run(76outdent`77class Foo {78private <<#method>>(a: number, b: number): number {79return a + b;80}81}82`,83);84expect(result).toMatchInlineSnapshot(`"testable node NOT found"`);85});8687test('static method', async () => {88const result = await run(89outdent`90class Foo {91static <<method>>(a: number, b: number): number {92return a + b;93}94}95`,96);97expect(result).toMatchInlineSnapshot(`98"class Foo {99<NODE(method_definition)>static <IDENT>method</IDENT>(a: number, b: number): number {100return a + b;101}</NODE(method_definition)>102}"103`);104});105106test('private static method', async () => {107const result = await run(108outdent`109class Foo {110static <<#method>>(a: number, b: number): number {111return a + b;112}113}114`,115);116expect(result).toMatchInlineSnapshot(`"testable node NOT found"`);117});118119test('public static method', async () => {120const result = await run(121outdent`122class Foo {123public static <<method>>(a: number, b: number): number {124return a + b;125}126}127`,128);129expect(result).toMatchInlineSnapshot(`130"class Foo {131public <NODE(method_definition)>static <IDENT>method</IDENT>(a: number, b: number): number {132return a + b;133}</NODE(method_definition)>134}"135`);136});137});138139140