@@ -160,7 +160,7 @@ Deno.test({
160
160
fn : ( ) => {
161
161
const actual = vimStringify ( {
162
162
foo : 42 ,
163
- toJSON : ( ) => JSON . stringify ( [ 123 , "bar" ] ) ,
163
+ toJSON : ( ) => [ 123 , "bar" ] ,
164
164
} ) ;
165
165
assertEquals ( actual , "[123,'bar']" ) ;
166
166
} ,
@@ -171,12 +171,20 @@ Deno.test({
171
171
const actual = vimStringify ( Object . assign (
172
172
( ) => { } ,
173
173
{
174
- toJSON : ( ) => JSON . stringify ( [ 123 , "bar" ] ) ,
174
+ toJSON : ( ) => [ 123 , "bar" ] ,
175
175
} ,
176
176
) ) ;
177
177
assertEquals ( actual , "[123,'bar']" ) ;
178
178
} ,
179
179
} ) ;
180
+ await t . step ( {
181
+ name : "stringify Date that has native `toJSON()` method." ,
182
+ fn : ( ) => {
183
+ // NOTE: `Date.prototype.toJSON` returns a string representing date in the same ISO format as `Date.prototype.toISOString()`.
184
+ const actual = vimStringify ( new Date ( "2007-08-31T12:34:56.000Z" ) ) ;
185
+ assertEquals ( actual , "'2007-08-31T12:34:56.000Z'" ) ;
186
+ } ,
187
+ } ) ;
180
188
await t . step ( {
181
189
name : "raises TypeError if specified BigInt." ,
182
190
fn : ( ) => {
@@ -197,7 +205,7 @@ Deno.test({
197
205
} ) ;
198
206
try {
199
207
const actual = vimStringify ( 92382417n ) ;
200
- assertEquals ( actual , "92382417" ) ;
208
+ assertEquals ( actual , "' 92382417' " ) ;
201
209
} finally {
202
210
// deno-lint-ignore no-explicit-any
203
211
delete ( BigInt . prototype as any ) . toJSON ;
@@ -216,8 +224,9 @@ Deno.test({
216
224
Symbol ( "foo" ) ,
217
225
"bar" ,
218
226
{
219
- toJSON : ( ) => JSON . stringify ( [ 123 , "baz" ] ) ,
227
+ toJSON : ( ) => [ 123 , "baz" ] ,
220
228
} ,
229
+ new Date ( "2007-08-31T12:34:56.000Z" ) ,
221
230
{
222
231
k0 : null ,
223
232
k1 : undefined ,
@@ -232,7 +241,7 @@ Deno.test({
232
241
] ) ;
233
242
assertEquals (
234
243
actual ,
235
- `[v:null,v:null,42,v:true,v:null,v:null,'bar',[123,'baz'],{'k0':v:null,'k2':[{'key':234,'expr':"\\U0001F680"}]}]` ,
244
+ `[v:null,v:null,42,v:true,v:null,v:null,'bar',[123,'baz'],'2007-08-31T12:34:56.000Z', {'k0':v:null,'k2':[{'key':234,'expr':"\\U0001F680"}]}]` ,
236
245
) ;
237
246
} ,
238
247
} ) ;
@@ -419,8 +428,9 @@ test({
419
428
Symbol ( "foo" ) ,
420
429
"bar" ,
421
430
{
422
- toJSON : ( ) => JSON . stringify ( [ 123 , "baz" ] ) ,
431
+ toJSON : ( ) => [ 123 , "baz" ] ,
423
432
} ,
433
+ new Date ( "2007-08-31T12:34:56.000Z" ) ,
424
434
{
425
435
k0 : null ,
426
436
k1 : undefined ,
@@ -448,6 +458,7 @@ test({
448
458
123 ,
449
459
"baz" ,
450
460
] ,
461
+ "2007-08-31T12:34:56.000Z" ,
451
462
{
452
463
k0 : null ,
453
464
k2 : [
0 commit comments