-
-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
322722d
commit fff46b3
Showing
6 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/vscode-vue-languageservice/testCases/typeChecks/emit_from.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script lang="ts" setup> | ||
defineEmits({ fooBar: (num: number) => true }); | ||
</script> |
21 changes: 21 additions & 0 deletions
21
packages/vscode-vue-languageservice/testCases/typeChecks/emit_to.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<Comp @foo-bar="strFn"></Comp> | ||
<Comp @fooBar="strFn"></Comp> | ||
<Comp @foo-bar="numFn"></Comp> | ||
<Comp @fooBar="numFn"></Comp> | ||
<Comp @foo-bar="strFn($event)"></Comp> | ||
<Comp @fooBar="strFn($event)"></Comp> | ||
<Comp @foo-bar="numFn($event)"></Comp> | ||
<Comp @fooBar="numFn($event)"></Comp> | ||
<Comp @foo-bar="payload => strFn(payload)"></Comp> | ||
<Comp @fooBar="payload => strFn(payload)"></Comp> | ||
<Comp @foo-bar="payload => numFn(payload)"></Comp> | ||
<Comp @fooBar="payload => numFn(payload)"></Comp> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import Comp from './emit_from.vue'; | ||
function strFn(_: string) { } | ||
function numFn(_: number) { } | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/vscode-vue-languageservice/tests/typeChecks/emit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as path from 'upath'; | ||
import { defineTypeCheck } from '../utils/defineTypeCheck'; | ||
|
||
defineTypeCheck(path.resolve(__dirname, '../../testCases/typeChecks/emit_to.vue'), [ | ||
{ | ||
start: 19, | ||
end: 26, | ||
source: 'ts', | ||
code: 2322, | ||
}, | ||
{ | ||
start: 51, | ||
end: 57, | ||
source: 'ts', | ||
code: 2322, | ||
}, | ||
{ | ||
start: 160, | ||
end: 166, | ||
source: 'ts', | ||
code: 2345, | ||
}, | ||
{ | ||
start: 199, | ||
end: 205, | ||
source: 'ts', | ||
code: 2345, | ||
}, | ||
{ | ||
start: 329, | ||
end: 336, | ||
source: 'ts', | ||
code: 2345, | ||
}, | ||
{ | ||
start: 380, | ||
end: 387, | ||
source: 'ts', | ||
code: 2345, | ||
}, | ||
]); |
64 changes: 64 additions & 0 deletions
64
packages/vscode-vue-languageservice/tests/utils/defineTypeCheck.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type * as vscode from 'vscode-languageserver/node'; | ||
import * as path from 'upath'; | ||
import { createTester } from './createTester'; | ||
import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
import * as shared from '@volar/shared'; | ||
|
||
const volarRoot = path.resolve(__dirname, '../../../..'); | ||
const testRoot = path.resolve(__dirname, '../../testCases'); | ||
const tester = createTester(testRoot); | ||
|
||
export function defineTypeCheck(fileName: string, expectErrors: { | ||
start: number, | ||
end: number, | ||
source: string, | ||
code: number, | ||
}[]) { | ||
|
||
describe(`type check to ${path.relative(volarRoot, fileName)}`, () => { | ||
|
||
const uri = shared.fsPathToUri(fileName); | ||
const script = tester.host.getScriptSnapshot(fileName); | ||
|
||
let errors: vscode.Diagnostic[] | undefined; | ||
|
||
beforeAll(async () => { | ||
errors = await tester.languageService.doValidation(uri); | ||
}); | ||
|
||
it(`should has script snapshot`, async () => { | ||
expect(!!script).toEqual(true); | ||
const errors = await tester.languageService.doValidation(uri); | ||
expect(errors?.length).toEqual(expectErrors.length); | ||
}); | ||
|
||
it(`should has ${expectErrors.length} errors`, async () => { | ||
const errors = await tester.languageService.doValidation(uri); | ||
expect(errors?.length).toEqual(expectErrors.length); | ||
}); | ||
|
||
if (script) { | ||
|
||
const doc = TextDocument.create('', '', 0, script.getText(0, script.getLength())); | ||
|
||
for (const expectError of expectErrors) { | ||
|
||
const pos = doc.positionAt(expectError.start); | ||
|
||
it(`should report ${expectError.source}(${expectError.code}) at ${path.relative(volarRoot, fileName)}:${pos.line + 1}:${pos.character + 1}`, () => { | ||
expect(errors?.some(error => { | ||
|
||
const start = doc.offsetAt(error.range.start); | ||
const end = doc.offsetAt(error.range.end); | ||
|
||
return expectError.start === start | ||
&& expectError.end === end | ||
&& expectError.source === error.source | ||
&& expectError.code === error.code | ||
|
||
})).toEqual(true); | ||
}); | ||
} | ||
} | ||
}); | ||
} |