Skip to content

Commit e0c00f9

Browse files
alistairjcbrownTheLarkInn
authored andcommitted
Add tests for ArrayMap (webpack#3662)
1 parent c7b06ad commit e0c00f9

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

test/ArrayMap.test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
var should = require("should");
2+
var ArrayMap = require("../lib/ArrayMap");
3+
4+
describe("ArrayMap", function() {
5+
var myArrayMap;
6+
7+
beforeEach(function() {
8+
myArrayMap = new ArrayMap();
9+
});
10+
11+
describe('get', function() {
12+
it('returns value for known key', function() {
13+
myArrayMap.set('foo', 10);
14+
myArrayMap.get('foo').should.be.exactly(10);
15+
});
16+
17+
it('returns undefined for unknown key', function() {
18+
should(myArrayMap.get('foo')).be.undefined();
19+
});
20+
});
21+
22+
describe('set', function() {
23+
it('returns reference to array map instance', function() {
24+
myArrayMap.set('foo', 10).should.be.exactly(myArrayMap);
25+
});
26+
27+
it('sets value for new key', function() {
28+
myArrayMap.set('foo', 10);
29+
myArrayMap.get('foo').should.be.exactly(10);
30+
});
31+
32+
it('overwrites value for existing key', function() {
33+
myArrayMap.set('foo', 10).set('foo', 'hello');
34+
myArrayMap.get('foo').should.be.exactly('hello');
35+
});
36+
});
37+
38+
describe('remove', function() {
39+
it('removes entry for existing data', function() {
40+
myArrayMap.set('foo', 10);
41+
myArrayMap.remove('foo').should.be.exactly(true);
42+
should(myArrayMap.get('foo')).be.undefined();
43+
});
44+
45+
it('does nothing for non-existant data', function() {
46+
myArrayMap.remove('foo').should.be.exactly(false);
47+
should(myArrayMap.get('foo')).be.undefined();
48+
});
49+
});
50+
51+
describe('clone', function() {
52+
it('creates a new instance of the array map', function() {
53+
myArrayMap.clone().should.not.be.exactly(myArrayMap);
54+
});
55+
56+
it('creates a new copy with no shared data', function() {
57+
var myArrayMap2 = myArrayMap.set('foo', 10).clone();
58+
myArrayMap.set('foo', 'hello');
59+
myArrayMap2.set('bar', 20);
60+
61+
myArrayMap.get('foo').should.be.exactly('hello');
62+
myArrayMap2.get('foo').should.be.exactly(10);
63+
should(myArrayMap.get('bar')).be.undefined();
64+
myArrayMap2.get('bar').should.be.exactly(20);
65+
});
66+
});
67+
});

0 commit comments

Comments
 (0)