test: generators

This commit is contained in:
tomasz-io 2024-11-15 13:12:21 -08:00
parent 3595293647
commit 3bece78be4
3 changed files with 198 additions and 0 deletions

View file

@ -0,0 +1,33 @@
// @ts-nocheck
function* getAddress(person: Person): Address {
// TODO
}
function* getFirstAddress(people: Person[]): Address {
// TODO
}
function* logPerson(person: Person) {
// TODO
}
function* getHardcodedAddress(): Address {
// TODO
}
function* getAddresses(people: Person[]): Address[] {
// TODO
}
function* logPersonWithAddress(person: Person<Address>): Person<Address> {
// TODO
}
function* logPersonOrAddress(person: Person | Address): Person | Address {
// TODO
}
function* logPersonAndAddress(person: Person, address: Address) {
// TODO
}

View file

@ -85,6 +85,93 @@ const FUNCTIONS = [
},
];
const GENERATORS = [
{
nodeType: "function_declaration with a param and a return type",
fileName: "generators.ts",
language: "TypeScript",
cursorPosition: { line: 3, character: 9 },
definitionPositions: [
{ row: 2, column: 35 }, // Person
{ row: 2, column: 45 }, // Address
],
},
{
nodeType: "function_declaration with array param",
fileName: "generators.ts",
language: "TypeScript",
cursorPosition: { line: 7, character: 9 },
definitionPositions: [
{ row: 6, column: 40 }, // Person
{ row: 6, column: 52 }, // Address
],
},
{
nodeType: "function_declaration without return type",
fileName: "generators.ts",
language: "TypeScript",
cursorPosition: { line: 11, character: 9 },
definitionPositions: [
{ row: 10, column: 34 }, // Person
],
},
{
nodeType: "function_declaration without params",
fileName: "generators.ts",
language: "TypeScript",
cursorPosition: { line: 15, character: 9 },
definitionPositions: [
{ row: 14, column: 40 }, // Person
],
},
{
nodeType: "function_declaration with array params and array return type",
fileName: "generators.ts",
language: "TypeScript",
cursorPosition: { line: 19, character: 9 },
definitionPositions: [
{ row: 18, column: 37 }, // Person
{ row: 18, column: 49 }, // Address
],
},
{
nodeType:
"function_declaration with generic params and generic return type",
fileName: "generators.ts",
language: "TypeScript",
cursorPosition: { line: 23, character: 9 },
definitionPositions: [
{ row: 22, column: 45 }, // Person
{ row: 22, column: 53 }, // Address
{ row: 22, column: 63 }, // Person
{ row: 22, column: 71 }, // Address
],
},
{
nodeType:
"function_declaration with union type params and union return type",
fileName: "generators.ts",
language: "TypeScript",
cursorPosition: { line: 27, character: 9 },
definitionPositions: [
{ row: 26, column: 43 }, // Person
{ row: 26, column: 53 }, // Address
{ row: 26, column: 62 }, // Person
{ row: 26, column: 72 }, // Address
],
},
{
nodeType: "function_declaration with two arguments",
fileName: "generators.ts",
language: "TypeScript",
cursorPosition: { line: 31, character: 9 },
definitionPositions: [
{ row: 30, column: 44 }, // Person
{ row: 30, column: 62 }, // Address
],
},
];
const ARROW_FUNCTIONS = [
{
nodeType: "arrow_function with a param and a return type",
@ -303,6 +390,7 @@ const CLASS_DEFINITIONS = [
export const TYPESCRIPT_TEST_CASES = [
...FUNCTIONS,
...GENERATORS,
...ARROW_FUNCTIONS,
...CLASS_METHODS,
...CLASS_DEFINITIONS,

View file

@ -0,0 +1,77 @@
; Pattern for return type with direct type_identifier
(
(generator_function_declaration
(type_annotation
(type_identifier) @return_type
)
)
)
; Pattern for return type with one level of nesting
(
(generator_function_declaration
(type_annotation
(_
(type_identifier) @return_type
)
)
)
)
; Pattern for return type with two levels of nesting
(
(generator_function_declaration
(type_annotation
(_
(_
(type_identifier) @return_type
)
)
)
)
)
; Pattern for parameters with direct type_identifier
(
(generator_function_declaration
(formal_parameters
(_
(type_annotation
(type_identifier) @param_type
)
)
)
)
)
; Pattern for parameters with one level of nesting
(
(generator_function_declaration
(formal_parameters
(_
(type_annotation
(_
(type_identifier) @param_type
)
)
)
)
)
)
; Pattern for parameters with two levels of nesting
(
(generator_function_declaration
(formal_parameters
(_
(type_annotation
(_
(_
(type_identifier) @param_type
)
)
)
)
)
)
)