@@ -256,7 +256,7 @@ test.each([
256256 { array : [ 0 , 2 , 4 , 8 ] , predicate : "false" } ,
257257] ) ( "array.find (%p)" , ( { array, predicate } ) => {
258258 util . testFunction `
259- const array = ${ util . valueToString ( array ) } ;
259+ const array = ${ util . formatCode ( array ) } ;
260260 return array.find((elem, index, arr) => ${ predicate } && arr[index] === elem);
261261 ` . expectToMatchJsResult ( ) ;
262262} ) ;
@@ -268,7 +268,7 @@ test.each([
268268 { array : [ 0 , 2 , 4 , 8 ] , searchElement : 8 } ,
269269] ) ( "array.findIndex (%p)" , ( { array, searchElement } ) => {
270270 util . testFunction `
271- const array = ${ util . valueToString ( array ) } ;
271+ const array = ${ util . formatCode ( array ) } ;
272272 return array.findIndex((elem, index, arr) => elem === ${ searchElement } && arr[index] === elem);
273273 ` . expectToMatchJsResult ( ) ;
274274} ) ;
@@ -281,7 +281,7 @@ test.each([
281281 { array : [ 0 , 1 , 2 , 3 ] , func : "x => x+2" } ,
282282 { array : [ 0 , 1 , 2 , 3 ] , func : "x => x%2 == 0 ? x + 1 : x - 1" } ,
283283] ) ( "array.map (%p)" , ( { array, func } ) => {
284- util . testExpression `${ util . valueToString ( array ) } .map(${ func } )` . expectToMatchJsResult ( ) ;
284+ util . testExpression `${ util . formatCode ( array ) } .map(${ func } )` . expectToMatchJsResult ( ) ;
285285} ) ;
286286
287287test . each ( [
@@ -293,7 +293,7 @@ test.each([
293293 { array : [ 0 , 1 , 2 , 3 ] , func : "() => true" } ,
294294 { array : [ 0 , 1 , 2 , 3 ] , func : "() => false" } ,
295295] ) ( "array.filter (%p)" , ( { array, func } ) => {
296- util . testExpression `${ util . valueToString ( array ) } .filter(${ func } )` . expectToMatchJsResult ( ) ;
296+ util . testExpression `${ util . formatCode ( array ) } .filter(${ func } )` . expectToMatchJsResult ( ) ;
297297} ) ;
298298
299299test . each ( [
@@ -302,7 +302,7 @@ test.each([
302302 { array : [ false , true , false ] , func : "x => x" } ,
303303 { array : [ true , true , true ] , func : "x => x" } ,
304304] ) ( "array.every (%p)" , ( { array, func } ) => {
305- util . testExpression `${ util . valueToString ( array ) } .every(${ func } )` . expectToMatchJsResult ( ) ;
305+ util . testExpression `${ util . formatCode ( array ) } .every(${ func } )` . expectToMatchJsResult ( ) ;
306306} ) ;
307307
308308test . each ( [
@@ -311,7 +311,7 @@ test.each([
311311 { array : [ false , true , false ] , func : "x => x" } ,
312312 { array : [ true , true , true ] , func : "x => x" } ,
313313] ) ( "array.some (%p)" , ( { array, func } ) => {
314- util . testExpression `${ util . valueToString ( array ) } .some(${ func } )` . expectToMatchJsResult ( ) ;
314+ util . testExpression `${ util . formatCode ( array ) } .some(${ func } )` . expectToMatchJsResult ( ) ;
315315} ) ;
316316
317317test . each ( [
@@ -324,7 +324,8 @@ test.each([
324324 { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , args : [ 1 , 3 ] } ,
325325 { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , args : [ 3 ] } ,
326326] ) ( "array.slice (%p)" , ( { array, args } ) => {
327- util . testExpression `${ util . valueToString ( array ) } .slice(${ util . valuesToString ( args ) } )` . expectToMatchJsResult ( ) ;
327+ const argumentString = util . formatCode ( ...args ) ;
328+ util . testExpression `${ util . formatCode ( array ) } .slice(${ argumentString } )` . expectToMatchJsResult ( ) ;
328329} ) ;
329330
330331test . each ( [
@@ -338,26 +339,37 @@ test.each([
338339 { array : [ 0 , 1 , 2 , 3 ] , start : - 3 , deleteCount : 0 , newElements : [ 8 , 9 ] } ,
339340 { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , start : 5 , deleteCount : 9 , newElements : [ 10 , 11 ] } ,
340341 { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , start : 3 , deleteCount : 2 , newElements : [ 3 , 4 , 5 ] } ,
342+ { array : [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] , start : 5 , deleteCount : 9 , newElements : [ 10 , 11 ] } ,
343+ { array : [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] , start : 5 , deleteCount : undefined , newElements : [ 10 , 11 ] } ,
344+ // tslint:disable-next-line:no-null-keyword
345+ { array : [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] , start : 5 , deleteCount : null , newElements : [ 10 , 11 ] } ,
341346
342347 // Remove
343348 { array : [ ] , start : 1 , deleteCount : 1 } ,
344349 { array : [ 0 , 1 , 2 , 3 ] , start : 1 , deleteCount : 1 } ,
345350 { array : [ 0 , 1 , 2 , 3 ] , start : 10 , deleteCount : 1 } ,
346- { array : [ 0 , 1 , 2 , 3 ] , start : 1 , deleteCount : undefined } ,
347- { array : [ 0 , 1 , 2 , 3 ] , start : 4 } ,
348- { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , start : 3 } ,
349- { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , start : - 3 } ,
350- { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , start : - 2 } ,
351351 { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , start : 2 , deleteCount : 2 } ,
352- { array : [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] , start : 5 , deleteCount : 9 , newElements : [ 10 , 11 ] } ,
352+ { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , start : - 3 , deleteCount : 2 } ,
353+ { array : [ 0 , 1 , 2 , 3 ] , start : 1 , deleteCount : undefined } ,
354+ // tslint:disable-next-line:no-null-keyword
355+ { array : [ 0 , 1 , 2 , 3 ] , start : 1 , deleteCount : null } ,
353356] ) ( "array.splice (%p)" , ( { array, start, deleteCount, newElements = [ ] } ) => {
354357 util . testFunction `
355- const array = ${ util . valueToString ( array ) } ;
356- array.splice(${ util . valuesToString ( [ start , deleteCount , ...newElements ] ) } );
358+ const array = ${ util . formatCode ( array ) } ;
359+ array.splice(${ util . formatCode ( start , deleteCount , ...newElements ) } );
357360 return array;
358361 ` . expectToMatchJsResult ( ) ;
359362} ) ;
360363
364+ test . each ( [
365+ { array : [ 0 , 1 , 2 , 3 ] , start : 4 } ,
366+ { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , start : 3 } ,
367+ { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , start : - 3 } ,
368+ { array : [ 0 , 1 , 2 , 3 , 4 , 5 ] , start : - 2 } ,
369+ ] ) ( "array.splice no delete argument" , ( { array, start } ) => {
370+ util . testExpression `${ util . formatCode ( array ) } .splice(${ start } )` . expectToMatchJsResult ( ) ;
371+ } ) ;
372+
361373test . each ( [
362374 { array : [ ] , args : [ [ ] ] } ,
363375 { array : [ 1 , 2 , 3 ] , args : [ [ ] ] } ,
@@ -371,8 +383,8 @@ test.each([
371383 { array : [ 1 , 2 , "test" ] , args : [ "test" , [ "test1" , "test2" ] ] } ,
372384] ) ( "array.concat (%p)" , ( { array, args } ) => {
373385 util . testFunction `
374- const array: any[] = ${ util . valueToString ( array ) } ;
375- return array.concat(${ util . valuesToString ( args ) } );
386+ const array: any[] = ${ util . formatCode ( array ) } ;
387+ return array.concat(${ util . formatCode ( ... args ) } );
376388 ` . expectToMatchJsResult ( ) ;
377389} ) ;
378390
@@ -383,7 +395,11 @@ test.each([
383395 { array : [ "test1" , "test2" ] , separator : ";" } ,
384396 { array : [ "test1" , "test2" ] , separator : "" } ,
385397] ) ( "array.join (%p)" , ( { array, separator } ) => {
386- util . testExpression `${ util . valueToString ( array ) } .join(${ util . valueToString ( separator ) } )` . expectToMatchJsResult ( ) ;
398+ util . testExpression `${ util . formatCode ( array ) } .join(${ util . formatCode ( separator ) } )` . expectToMatchJsResult ( ) ;
399+ } ) ;
400+
401+ test ( "array.join without separator argument" , ( ) => {
402+ util . testExpression `["test1", "test2"].join()` . expectToMatchJsResult ( ) ;
387403} ) ;
388404
389405test . each ( [
@@ -395,13 +411,13 @@ test.each([
395411 { array : [ "test1" , "test2" , "test3" ] , args : [ "test1" , - 2 ] } ,
396412 { array : [ "test1" , "test2" , "test3" ] , args : [ "test1" , 12 ] } ,
397413] ) ( "array.indexOf (%p)" , ( { array, args } ) => {
398- util . testExpression `${ util . valueToString ( array ) } .indexOf(${ util . valuesToString ( args ) } )` . expectToMatchJsResult ( ) ;
414+ util . testExpression `${ util . formatCode ( array ) } .indexOf(${ util . formatCode ( ... args ) } )` . expectToMatchJsResult ( ) ;
399415} ) ;
400416
401417test . each ( [ { args : [ 1 ] } , { args : [ 1 , 2 , 3 ] } ] ) ( "array.push (%p)" , ( { args } ) => {
402418 util . testFunction `
403419 const array = [0];
404- const value = array.push(${ util . valuesToString ( args ) } );
420+ const value = array.push(${ util . formatCode ( ... args ) } );
405421 return { array, value };
406422 ` . expectToMatchJsResult ( ) ;
407423} ) ;
@@ -411,7 +427,7 @@ test.each([{ array: [1, 2, 3], expected: [3, 2] }, { array: [1, 2, 3, null], exp
411427 "array.pop (%p)" ,
412428 ( { array, expected } ) => {
413429 util . testFunction `
414- const array = ${ util . valueToString ( array ) } ;
430+ const array = ${ util . formatCode ( array ) } ;
415431 const value = array.pop();
416432 return [value, array.length];
417433 ` . expectToEqual ( expected ) ;
@@ -422,7 +438,7 @@ test.each([{ array: [1, 2, 3] }, { array: [1, 2, 3, 4] }, { array: [1] }, { arra
422438 "array.reverse (%p)" ,
423439 ( { array } ) => {
424440 util . testFunction `
425- const array = ${ util . valueToString ( array ) } ;
441+ const array = ${ util . formatCode ( array ) } ;
426442 array.reverse();
427443 return array;
428444 ` . expectToMatchJsResult ( ) ;
@@ -431,7 +447,7 @@ test.each([{ array: [1, 2, 3] }, { array: [1, 2, 3, 4] }, { array: [1] }, { arra
431447
432448test . each ( [ { array : [ 1 , 2 , 3 ] } , { array : [ 1 ] } , { array : [ ] } ] ) ( "array.shift (%p)" , ( { array } ) => {
433449 util . testFunction `
434- const array = ${ util . valueToString ( array ) } ;
450+ const array = ${ util . formatCode ( array ) } ;
435451 const value = array.shift();
436452 return { array, value };
437453 ` . expectToMatchJsResult ( ) ;
@@ -444,8 +460,8 @@ test.each([
444460 { array : [ ] , args : [ 1 ] } ,
445461] ) ( "array.unshift (%p)" , ( { array, args } ) => {
446462 util . testFunction `
447- const array = ${ util . valueToString ( array ) } ;
448- const value = array.unshift(${ util . valuesToString ( args ) } );
463+ const array = ${ util . formatCode ( array ) } ;
464+ const value = array.unshift(${ util . formatCode ( ... args ) } );
449465 return { array, value };
450466 ` . expectToMatchJsResult ( ) ;
451467} ) ;
@@ -499,7 +515,7 @@ test.each<[[(total: number, currentItem: number, index: number, array: number[])
499515 [ [ ( total , _ , index , array ) => total + array [ index ] ] ] ,
500516 [ [ ( a , b ) => a + b ] ] ,
501517] ) ( "array.reduce (%p)" , args => {
502- util . testExpression `[1, 3, 5, 7].reduce(${ util . valuesToString ( args ) } )` . expectToMatchJsResult ( ) ;
518+ util . testExpression `[1, 3, 5, 7].reduce(${ util . formatCode ( ... args ) } )` . expectToMatchJsResult ( ) ;
503519} ) ;
504520
505521test ( "array.reduce empty undefined initial" , ( ) => {
0 commit comments