mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Add registry tests.
This commit is contained in:
@@ -35,4 +35,40 @@ describe("DocumentRegistry", () => {
|
||||
|
||||
assert(f3 === f4, "Changed module: Expected to have the same instance of the document");
|
||||
});
|
||||
|
||||
it("Acquiring document gets correct version 1", () => {
|
||||
var documentRegistry = ts.createDocumentRegistry();
|
||||
var defaultCompilerOptions = ts.getDefaultCompilerOptions();
|
||||
|
||||
// Simulate one LS getting the document.
|
||||
var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), /* version */ "1");
|
||||
|
||||
// Simulate another LS getting the document at another version.
|
||||
var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), /* version */ "2");
|
||||
|
||||
assert(f2.version === "2");
|
||||
});
|
||||
|
||||
it("Acquiring document gets correct version 2", () => {
|
||||
debugger;
|
||||
var documentRegistry = ts.createDocumentRegistry();
|
||||
var defaultCompilerOptions = ts.getDefaultCompilerOptions();
|
||||
|
||||
var contents = "var x = 1;"
|
||||
var snapshot = ts.ScriptSnapshot.fromString(contents);
|
||||
|
||||
// Simulate one LS getting the document.
|
||||
var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, snapshot, /* version */ "1");
|
||||
|
||||
// Simulate another LS getting that document.
|
||||
var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, snapshot, /* version */ "1");
|
||||
|
||||
// Now LS1 updates their document.
|
||||
var f3 = documentRegistry.updateDocument(f1, "file1.ts", defaultCompilerOptions, snapshot, /* version */ "2",
|
||||
ts.createTextChangeRange(ts.createTextSpan(0, contents.length), contents.length));
|
||||
|
||||
// Now LS2 tries to update their document.
|
||||
var f4 = documentRegistry.updateDocument(f1, "file1.ts", defaultCompilerOptions, snapshot, /* version */ "3",
|
||||
ts.createTextChangeRange(ts.createTextSpan(0, contents.length), contents.length));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user