mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Merge pull request #924 from Microsoft/fixColorizationUnittest
Fix colorization unittest
This commit is contained in:
commit
a6eb698f5b
9
Jakefile
9
Jakefile
@ -10,6 +10,7 @@ var servicesDirectory = "src/services/";
|
||||
var harnessDirectory = "src/harness/";
|
||||
var libraryDirectory = "src/lib/";
|
||||
var scriptsDirectory = "scripts/";
|
||||
var unittestsDirectory = "tests/cases/unittests/";
|
||||
var docDirectory = "doc/";
|
||||
|
||||
var builtDirectory = "built/";
|
||||
@ -74,13 +75,17 @@ var harnessSources = [
|
||||
"typeWriter.ts",
|
||||
"fourslashRunner.ts",
|
||||
"projectsRunner.ts",
|
||||
"unittestrunner.ts",
|
||||
"loggedIO.ts",
|
||||
"rwcRunner.ts",
|
||||
"runner.ts"
|
||||
].map(function (f) {
|
||||
return path.join(harnessDirectory, f);
|
||||
});
|
||||
}).concat([
|
||||
"services/colorization.ts",
|
||||
"services/documentRegistry.ts"
|
||||
].map(function (f) {
|
||||
return path.join(unittestsDirectory, f);
|
||||
}));
|
||||
|
||||
var librarySourceMap = [
|
||||
{ target: "lib.core.d.ts", sources: ["core.d.ts"] },
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
// ///<reference path='fourslashRunner.ts' />
|
||||
/// <reference path='projectsRunner.ts' />
|
||||
/// <reference path='rwcRunner.ts' />
|
||||
/// <reference path='unittestrunner.ts' />
|
||||
|
||||
function runTests(runners: RunnerBase[]) {
|
||||
if (reverse) {
|
||||
@ -67,9 +66,6 @@ if (testConfigFile !== '') {
|
||||
case 'fourslash-generated':
|
||||
runners.push(new GeneratedFourslashRunner());
|
||||
break;
|
||||
case 'unittests':
|
||||
runners.push(new UnitTestRunner());
|
||||
break;
|
||||
case 'rwc':
|
||||
runners.push(new RWCRunner());
|
||||
break;
|
||||
@ -93,9 +89,6 @@ if (runners.length === 0) {
|
||||
// language services
|
||||
runners.push(new FourslashRunner());
|
||||
//runners.push(new GeneratedFourslashRunner());
|
||||
|
||||
// unittests
|
||||
runners.push(new UnitTestRunner());
|
||||
}
|
||||
|
||||
sys.newLine = '\r\n';
|
||||
|
||||
@ -1,73 +0,0 @@
|
||||
///<reference path="harness.ts" />
|
||||
///<reference path="runnerbase.ts" />
|
||||
|
||||
class UnitTestRunner extends RunnerBase {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public initializeTests() {
|
||||
this.tests = this.enumerateFiles('tests/cases/unittests/services', /\.ts/i);
|
||||
|
||||
var outfile = new Harness.Compiler.WriterAggregator()
|
||||
var outerr = new Harness.Compiler.WriterAggregator();
|
||||
// note this is running immediately to generate tests to be run later inside describe/it
|
||||
// need a fresh instance so that the previous runner's last test is not hanging around
|
||||
var harnessCompiler = Harness.Compiler.getCompiler({ useExistingInstance: false });
|
||||
|
||||
var toBeAdded = this.tests.map(test => {
|
||||
return { unitName: test, content: Harness.IO.readFile(test) }
|
||||
});
|
||||
harnessCompiler.addInputFiles(toBeAdded);
|
||||
harnessCompiler.setCompilerOptions({ noResolve: true });
|
||||
|
||||
var stdout = new Harness.Compiler.EmitterIOHost();
|
||||
var emitDiagnostics = harnessCompiler.emitAll(stdout);
|
||||
var results = stdout.toArray();
|
||||
var lines: string[] = [];
|
||||
results.forEach(v => lines = lines.concat(v.file.lines));
|
||||
var code = lines.join("\n")
|
||||
|
||||
var nodeContext: any = undefined;
|
||||
if (Utils.getExecutionEnvironment() === Utils.ExecutionEnvironment.Node) {
|
||||
nodeContext = {
|
||||
require: require,
|
||||
process: process,
|
||||
describe: describe,
|
||||
it: it,
|
||||
assert: assert,
|
||||
beforeEach: beforeEach,
|
||||
afterEach: afterEach,
|
||||
before: before,
|
||||
after: after,
|
||||
Harness: Harness,
|
||||
IO: Harness.IO,
|
||||
ts: ts,
|
||||
TypeScript: TypeScript
|
||||
// FourSlash: FourSlash
|
||||
};
|
||||
}
|
||||
|
||||
describe("Setup compiler for compiler unittests", () => {
|
||||
// ensures a clean compiler instance when tests are eventually executed following this describe block
|
||||
harnessCompiler = Harness.Compiler.getCompiler({
|
||||
useExistingInstance: false,
|
||||
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false }
|
||||
});
|
||||
});
|
||||
|
||||
// this generated code is a series of top level describe/it blocks that will run in between the setup and cleanup blocks in this file
|
||||
Utils.evalFile(code, "generated_test_code.js", nodeContext);
|
||||
|
||||
describe("Cleanup after unittests", () => {
|
||||
var harnessCompiler = Harness.Compiler.getCompiler({
|
||||
useExistingInstance: false,
|
||||
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false }
|
||||
});
|
||||
});
|
||||
|
||||
// note this runs immediately (ie before this same code in the describe block above)
|
||||
// to make sure the next runner doesn't include the previous one's stuff
|
||||
harnessCompiler = Harness.Compiler.getCompiler({ useExistingInstance: false });
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,7 @@
|
||||
interface Classification {
|
||||
/// <reference path="..\..\..\..\src\harness\external\mocha.d.ts" />
|
||||
/// <reference path="..\..\..\..\src\harness\harnessLanguageService.ts" />
|
||||
|
||||
interface Classification {
|
||||
position: number;
|
||||
length: number;
|
||||
class: ts.TokenClass;
|
||||
@ -66,7 +69,7 @@ describe('Colorization', function () {
|
||||
function numberLiteral(text: string) { return { value: text, class: ts.TokenClass.NumberLiteral }; }
|
||||
function stringLiteral(text: string) { return { value: text, class: ts.TokenClass.StringLiteral }; }
|
||||
function regExpLiteral(text: string) { return { value: text, class: ts.TokenClass.RegExpLiteral }; }
|
||||
function finalEndOfLineState(value: number) { return { value: value, class: undefined }; }
|
||||
function finalEndOfLineState(value: number) { return { value: value, class: <ts.TokenClass>undefined }; }
|
||||
|
||||
function test(text: string, initialEndOfLineState: ts.EndOfLineState, ...expectedEntries: ClassificationEntry[]): void {
|
||||
var result = getClassifications(text, initialEndOfLineState);
|
||||
@ -253,7 +256,7 @@ describe('Colorization', function () {
|
||||
identifier("Foo"),
|
||||
operator("<"),
|
||||
identifier("Foo"),
|
||||
punctuation(","),
|
||||
operator(","),
|
||||
identifier("Foo"),
|
||||
operator("<"),
|
||||
identifier("number"),
|
||||
@ -265,8 +268,8 @@ describe('Colorization', function () {
|
||||
identifier("Foo"),
|
||||
operator("<"),
|
||||
identifier("Foo"),
|
||||
operator(">"
|
||||
identifier("keyword"),
|
||||
operator(">"),
|
||||
keyword("number"),
|
||||
finalEndOfLineState(ts.EndOfLineState.Start));
|
||||
});
|
||||
});
|
||||
|
||||
@ -5,8 +5,8 @@ describe("DocumentRegistry", () => {
|
||||
var documentRegistry = ts.createDocumentRegistry();
|
||||
var defaultCompilerOptions = ts.getDefaultCompilerOptions();
|
||||
|
||||
var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
|
||||
var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
|
||||
var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false);
|
||||
var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false);
|
||||
|
||||
assert(f1 === f2, "DocumentRegistry should return the same document for the same name");
|
||||
});
|
||||
@ -17,21 +17,21 @@ describe("DocumentRegistry", () => {
|
||||
|
||||
// change compilation setting that doesn't affect parsing - should have the same document
|
||||
compilerOptions.declaration = true;
|
||||
var f1 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
|
||||
var f1 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false);
|
||||
compilerOptions.declaration = false;
|
||||
var f2 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
|
||||
var f2 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false);
|
||||
|
||||
assert(f1 === f2, "Expected to have the same document instance");
|
||||
|
||||
|
||||
// change value of compilation setting that is used during production of AST - new document is required
|
||||
compilerOptions.target = ts.ScriptTarget.ES3;
|
||||
var f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
|
||||
var f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false);
|
||||
|
||||
assert(f1 !== f3, "Changed target: Expected to have different instances of document");
|
||||
|
||||
compilerOptions.module = ts.ModuleKind.CommonJS;
|
||||
var f4 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false);
|
||||
var f4 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false);
|
||||
|
||||
assert(f1 !== f4, "Changed module: Expected to have different instances of document");
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user