1
- var expect = require ( 'chai' ) . expect ,
2
- expandHash = require ( '..' ) ;
1
+ 'use strict' ;
3
2
4
- describe ( 'expand-hash' , function ( ) {
3
+ require ( 'mocha' ) ;
4
+ const assert = require ( 'assert' ) ;
5
+ const expandHash = require ( '..' ) ;
5
6
6
- /***
7
- var expandHash = require('expand-hash');
8
- var hash = {
9
- 'foo': 'bar',
10
- 'baz': 'bang'
11
- };
12
-
13
- var expanded = expandHash(hash);
14
- console.log('expanded: ', expanded);
15
- ***/
16
-
17
- it ( 'expand simple hash' , function ( done ) {
18
- var simple = { 'foo' : 'bar' , 'baz' : 'bang' } ;
19
- var expected = { foo : 'bar' , baz : 'bang' } ;
20
- var actual = expandHash ( simple ) ;
21
- expect ( actual ) . to . eql ( expected ) ;
22
- done ( ) ;
7
+ describe ( 'expand-hash' , ( ) => {
8
+ it ( 'expand simple hash' , ( ) => {
9
+ assert . deepEqual ( expandHash ( { foo : 'bar' , baz : 'bang' } ) , { foo : 'bar' , baz : 'bang' } ) ;
23
10
} ) ;
24
11
25
- /***
26
- var expandHash = require('expand-hash');
27
- var hash = {
28
- 'foo.bar': 'bar',
29
- 'foo.baz': 'baz',
30
- 'something': 'else'
31
- };
32
- var expanded = expandHash(hash);
33
- console.log('expanded: ', expanded);
34
- **/
35
-
36
- it ( 'expand complex hash' , function ( done ) {
37
- var complex = { 'foo.bar' : 'bar' , 'foo.baz' : 'baz' , 'beep.boop' : 'bop' , 'something' : 'else' } ;
38
- var expected = { foo : { bar : 'bar' , baz : 'baz' } , beep : { boop : 'bop' } , something : 'else' } ;
39
- var actual = expandHash ( complex ) ;
40
- expect ( actual ) . to . eql ( expected ) ;
41
- done ( ) ;
12
+ it ( 'expand multiple props with the same keys' , ( ) => {
13
+ assert . deepEqual ( expandHash ( { 'foo.bar' : 'bar' , 'foo.baz' : 'baz' , 'beep.boop' : 'bop' , something : 'else' } ) , {
14
+ foo : { bar : 'bar' , baz : 'baz' } ,
15
+ beep : { boop : 'bop' } ,
16
+ something : 'else'
17
+ } ) ;
42
18
} ) ;
43
19
44
- it ( 'expand complex hash' , function ( done ) {
45
- var complex = { 'one.two.three.four.five' : 'bar' , bang : 'fez' } ;
46
- var expected = { one : { two : { three : { four : { five : 'bar' } } } } , bang : 'fez' } ;
47
- var actual = expandHash ( complex ) ;
48
- expect ( actual ) . to . eql ( expected ) ;
49
- done ( ) ;
20
+ it ( 'expand to deeply nested object' , ( ) => {
21
+ const complex = { 'one.two.three.four.five' : 'bar' , bang : 'fez' } ;
22
+ const expected = { one : { two : { three : { four : { five : 'bar' } } } } , bang : 'fez' } ;
23
+ const actual = expandHash ( complex ) ;
24
+ assert . deepEqual ( actual , expected ) ;
50
25
} ) ;
51
- } ) ;
52
26
53
- describe ( 'when keys are nested' , function ( ) {
54
- it ( 'should expand the prop strings into objects' , function ( done ) {
55
- var complex = { one : { 'two.three.four.five' : 'bar' } , bang : 'fez' } ;
56
- var expected = { one : { two : { three : { four : { five : 'bar' } } } } , bang : 'fez' } ;
57
- var actual = expandHash ( complex ) ;
58
- expect ( actual ) . to . eql ( expected ) ;
59
- done ( ) ;
60
- } ) ;
61
- } ) ;
27
+ it ( 'should expand nested keys into objects' , ( ) => {
28
+ assert . deepEqual ( expandHash ( { one : { 'two.three.four.five' : 'bar' } , bang : 'fez' } ) , {
29
+ one : { two : { three : { four : { five : 'bar' } } } } ,
30
+ bang : 'fez'
31
+ } ) ;
62
32
63
- describe ( 'when keys are nested' , function ( ) {
64
- it ( 'should expand the prop strings into objects' , function ( done ) {
65
- var complex = { a : [ 'b' , 'c' ] , one : { 'two.three.four.five' : 'bar' } , bang : 'fez' } ;
66
- var expected = { a : [ 'b' , 'c' ] , one : { two : { three : { four : { five : 'bar' } } } } , bang : 'fez' } ;
67
- var actual = expandHash ( complex ) ;
68
- expect ( actual ) . to . eql ( expected ) ;
69
- done ( ) ;
33
+ assert . deepEqual ( expandHash ( { a : [ 'b' , 'c' ] , one : { 'two.three.four.five' : 'bar' } , bang : 'fez' } ) , {
34
+ a : [ 'b' , 'c' ] ,
35
+ one : { two : { three : { four : { five : 'bar' } } } } ,
36
+ bang : 'fez'
37
+ } ) ;
70
38
} ) ;
71
- } ) ;
72
39
73
- describe ( 'when keys are nested' , function ( ) {
74
- it ( 'should expand the prop strings into objects' , function ( done ) {
75
- var complex = { a : [ 'b' , 'c' ] , one : { two : { three : { 'four.five' : 'bar' } } } , bang : 'fez' } ;
76
- var expected = { a : [ 'b' , 'c' ] , one : { two : { three : { four : { five : 'bar' } } } } , bang : 'fez' } ;
77
- var actual = expandHash ( complex ) ;
78
- expect ( actual ) . to . eql ( expected ) ;
79
- done ( ) ;
40
+ it ( 'should expand keys on object values into objects' , ( ) => {
41
+ assert . deepEqual ( expandHash ( { a : [ 'b' , 'c' ] , one : { two : { three : { 'four.five' : 'bar' } } } , bang : 'fez' } ) , {
42
+ a : [ 'b' , 'c' ] ,
43
+ one : { two : { three : { four : { five : 'bar' } } } } ,
44
+ bang : 'fez'
45
+ } ) ;
80
46
} ) ;
81
- } ) ;
82
-
83
47
84
- describe ( 'when keys are nested' , function ( ) {
85
- it ( 'should expand the prop strings into objects' , function ( done ) {
86
- var complex = { a : [ 'b' , 'c' ] , one : { two : { three : { four : { five : { six : { seven : { 'a.b.c.d.e.f.g' : 'Dante\'s ninth circle' } } } } } } } , bang : 'fez' } ;
87
- var expected = { a : [ 'b' , 'c' ] , one : { two : { three : { four : { five : { six : { seven : { a : { b : { c : { d : { e : { f : { g : 'Dante\'s ninth circle' } } } } } } } } } } } } } , bang : 'fez' } ;
88
- var actual = expandHash ( complex ) ;
89
- expect ( actual ) . to . eql ( expected ) ;
90
- done ( ) ;
48
+ it ( 'should expand keys in arrays into objects' , ( ) => {
49
+ assert . deepEqual ( expandHash ( { a : [ { 'a.b' : 'c' } , 'c' ] , one : { two : { three : { 'four.five' : 'bar' } } } , bang : 'fez' } ) , {
50
+ a : [ { a : { b : 'c' } } , 'c' ] ,
51
+ one : { two : { three : { four : { five : 'bar' } } } } ,
52
+ bang : 'fez'
53
+ } ) ;
91
54
} ) ;
92
55
} ) ;
93
-
94
- describe ( 'when the value is an object' , function ( ) {
95
- it ( 'should expand the prop strings into objects' , function ( done ) {
96
- var complex = { 'foo.bar' : { 'aaa' : 'bbbb' , 'ccc' : 'dddd' , 'eee' : 'ffff' } } ;
97
- var expected = { foo : { bar : { 'aaa' : 'bbbb' , 'ccc' : 'dddd' , 'eee' : 'ffff' } } } ;
98
- var actual = expandHash ( complex ) ;
99
- expect ( actual ) . to . eql ( expected ) ;
100
- done ( ) ;
101
- } ) ;
102
- } ) ;
0 commit comments