Adding rename tests.

This commit is contained in:
Cyrus Najmabadi 2014-09-17 15:19:20 -07:00
parent a1ca10d380
commit 7320a189f1
4 changed files with 62 additions and 0 deletions

View File

@ -832,6 +832,44 @@ module FourSlash {
}
}
private validate(name: string, expected: string, actual: string) {
if (expected && expected !== actual) {
throw new Error("Expected " + name + " '" + expected + "'. Got '" + actual + "' instead.");
}
}
public verifyRenameInfoSucceeded(displayName?: string, fullDisplayName?: string, kind?: string, kindModifiers?: string) {
var renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition);
if (!renameInfo.canRename) {
throw new Error("Rename did not succeed");
}
this.validate("displayName", displayName, renameInfo.displayName);
this.validate("fullDisplayName", fullDisplayName, renameInfo.fullDisplayName);
this.validate("kind", kind, renameInfo.kind);
this.validate("kindModifiers", kindModifiers, renameInfo.kindModifiers);
if (this.getRanges().length !== 1) {
throw new Error("Expected a single range to be selected in the test file.");
}
var expectedRange = this.getRanges()[0];
if (renameInfo.triggerSpan.start() !== expectedRange.start ||
renameInfo.triggerSpan.end() !== expectedRange.end) {
throw new Error("Expected triggerSpan [" + expectedRange.start + "," + expectedRange.end + "). Got [" +
renameInfo.triggerSpan.start() + "," + renameInfo.triggerSpan.end() + ") instead.");
}
}
public verifyRenameInfoFailed(message?: string) {
var renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition);
if (renameInfo.canRename) {
throw new Error("Rename was expected to fail");
}
this.validate("error", message, renameInfo.localizedErrorMessage);
}
//private getFormalParameter() {
// var help = this.languageService.getSignatureHelpItems(this.activeFile.fileName, this.currentCaretPosition);
// return help.formal;

View File

@ -390,6 +390,14 @@ module FourSlashInterface {
public semanticClassificationsAre(...classifications: { classificationType: string; text: string }[]) {
FourSlash.currentTestState.verifySemanticClassifications(classifications);
}
public renameInfoSucceeded(displayName?: string, fullDisplayName?: string, kind?: string, kindModifiers?: string) {
FourSlash.currentTestState.verifyRenameInfoSucceeded(displayName, fullDisplayName, kind, kindModifiers)
}
public renameInfoFailed(message?: string) {
FourSlash.currentTestState.verifyRenameInfoFailed(message)
}
}
export class edit {

View File

@ -0,0 +1,8 @@
/// <reference path="fourslash.ts"/>
////class [|/**/C|] {
////
////}
goTo.marker("");
verify.renameInfoSucceeded("C");

View File

@ -0,0 +1,8 @@
/// <reference path="fourslash.ts"/>
/////**/class C {
////
////}
goTo.marker("");
verify.renameInfoFailed();