Skip to content

Commit 545fa20

Browse files
Add registry tests.
1 parent 604c37e commit 545fa20

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/cases/unittests/services/documentRegistry.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,40 @@ describe("DocumentRegistry", () => {
3535

3636
assert(f3 === f4, "Changed module: Expected to have the same instance of the document");
3737
});
38+
39+
it("Acquiring document gets correct version 1", () => {
40+
var documentRegistry = ts.createDocumentRegistry();
41+
var defaultCompilerOptions = ts.getDefaultCompilerOptions();
42+
43+
// Simulate one LS getting the document.
44+
var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), /* version */ "1");
45+
46+
// Simulate another LS getting the document at another version.
47+
var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), /* version */ "2");
48+
49+
assert(f2.version === "2");
50+
});
51+
52+
it("Acquiring document gets correct version 2", () => {
53+
debugger;
54+
var documentRegistry = ts.createDocumentRegistry();
55+
var defaultCompilerOptions = ts.getDefaultCompilerOptions();
56+
57+
var contents = "var x = 1;"
58+
var snapshot = ts.ScriptSnapshot.fromString(contents);
59+
60+
// Simulate one LS getting the document.
61+
var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, snapshot, /* version */ "1");
62+
63+
// Simulate another LS getting that document.
64+
var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, snapshot, /* version */ "1");
65+
66+
// Now LS1 updates their document.
67+
var f3 = documentRegistry.updateDocument(f1, "file1.ts", defaultCompilerOptions, snapshot, /* version */ "2",
68+
ts.createTextChangeRange(ts.createTextSpan(0, contents.length), contents.length));
69+
70+
// Now LS2 tries to update their document.
71+
var f4 = documentRegistry.updateDocument(f1, "file1.ts", defaultCompilerOptions, snapshot, /* version */ "3",
72+
ts.createTextChangeRange(ts.createTextSpan(0, contents.length), contents.length));
73+
});
3874
});

0 commit comments

Comments
 (0)