Consolidate logic to use the lib in one location in the tests

This commit is contained in:
Mohamed Hegazy
2014-08-11 15:35:15 -07:00
parent 851e3358ce
commit 349367d991
7 changed files with 108 additions and 195 deletions

View File

@@ -254,7 +254,7 @@ module FourSlash {
}
});
this.languageServiceShimHost.addScript('lib.d.ts', Harness.Compiler.libTextMinimal);
this.languageServiceShimHost.addDefaultLibrary();
// Sneak into the language service and get its compiler so we can examine the syntax trees
@@ -1467,7 +1467,7 @@ module FourSlash {
var referenceLanguageService = referenceLanguageServiceShim.languageService;
// Add lib.d.ts to the reference language service
referenceLanguageServiceShimHost.addScript('lib.d.ts', Harness.Compiler.libTextMinimal);
referenceLanguageServiceShimHost.addDefaultLibrary();
for (var i = 0; i < this.testData.files.length; i++) {
var file = this.testData.files[i];
@@ -1885,7 +1885,7 @@ module FourSlash {
// Cache these between executions so we don't have to re-parse them for every test
var fourslashSourceFile: ts.SourceFile = undefined;
var libdtsSourceFile: ts.SourceFile = undefined;
export function runFourSlashTestContent(content: string, fileName: string): TestXmlData {
// Parse out the files and their metadata
var testData = parseTestData(content, fileName);
@@ -1896,12 +1896,11 @@ module FourSlash {
var fourslashFilename = 'fourslash.ts';
var tsFn = 'tests/cases/fourslash/' + fourslashFilename;
fourslashSourceFile = fourslashSourceFile || ts.createSourceFile(tsFn, Harness.IO.readFile(tsFn), ts.ScriptTarget.ES5, /*version*/ 0, /*isOpen*/ false);
libdtsSourceFile = libdtsSourceFile || ts.createSourceFile('lib.d.ts', Harness.Compiler.libTextMinimal, ts.ScriptTarget.ES3, /*version*/ 0, /*isOpen*/ false);
var files: { [filename: string]: ts.SourceFile; } = {};
files[fourslashFilename] = fourslashSourceFile;
files[fileName] = ts.createSourceFile(fileName, content, ts.ScriptTarget.ES5, /*version*/ 0, /*isOpen*/ false);
files['lib.d.ts'] = libdtsSourceFile;
files[Harness.Compiler.defaultLibFileName] = Harness.Compiler.defaultLibSourceFile;
var host = Harness.Compiler.createCompilerHost(files, (fn, contents) => result = contents);
var program = ts.createProgram([fileName, fourslashFilename], {}, host);

View File

@@ -434,15 +434,15 @@ module Harness {
export var libFolder: string;
switch (Utils.getExecutionEnvironment()) {
case Utils.ExecutionEnvironment.CScript:
libFolder = Path.filePath(global['WScript'].ScriptFullName);
libFolder = "built/local/";
tcServicesFilename = "built/local/typescriptServices.js";
break;
case Utils.ExecutionEnvironment.Node:
libFolder = (__dirname + '/');
libFolder = "built/local/";
tcServicesFilename = "built/local/typescriptServices.js";
break;
case Utils.ExecutionEnvironment.Browser:
libFolder = "bin/";
libFolder = "built/local/";
tcServicesFilename = "built/local/typescriptServices.js";
break;
default:
@@ -531,8 +531,8 @@ module Harness {
}
}
export var libText = IO.readFile(libFolder + "lib.d.ts");
export var libTextMinimal = IO.readFile('bin/lib.core.d.ts');
export var defaultLibFileName = 'lib.d.ts';
export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.ES5);
export function createCompilerHost(filemap: { [filename: string]: ts.SourceFile; }, writeFile: (fn: string, contents: string, writeByteOrderMark:boolean) => void): ts.CompilerHost {
return {
@@ -542,15 +542,15 @@ module Harness {
if (fn in filemap) {
return filemap[fn];
} else {
var lib = 'lib.d.ts';
if (fn.substr(fn.length - lib.length) === lib) {
return filemap[fn] = ts.createSourceFile('lib.d.ts', libTextMinimal, languageVersion);
var lib = defaultLibFileName;
if (fn === defaultLibFileName) {
return defaultLibSourceFile;
}
// Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC
return null;
}
},
getDefaultLibFilename: () => 'lib.d.ts',
getDefaultLibFilename: () => defaultLibFileName,
writeFile: writeFile,
getCanonicalFileName: ts.getCanonicalFileName,
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,

View File

@@ -175,7 +175,7 @@ module Harness.LanguageService {
}
public addDefaultLibrary() {
this.addScript("lib.d.ts", Harness.Compiler.libText);
this.addScript(Harness.Compiler.defaultLibFileName, Harness.Compiler.defaultLibSourceFile.text);
}
public getHostIdentifier(): string {

View File

@@ -136,8 +136,8 @@ class ProjectRunner extends RunnerBase {
function getSourceFile(filename: string, languageVersion: ts.ScriptTarget): ts.SourceFile {
var sourceFile: ts.SourceFile = undefined;
if (filename === 'lib.d.ts') {
sourceFile = ts.createSourceFile('lib.d.ts', Harness.Compiler.libTextMinimal, languageVersion);
if (filename === Harness.Compiler.defaultLibFileName) {
sourceFile = Harness.Compiler.defaultLibSourceFile;
}
else {
assert.isTrue(!ts.filter(readInputFiles, sourceFile => sourceFile.filename == filename).length, "Compiler trying to read same file again: " + filename);
@@ -217,7 +217,7 @@ class ProjectRunner extends RunnerBase {
function createCompilerHost(): ts.CompilerHost {
return {
getSourceFile: getSourceFile,
getDefaultLibFilename: () => "lib.d.ts",
getDefaultLibFilename: () => Harness.Compiler.defaultLibFileName,
writeFile: writeFile,
getCurrentDirectory: getCurrentDirectory,
getCanonicalFileName: ts.getCanonicalFileName,

View File

@@ -1,138 +1,47 @@
==== tests/cases/conformance/types/members/duplicateStringIndexers.ts (52 errors) ====
==== tests/cases/conformance/types/members/duplicateStringIndexers.ts (6 errors) ====
// it is an error to have duplicate index signatures of the same kind in a type
interface Number {
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
!!! Property 'toExponential' of type '(fractionDigits?: number) => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'toFixed' of type '(fractionDigits?: number) => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'toPrecision' of type '(precision?: number) => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'toString' of type '(radix?: number) => string' is not assignable to string index type 'string'.
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
module test {
interface Number {
[x: string]: string;
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
!!! Duplicate string index signature.
}
}
interface String {
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
!!! Property 'charAt' of type '(pos: number) => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'charCodeAt' of type '(index: number) => number' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'concat' of type '(...strings: string[]) => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'indexOf' of type '(searchString: string, position?: number) => number' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'lastIndexOf' of type '(searchString: string, position?: number) => number' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'length' of type 'number' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'localeCompare' of type '(that: string) => number' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'match' of type '{ (regexp: string): string[]; (regexp: RegExp): string[]; }' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'replace' of type '{ (searchValue: string, replaceValue: string): string; (searchValue: string, replaceValue: (substring: string, ...args: any[]) => string): string; (searchValue: RegExp, replaceValue: string): string; (searchValue: RegExp, replaceValue: (substring: string, ...args: any[]) => string): string; }' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'search' of type '{ (regexp: string): number; (regexp: RegExp): number; }' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'slice' of type '(start?: number, end?: number) => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'split' of type '{ (separator: string, limit?: number): string[]; (separator: RegExp, limit?: number): string[]; }' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'substr' of type '(from: number, length?: number) => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'substring' of type '(start: number, end?: number) => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'toLocaleLowerCase' of type '() => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'toLocaleUpperCase' of type '() => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'toLowerCase' of type '() => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'toString' of type '() => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'toUpperCase' of type '() => string' is not assignable to string index type 'string'.
~~~~~~~~~~~~~~~~~~~~
!!! Property 'trim' of type '() => string' is not assignable to string index type 'string'.
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
interface String {
[x: string]: string;
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
!!! Duplicate string index signature.
}
}
interface Array<T> {
[x: string]: T;
~~~~~~~~~~~~~~~
!!! Property 'concat' of type '{ <U extends T[]>(...items: U[]): T[]; (...items: T[]): T[]; }' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'every' of type '(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any) => boolean' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'filter' of type '(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any) => T[]' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'forEach' of type '(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any) => void' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'indexOf' of type '(searchElement: T, fromIndex?: number) => number' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'join' of type '(separator?: string) => string' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'lastIndexOf' of type '(searchElement: T, fromIndex?: number) => number' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'length' of type 'number' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'map' of type '<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any) => U[]' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'pop' of type '() => T' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'push' of type '(...items: T[]) => number' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'reduce' of type '{ (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; }' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'reduceRight' of type '{ (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; }' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'reverse' of type '() => T[]' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'shift' of type '() => T' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'slice' of type '(start?: number, end?: number) => T[]' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'some' of type '(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any) => boolean' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'sort' of type '(compareFn?: (a: T, b: T) => number) => T[]' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'splice' of type '{ (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; }' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'toLocaleString' of type '() => string' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'toString' of type '() => string' is not assignable to string index type 'T'.
~~~~~~~~~~~~~~~
!!! Property 'unshift' of type '(...items: T[]) => number' is not assignable to string index type 'T'.
[x: string]: T;
~~~~~~~~~~~~~~~
interface Array<T> {
[x: string]: T;
[x: string]: T;
~~~~~~~~~~~~~~~
!!! Duplicate string index signature.
}
}
class C {
[x: string]: string;
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
class C {
[x: string]: string;
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
!!! Duplicate string index signature.
}
}
interface I {
[x: string]: string;
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
interface I {
[x: string]: string;
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
!!! Duplicate string index signature.
}
}
var a: {
[x: string]: string;
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
var a: {
[x: string]: string;
[x: string]: string;
~~~~~~~~~~~~~~~~~~~~
!!! Duplicate string index signature.
}
}

View File

@@ -1,42 +1,46 @@
//// [duplicateStringIndexers.ts]
// it is an error to have duplicate index signatures of the same kind in a type
interface Number {
[x: string]: string;
[x: string]: string;
}
module test {
interface Number {
[x: string]: string;
[x: string]: string;
}
interface String {
[x: string]: string;
[x: string]: string;
}
interface String {
[x: string]: string;
[x: string]: string;
}
interface Array<T> {
[x: string]: T;
[x: string]: T;
}
interface Array<T> {
[x: string]: T;
[x: string]: T;
}
class C {
[x: string]: string;
[x: string]: string;
}
class C {
[x: string]: string;
[x: string]: string;
}
interface I {
[x: string]: string;
[x: string]: string;
}
interface I {
[x: string]: string;
[x: string]: string;
}
var a: {
[x: string]: string;
[x: string]: string;
var a: {
[x: string]: string;
[x: string]: string;
}
}
//// [duplicateStringIndexers.js]
var C = (function () {
function C() {
}
return C;
})();
var a;
var test;
(function (test) {
var C = (function () {
function C() {
}
return C;
})();
var a;
})(test || (test = {}));

View File

@@ -1,32 +1,33 @@
// it is an error to have duplicate index signatures of the same kind in a type
interface Number {
[x: string]: string;
[x: string]: string;
}
module test {
interface Number {
[x: string]: string;
[x: string]: string;
}
interface String {
[x: string]: string;
[x: string]: string;
}
interface String {
[x: string]: string;
[x: string]: string;
}
interface Array<T> {
[x: string]: T;
[x: string]: T;
}
interface Array<T> {
[x: string]: T;
[x: string]: T;
}
class C {
[x: string]: string;
[x: string]: string;
}
class C {
[x: string]: string;
[x: string]: string;
}
interface I {
[x: string]: string;
[x: string]: string;
}
interface I {
[x: string]: string;
[x: string]: string;
}
var a: {
[x: string]: string;
[x: string]: string;
var a: {
[x: string]: string;
[x: string]: string;
}
}