@@ -531,10 +531,10 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
531
531
) ;
532
532
}
533
533
534
- // GH- 1941
534
+ // https://github.com/nodejs/node-v0.x-archive/issues/ 1941
535
535
assert . strictEqual ( util . inspect ( Object . create ( Date . prototype ) ) , 'Date {}' ) ;
536
536
537
- // GH- 1944
537
+ // https://github.com/nodejs/node-v0.x-archive/issues/ 1944
538
538
{
539
539
const d = new Date ( ) ;
540
540
d . toUTCString = null ;
@@ -549,20 +549,20 @@ assert.strictEqual(util.inspect(Object.create(Date.prototype)), 'Date {}');
549
549
}
550
550
551
551
// Should not throw.
552
- const r = / r e g e x p / ;
553
- r . toString = null ;
554
- util . inspect ( r ) ;
555
-
556
- // Bug with user-supplied inspect function returns non-string.
557
- util . inspect ( [ { inspect : ( ) => 123 } ] ) ;
552
+ {
553
+ const r = / r e g e x p / ;
554
+ r . toString = null ;
555
+ util . inspect ( r ) ;
556
+ }
558
557
559
- // GH- 2225
558
+ // See https://github.com/nodejs/node-v0.x-archive/issues/ 2225
560
559
{
561
- const x = { inspect : util . inspect } ;
562
- assert . strictEqual ( util . inspect ( x ) . includes ( 'inspect' ) , true ) ;
560
+ const x = { [ util . inspect . custom ] : util . inspect } ;
561
+ assert ( util . inspect ( x ) . includes (
562
+ '[Symbol(util.inspect.custom)]: \n { [Function: inspect]' ) ) ;
563
563
}
564
564
565
- // util.inspect should display the escaped value of a key.
565
+ // ` util.inspect` should display the escaped value of a key.
566
566
{
567
567
const w = {
568
568
'\\' : 1 ,
@@ -660,8 +660,8 @@ util.inspect({ hasOwnProperty: null });
660
660
}
661
661
662
662
{
663
- // "customInspect" option can enable/disable calling inspect() on objects .
664
- const subject = { inspect : ( ) => 123 } ;
663
+ // "customInspect" option can enable/disable calling [util. inspect.custom]() .
664
+ const subject = { [ util . inspect . custom ] : ( ) => 123 } ;
665
665
666
666
assert . strictEqual (
667
667
util . inspect ( subject , { customInspect : true } ) . includes ( '123' ) ,
@@ -680,31 +680,6 @@ util.inspect({ hasOwnProperty: null });
680
680
true
681
681
) ;
682
682
683
- // Custom inspect() functions should be able to return other Objects.
684
- subject . inspect = ( ) => ( { foo : 'bar' } ) ;
685
-
686
- assert . strictEqual ( util . inspect ( subject ) , '{ foo: \'bar\' }' ) ;
687
-
688
- subject . inspect = ( depth , opts ) => {
689
- assert . strictEqual ( opts . customInspectOptions , true ) ;
690
- } ;
691
-
692
- util . inspect ( subject , { customInspectOptions : true } ) ;
693
- }
694
-
695
- {
696
- // "customInspect" option can enable/disable calling [util.inspect.custom]().
697
- const subject = { [ util . inspect . custom ] : ( ) => 123 } ;
698
-
699
- assert . strictEqual (
700
- util . inspect ( subject , { customInspect : true } ) . includes ( '123' ) ,
701
- true
702
- ) ;
703
- assert . strictEqual (
704
- util . inspect ( subject , { customInspect : false } ) . includes ( '123' ) ,
705
- false
706
- ) ;
707
-
708
683
// A custom [util.inspect.custom]() should be able to return other Objects.
709
684
subject [ util . inspect . custom ] = ( ) => ( { foo : 'bar' } ) ;
710
685
@@ -717,43 +692,16 @@ util.inspect({ hasOwnProperty: null });
717
692
util . inspect ( subject , { customInspectOptions : true } ) ;
718
693
}
719
694
720
- {
721
- // [util.inspect.custom] takes precedence over inspect.
722
- const subject = {
723
- [ util . inspect . custom ] ( ) { return 123 ; } ,
724
- inspect ( ) { return 456 ; }
725
- } ;
726
-
727
- assert . strictEqual (
728
- util . inspect ( subject , { customInspect : true } ) . includes ( '123' ) ,
729
- true
730
- ) ;
731
- assert . strictEqual (
732
- util . inspect ( subject , { customInspect : false } ) . includes ( '123' ) ,
733
- false
734
- ) ;
735
- assert . strictEqual (
736
- util . inspect ( subject , { customInspect : true } ) . includes ( '456' ) ,
737
- false
738
- ) ;
739
- assert . strictEqual (
740
- util . inspect ( subject , { customInspect : false } ) . includes ( '456' ) ,
741
- false
742
- ) ;
743
- }
744
-
745
695
{
746
696
// Returning `this` from a custom inspection function works.
747
- assert . strictEqual ( util . inspect ( { a : 123 , inspect ( ) { return this ; } } ) ,
748
- '{ a: 123, inspect: [Function: inspect] }' ) ;
749
-
750
697
const subject = { a : 123 , [ util . inspect . custom ] ( ) { return this ; } } ;
751
698
const UIC = 'util.inspect.custom' ;
752
699
assert . strictEqual ( util . inspect ( subject ) ,
753
700
`{ a: 123,\n [Symbol(${ UIC } )]: [Function: [${ UIC } ]] }` ) ;
754
701
}
755
702
756
- // util.inspect with "colors" option should produce as many lines as without it.
703
+ // Using `util.inspect` with "colors" option should produce as many lines as
704
+ // without it.
757
705
{
758
706
function testLines ( input ) {
759
707
const countLines = ( str ) => ( str . match ( / \n / g) || [ ] ) . length ;
@@ -1160,8 +1108,11 @@ util.inspect(process);
1160
1108
1161
1109
// Setting custom inspect property to a non-function should do nothing.
1162
1110
{
1163
- const obj = { inspect : 'fhqwhgads' } ;
1164
- assert . strictEqual ( util . inspect ( obj ) , "{ inspect: 'fhqwhgads' }" ) ;
1111
+ const obj = { [ util . inspect . custom ] : 'fhqwhgads' } ;
1112
+ assert . strictEqual (
1113
+ util . inspect ( obj ) ,
1114
+ "{ [Symbol(util.inspect.custom)]: 'fhqwhgads' }"
1115
+ ) ;
1165
1116
}
1166
1117
1167
1118
{
0 commit comments