Skip to content

Commit

Permalink
Merge pull request #13817 from jchadwick/jchadwick/codecoverage/colle…
Browse files Browse the repository at this point in the history
…ctions

Increasing test coverage for collections
  • Loading branch information
jrieken committed Oct 17, 2016
2 parents 9583734 + 269022b commit c7c960e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/vs/base/test/common/collections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,69 @@ suite('Collections', () => {
dict['toString'] = 123;
collections.forEach(dict, () => count++);
assert.equal(count, 1);

collections.forEach(dict, () => false);

collections.forEach(dict, (x, remove) => remove());
assert.equal(dict['toString'], null);

// don't iterate over properties that are not on the object itself
let test = Object.create({ 'derived': true });
collections.forEach(test, () => assert(false));
});

test('lookupOrInsert - should not insert if found', () => {
const property = 123;

let from = collections.createNumberDictionary();
from[property] = 'whatever';

collections.lookupOrInsert(from, property, () => assert(false));
});

test('lookupOrInsert - should insert if not found', () => {

const expected = 'alternate', property = 'test';

let fromWithValue = collections.createStringDictionary();
collections.lookupOrInsert(fromWithValue, property, expected);
assert.equal(fromWithValue[property], expected);

let fromWithCallback = collections.createStringDictionary();
collections.lookupOrInsert(fromWithCallback, property, () => expected);
assert.equal(fromWithCallback[property], expected);
});

test('groupBy', () => {

const group1 = 'a', group2 = 'b';
const value1 = 1, value2 = 2, value3 = 3;
let source = [
{ key: group1, value: value1 },
{ key: group1, value: value2 },
{ key: group2, value: value3 },
];

let grouped = collections.groupBy(source, x => x.key);

// Group 1
assert.equal(grouped[group1].length, 2);
assert.equal(grouped[group1][0].value, value1);
assert.equal(grouped[group1][1].value, value2);

// Group 2
assert.equal(grouped[group2].length, 1);
assert.equal(grouped[group2][0].value, value3);
});

test('insert', () => {

const expected = 'value', hashFn = x => x.toString();

let into = collections.createStringDictionary();
collections.insert(into, expected, hashFn);

assert.equal(into[expected], expected);
});

test('remove', () => {
Expand Down

0 comments on commit c7c960e

Please sign in to comment.