add DiagnosticsCollection#has and #get

This commit is contained in:
Johannes Rieken
2016-04-08 17:30:56 +02:00
parent aeb52ceb8d
commit 8cdf377b66
3 changed files with 90 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ import {languages, Uri, Diagnostic, Range} from 'vscode';
suite('languages namespace tests', () => {
test('diagnostic collection', function () {
test('diagnostic collection, forEach, clear, has', function () {
let collection = languages.createDiagnosticCollection('test');
assert.equal(collection.name, 'test');
collection.dispose();
@@ -43,5 +43,33 @@ suite('languages namespace tests', () => {
]);
collection.forEach(() => c++);
assert.equal(c, 2);
assert.ok(collection.has(Uri.parse('foo:bar1')));
assert.ok(collection.has(Uri.parse('foo:bar2')));
assert.ok(!collection.has(Uri.parse('foo:bar3')));
collection.delete(Uri.parse('foo:bar1'));
assert.ok(!collection.has(Uri.parse('foo:bar1')));
});
test('diagnostic collection, immutable read', function () {
let collection = languages.createDiagnosticCollection('test');
collection.set(Uri.parse('foo:bar'), [
new Diagnostic(new Range(0, 0, 1, 1), 'message-1'),
new Diagnostic(new Range(0, 0, 1, 1), 'message-2')
]);
let array = collection.get(Uri.parse('foo:bar'));
assert.throws(() => array.length = 0);
assert.throws(() => array.pop());
assert.throws(() => array[0] = new Diagnostic(new Range(0, 0, 0, 0), 'evil'));
collection.forEach((uri, array) => {
assert.throws(() => array.length = 0);
assert.throws(() => array.pop());
assert.throws(() => array[0] = new Diagnostic(new Range(0, 0, 0, 0), 'evil'));
});
array = collection.get(Uri.parse('foo:bar'));
assert.equal(array.length, 2);
});
});