Skip to content

Commit

Permalink
feat: add tests for return type partial type searching
Browse files Browse the repository at this point in the history
  • Loading branch information
Zlatin Stanimirov authored and Zlatin Stanimirov committed Nov 5, 2023
1 parent 21caa41 commit 9792707
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function removeDynamicImports (inputStr: string): string {
return inputStr.replace(importRegex, '')
}

// TODO move to their own file ?
// showcase how we might add partial type checking
function doTypesMatch (searchParameterType: string, functionParameter: ParameterDeclaration): boolean {
const mandatoryObjectKeys = parseTypeQuery(searchParameterType)
Expand Down
7 changes: 6 additions & 1 deletion tests/evaluator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('getMatchingFunctions everything defined', () => {

it('should correctly parse ":?...,string"', () => {
const result = evaluateSearchQuery('testproject.tsconfig.json', { kind: 'both', returnTypes: [''], parameterTypes: [['...'], ['string']] })
expect(result.length).toEqual(3)
expect(result.length).toEqual(4)
})

it('should correctly parse ":?{a&b}"', () => {
Expand All @@ -60,4 +60,9 @@ describe('getMatchingFunctions everything defined', () => {
const result = evaluateSearchQuery('testproject.tsconfig.json', { kind: 'both', returnTypes: [''], parameterTypes: [['{a}']] })
expect(result.length).toEqual(1)
})

it('should correctly parse ":{a}?"', () => {
const result = evaluateSearchQuery('testproject.tsconfig.json', { kind: 'both', returnTypes: ['{a}'], parameterTypes: [] })
expect(result.length).toEqual(1)
})
})
4 changes: 4 additions & 0 deletions tests/testProject/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ export class Foo {
public asd (a: TestType): string {
return '42'
}

public tt1 (a: string, ...b: string[]): TestType {
return { a: '42', b: '42' }
}
}

0 comments on commit 9792707

Please sign in to comment.