From 545fa20efdfa6d8372052324abc70fce6686ed5a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 27 Feb 2015 16:25:44 -0800 Subject: [PATCH] Add registry tests. --- .../unittests/services/documentRegistry.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/cases/unittests/services/documentRegistry.ts b/tests/cases/unittests/services/documentRegistry.ts index 339c8866329..34dda543c1c 100644 --- a/tests/cases/unittests/services/documentRegistry.ts +++ b/tests/cases/unittests/services/documentRegistry.ts @@ -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)); + }); }); \ No newline at end of file