forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunwind.js
53 lines (46 loc) · 1.82 KB
/
unwind.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
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('unwind', function() {
var object = {
name: 'alice',
hobbies: ['Golf', 'Hacking'],
colors: ['red', 'green']
};
it('returns list of destructed object if key is present as list in the object', function() {
eq(R.unwind('hobbies', object), [
{name: 'alice', hobbies: 'Golf', colors: ['red', 'green']},
{name: 'alice', hobbies: 'Hacking', colors: ['red', 'green']}
]);
eq(R.unwind('colors', object), [
{name: 'alice', hobbies: ['Golf', 'Hacking'], colors: 'red'},
{name: 'alice', hobbies: ['Golf', 'Hacking'], colors: 'green'}
]);
});
it('returns a list containing only the original object if the key is not present in the object', function() {
eq(R.unwind('hobby', object), [object]);
});
it('returns a list containing only the original object if the value for that key is not iterable', function() {
eq(R.unwind('passtimes', object), [object]);
eq(R.unwind('options', {
title: 'What is the best programming language?',
options: {0: 'Python', 1: 'Java', 2: 'JavaScript', 3: 'C++'},
ans: 'Correct Answer is 2'
}), [{
title: 'What is the best programming language?',
options: {0: 'Python', 1: 'Java', 2: 'JavaScript', 3: 'C++'},
ans: 'Correct Answer is 2'
}]);
eq(R.unwind('hobbies', { name: 'Berney', hobbies: NaN}), [{ name: 'Berney', hobbies: NaN}]);
});
it('does not treat a String as a list', function() {
eq(R.unwind('hobbies', { name: 'alice', hobbies:'Golf' }), [
{ name: 'alice', hobbies: 'Golf'}
]);
// Incorrect: result <- [
// { name: 'alice', hobbies: 'G'},
// { name: 'alice', hobbies: 'o'},
// { name: 'alice', hobbies: 'l'},
// { name: 'alice', hobbies: 'f'},
// ]
});
});