-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
90 lines (76 loc) · 3.06 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
require('mocha');
var assert = require('assert');
var koalas = require('./');
describe('koalas', function() {
it('should return the first value', function() {
var expected = 'foo';
var actual = koalas('foo', 'bar', 'baz', null, undefined);
assert.equal(actual, expected);
});
it('should return the second value when first is null', function() {
var expected = 'foo';
var actual = koalas(null, 'foo', 'bar', 'baz', undefined);
assert.equal(actual, expected);
});
it('should return the second value when first is undefined', function() {
var expected = 'foo';
var actual = koalas(undefined, 'foo', 'bar', 'baz', null);
assert.equal(actual, expected);
});
it('should return the second value when first is NaN', function() {
var expected = 'foo';
var actual = koalas(NaN, 'foo', 'bar', 'baz', null);
assert.equal(actual, expected);
});
it('should return a string', function() {
var expected = 'foo';
var actual = koalas(undefined, 'foo', 'bar', 'baz', null);
assert.equal(actual, expected);
});
it('should return a number', function() {
var expected = 42;
var actual = koalas(undefined, null, 42, 'foo', {bar: 'baz'}, null);
assert.equal(actual, expected);
});
it('should return an object', function() {
var expected = {bar: 'baz'};
var actual = koalas(undefined, null, {bar: 'baz'}, 42, 'foo', null);
assert.deepEqual(actual, expected);
});
it('should return an array', function() {
var expected = [{bar: 'baz'}, 'a', 42];
var actual = koalas(undefined, null, [{bar: 'baz'}, 'a', 42], {bar: 'baz'}, 42, 'foo', null);
assert.deepEqual(actual, expected);
});
it('should return an empty array', function() {
var expected = [];
var actual = koalas(undefined, null, [], [{bar: 'baz'}, 'a', 42], {bar: 'baz'}, 42, 'foo', null);
assert.deepEqual(actual, expected);
});
it('should return an array with "invalid" values', function() {
var expected = [undefined, null, NaN, {bar: 'baz'}, 'a', 42];
var actual = koalas(undefined, null, [undefined, null, NaN, {bar: 'baz'}, 'a', 42], [{bar: 'baz'}, 'a', 42], {bar: 'baz'}, 42, 'foo', null);
assert.equal(actual.length, expected.length);
assert.equal(typeof actual[0], 'undefined');
assert.equal(actual[1], null);
assert(isNaN(actual[2]));
assert.deepEqual(actual[3], expected[3]);
assert.equal(actual[4], expected[4]);
assert.equal(actual[5], expected[5]);
});
it('should return a RegExp', function() {
var expected = /foo/gi;
var actual = koalas(undefined, null, /foo/gi, [{bar: 'baz'}, 'a', 42], {bar: 'baz'}, 42, 'foo', null);
assert.deepEqual(actual, expected);
});
it('should return a Buffer', function() {
var expected = new Buffer('foo');
var actual = koalas(undefined, null, new Buffer('foo'), [{bar: 'baz'}, 'a', 42], {bar: 'baz'}, 42, 'foo', null);
assert.deepEqual(actual, expected);
});
it('should return last value when nothing is valid', function() {
var actual = koalas(undefined, null, NaN);
assert(isNaN(actual));
});
});