UNPKG

1.41 kBJavaScriptView Raw
1var vows = require('vows');
2var assert = require('assert');
3var dedupe = require('../lib/utils').dedupe;
4var suite = vows.describe('utils');
5
6suite.addBatch({
7 'when deduping an array of strings': {
8 topic: function () {
9 return dedupe(['hello', 'hello', 'world', 'world', 'hello']);
10 },
11 'we get back an array with unique values': function (deduped) {
12 assert.lengthOf(deduped, 2);
13 assert.deepEqual(deduped, ['hello', 'world']);
14 }
15 },
16 'when deduping an empty array': {
17 topic: function () {
18 return dedupe([]);
19 },
20 'we get back an empty array': function (deduped) {
21 assert.lengthOf(deduped, 0);
22 }
23 },
24 'when deduping an array that contains empty strings': {
25 topic: function () {
26 return dedupe(['', 'foo', '', 'foo', 'bar']);
27 },
28 'the empty strings are discarded': function (deduped) {
29 assert.lengthOf(deduped, 2);
30 assert.deepEqual(deduped, ['foo', 'bar']);
31 }
32 },
33 'when deduping an array that contains only empty strings': {
34 topic: function () {
35 return dedupe(['', '', '']);
36 },
37 'the empty strings are discarded': function (deduped) {
38 assert.lengthOf(deduped, 0);
39 assert.deepEqual(deduped, []);
40 }
41 }
42});
43
44suite.export(module);