@@ -23,28 +23,54 @@ test('split_at', (t) => {
2323 t . deepEqual ( Functions . split_at ( '😀abélkm' , 4 ) . values , [ '😀abé' , 'lkm' ] ) ;
2424} ) ;
2525
26- //TODO: Fix these tests
27- /*test('map_to_object/1', (t) => {
28- const s_key = Symbol.for('key');
29- const s_anotherKey = Symbol.for('anotherKey');
30-
31- const map = new Map([[s_key, 'value'], [s_anotherKey, 'value2']]);
26+ test ( 'map_to_object/1' , ( t ) => {
27+ const map = new Map ( [ [ Symbol . for ( 'key' ) , 'value' ] , [ Symbol . for ( 'anotherKey' ) , 'value2' ] ] ) ;
3228 const result = Functions . map_to_object ( map ) ;
33- t.deepEqual(result, { s_key: 'value', s_anotherKey: 'value2' });
29+ const obj = { } ;
30+ obj [ Symbol . for ( 'key' ) ] = 'value' ;
31+ obj [ Symbol . for ( 'anotherKey' ) ] = 'value2' ;
32+ t . deepEqual ( result , obj ) ;
3433} ) ;
3534
3635test ( 'map_to_object/2' , ( t ) => {
37- const s_key = Symbol.for('key');
38- const s_anotherKey = Symbol.for('anotherKey');
39-
40- const map = new Map([[s_key, 'value'], [s_anotherKey, 'value2']]);
41- const options = [new Core.Tuple(Symbol.for('keys'), Symbol.for('strings'))];
36+ const map = new Map ( [ [ Symbol . for ( 'key' ) , 'value' ] , [ Symbol . for ( 'anotherKey' ) , 'value2' ] ] ) ;
37+ const options = [ new Core . Tuple ( Symbol . for ( 'keys' ) , Symbol . for ( 'string' ) ) ] ;
4238 const result = Functions . map_to_object ( map , options ) ;
4339
4440 t . deepEqual ( result , { key : 'value' , anotherKey : 'value2' } ) ;
41+ } ) ;
42+
43+ test ( 'object_to_map/1' , ( t ) => {
44+ let obj = { } ;
45+ let result = Functions . object_to_map ( obj ) ;
46+ t . deepEqual ( result , new Map ( ) ) ;
47+
48+ obj = { key : 'value' } ;
49+ result = Functions . object_to_map ( obj ) ;
50+ t . deepEqual ( result , new Map ( [ [ 'key' , 'value' ] ] ) ) ;
51+
52+ obj = { } ;
53+ obj [ Symbol . for ( 'key' ) ] = 'value' ;
54+ result = Functions . object_to_map ( obj ) ;
55+ t . deepEqual ( result , new Map ( [ [ Symbol . for ( 'key' ) , 'value' ] ] ) ) ;
56+ } ) ;
57+
58+ test ( 'object_to_map/2' , ( t ) => {
59+ let obj = { } ;
60+ let result = Functions . object_to_map ( obj , [ ] ) ;
61+ t . deepEqual ( result , new Map ( ) ) ;
4562
46- map = new Map([[s_key, 'value'], [s_anotherKey, 'value2']]);
47- result = Functions.map_to_object(map, []);
63+ obj = { key : 'value' } ;
64+ result = Functions . object_to_map ( obj , [ new Core . Tuple ( Symbol . for ( 'keys' ) , Symbol . for ( 'atom' ) ) ] ) ;
65+ t . deepEqual ( result , new Map ( [ [ Symbol . for ( 'key' ) , 'value' ] ] ) ) ;
4866
49- t.deepEqual(result, { s_key: 'value', s_anotherKey: 'value2' });
50- });*/
67+ obj = { } ;
68+ obj [ Symbol . for ( 'key' ) ] = [ { nest1 : 'valuenest1' } , { nest2 : 'valuenest2' } ] ;
69+ result = Functions . object_to_map ( obj , [
70+ new Core . Tuple ( Symbol . for ( 'keys' ) , Symbol . for ( 'atom' ) ) ,
71+ new Core . Tuple ( Symbol . for ( 'recurse_array' ) , true ) ] ) ;
72+ t . deepEqual ( result , new Map ( [ [ Symbol . for ( 'key' ) , [
73+ new Map ( [ [ Symbol . for ( 'nest1' ) , 'valuenest1' ] ] ) ,
74+ new Map ( [ [ Symbol . for ( 'nest2' ) , 'valuenest2' ] ] )
75+ ] ] ] ) ) ;
76+ } ) ;
0 commit comments