You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$result."date-upperO-should-parse-as-datetime".ToString("d") | Should -Be "9/22/2008"
405
+
$result."date-upperO-should-parse-as-datetime".ToString("D") | Should -Be "Monday, September 22, 2008"
406
+
$result."date-upperO-should-parse-as-datetime".ToString("f") | Should -Be "Monday, September 22, 2008 2:01 PM"
407
+
$result."date-upperO-should-parse-as-datetime".ToString("F") | Should -Be "Monday, September 22, 2008 2:01:54 PM"
408
+
$result."date-upperO-should-parse-as-datetime".ToString("g") | Should -Be "9/22/2008 2:01 PM"
409
+
$result."date-upperO-should-parse-as-datetime".ToString("G") | Should -Be "9/22/2008 2:01:54 PM"
410
+
$result."date-upperO-should-parse-as-datetime".ToString("m") | Should -Be "September 22"
411
+
$result."date-upperO-should-parse-as-datetime".ToString("M") | Should -Be "September 22"
412
+
$result."date-upperO-should-parse-as-datetime".ToString("o") | Should -Be "2008-09-22T14:01:54.9571247Z"
413
+
$result."date-upperO-should-parse-as-datetime".ToString("O") | Should -Be "2008-09-22T14:01:54.9571247Z"
414
+
$result."date-upperO-should-parse-as-datetime".ToString("R") | Should -Be "Mon, 22 Sep 2008 14:01:54 GMT"
415
+
$result."date-upperO-should-parse-as-datetime".ToString("s") | Should -Be "2008-09-22T14:01:54"
416
+
$result."date-upperO-should-parse-as-datetime".ToString("t") | Should -Be "2:01 PM"
417
+
$result."date-upperO-should-parse-as-datetime".ToString("T") | Should -Be "2:01:54 PM"
418
+
$result."date-upperO-should-parse-as-datetime".ToString("u") | Should -Be "2008-09-22 14:01:54Z"
419
+
$result."date-upperO-should-parse-as-datetime".ToString("U") | Should -Be "Monday, September 22, 2008 2:01:54 PM"
420
+
$result."date-upperO-should-parse-as-datetime".ToString("Y") | Should -Be "September 2008"
421
+
$result."date-upperO-should-parse-as-datetime".ToString("y") | Should -Be "September 2008"
422
+
$result."date-upperO-should-parse-as-datetime"| Should -BeOfType [DateTime]
423
+
424
+
$result."date-o-should-parse-as-string"| Should -Be "2019-12-17T06:14:06 +06:00"
425
+
$result."date-o-should-parse-as-string"| Should -BeOfType [String]
426
+
$result."date-f-should-parse-as-string"| Should -Be "Monday, September 22, 2008 2:01 PM"
427
+
$result."date-f-should-parse-as-string"| Should -BeOfType [String]
428
+
$result."date-g-should-parse-as-string"| Should -Be "9/22/2008 2:01 PM"
429
+
$result."date-g-should-parse-as-string"| Should -BeOfType [String]
430
+
$result."date-m-should-parse-as-string"| Should -Be "September 22"
431
+
$result."date-m-should-parse-as-string"| Should -BeOfType [String]
432
+
$result."date-upperM-should-parse-as-string"| Should -Be "September 22"
433
+
$result."date-upperM-should-parse-as-string"| Should -BeOfType [String]
434
+
$result."date-t-should-parse-as-string"| Should -Be "2:01 PM"
435
+
$result."date-t-should-parse-as-string"| Should -BeOfType [String]
436
+
$result."date-u-should-parse-as-string"| Should -Be "2008-09-22 14:01:54Z"
437
+
$result."date-u-should-parse-as-string"| Should -BeOfType [String]
438
+
$result."date-upperD-should-parse-as-string"| Should -Be "Monday, September 22, 2008"
439
+
$result."date-upperD-should-parse-as-string"| Should -BeOfType [String]
440
+
$result."date-upperF-should-parse-as-string"| Should -Be "Monday, September 22, 2008 2:01:54 PM"
441
+
$result."date-upperF-should-parse-as-string"| Should -BeOfType [String]
442
+
$result."date-upperG-should-parse-as-string"| Should -Be "9/22/2008 2:01:54 PM"
443
+
$result."date-upperG-should-parse-as-string"| Should -BeOfType [String]
444
+
$result."date-upperR-should-parse-as-string"| Should -Be "Mon, 22 Sep 2008 14:01:54 GMT"
445
+
$result."date-upperR-should-parse-as-string"| Should -BeOfType [String]
446
+
$result."date-upperT-should-parse-as-string"| Should -Be "2:01:54 PM"
447
+
$result."date-upperT-should-parse-as-string"| Should -BeOfType [String]
448
+
$result."date-upperU-should-parse-as-string"| Should -Be "Monday, September 22, 2008 2:01:54 PM"
449
+
$result."date-upperU-should-parse-as-string"| Should -BeOfType [String]
450
+
$result."date-upperY-should-parse-as-string"| Should -Be "September 2008"
451
+
$result."date-upperY-should-parse-as-string"| Should -BeOfType [String]
452
+
$result."date-y-should-parse-as-string"| Should -Be "September 2008"
453
+
$result."date-y-should-parse-as-string"| Should -BeOfType [String]
454
+
}
455
+
}
456
+
457
+
It "ConvertFrom-Json properly parses complex objects" {
458
+
$json=@"
459
+
{
460
+
"_id": "60dd3ea9253016932039a0a2",
461
+
"index": 0,
462
+
"guid": "429b96a7-24e3-47de-a93b-f44a346c5ac9",
463
+
"isActive": false,
464
+
"balance": "$2,039.72",
465
+
"picture": "http://placehold.it/32x32",
466
+
"age": 35,
467
+
"eyeColor": "green",
468
+
"name": "Rhodes Roberson",
469
+
"gender": "male",
470
+
"company": "INSECTUS",
471
+
"email": "rhodesroberson@insectus.com",
472
+
"phone": "+1 (883) 561-3999",
473
+
"address": "931 Kings Place, Hartsville/Hartley, Federated States Of Micronesia, 9344",
474
+
"about": "Ipsum pariatur nisi eiusmod aliquip in cupidatat. Deserunt non sit anim consectetur consectetur incididunt elit qui id proident nostrud. Consectetur pariatur et adipisicing aliquip fugiat fugiat Lorem reprehenderit laboris magna. Duis veniam irure amet ex minim eiusmod et laborum non elit. Dolor enim Lorem occaecat nisi consectetur mollit laborum anim velit et. Irure aliquip eiusmod anim proident ex ea duis deserunt aute amet adipisicing nisi nostrud. Minim ipsum fugiat consequat mollit fugiat tempor fugiat.",
475
+
"registered": "2019-12-17T06:14:06 +06:00",
476
+
"latitude": 51.890798,
477
+
"longitude": -47.522764,
478
+
"tags": [
479
+
"laboris",
480
+
"voluptate",
481
+
"amet",
482
+
"ad",
483
+
"velit",
484
+
"ipsum",
485
+
"do"
486
+
],
487
+
"friends": [
488
+
{
489
+
"id": 0,
490
+
"name": "Renee Holden"
491
+
},
492
+
{
493
+
"id": 1,
494
+
"name": "Bennett Dixon"
495
+
},
496
+
{
497
+
"id": 2,
498
+
"name": "Emilia Holder"
499
+
}
500
+
],
501
+
"greeting": "Hello, Rhodes Roberson! You have 9 unread messages.",
502
+
"favoriteFruit": "banana"
503
+
}
504
+
"@
505
+
$result=ConvertFrom-Json$Json
506
+
$result."about"| Should -BeExactly "Ipsum pariatur nisi eiusmod aliquip in cupidatat. Deserunt non sit anim consectetur consectetur incididunt elit qui id proident nostrud. Consectetur pariatur et adipisicing aliquip fugiat fugiat Lorem reprehenderit laboris magna. Duis veniam irure amet ex minim eiusmod et laborum non elit. Dolor enim Lorem occaecat nisi consectetur mollit laborum anim velit et. Irure aliquip eiusmod anim proident ex ea duis deserunt aute amet adipisicing nisi nostrud. Minim ipsum fugiat consequat mollit fugiat tempor fugiat."
507
+
$result."about"| Should -BeOfType [String]
508
+
$result."address"| Should -BeExactly "931 Kings Place, Hartsville/Hartley, Federated States Of Micronesia, 9344"
509
+
$result."address"| Should -BeOfType [String]
510
+
$result."age"| Should -BeOfType [Int64]
511
+
$result."balance"| Should -BeExactly ",039.72"
512
+
$result."balance"| Should -BeOfType [String]
513
+
$result."company"| Should -BeExactly "INSECTUS"
514
+
$result."company"| Should -BeOfType [String]
515
+
$result."email"| Should -BeExactly "rhodesroberson@insectus.com"
516
+
$result."email"| Should -BeOfType [String]
517
+
$result."eyeColor"| Should -BeExactly "green"
518
+
$result."eyeColor"| Should -BeOfType [String]
519
+
$result."favoriteFruit"| Should -BeExactly "banana"
520
+
$result."favoriteFruit"| Should -BeOfType [String]
521
+
$result."gender"| Should -BeExactly "male"
522
+
$result."gender"| Should -BeOfType [String]
523
+
$result."greeting"| Should -BeExactly "Hello, Rhodes Roberson! You have 9 unread messages."
524
+
$result."greeting"| Should -BeOfType [String]
525
+
$result."guid"| Should -BeExactly "429b96a7-24e3-47de-a93b-f44a346c5ac9"
526
+
$result."guid"| Should -BeOfType [String]
527
+
$result."index"| Should -BeOfType [Int64]
528
+
$result."isActive"| Should -Be False
529
+
$result."isActive"| Should -BeOfType [Boolean]
530
+
$result."latitude"| Should -Be 51.890798
531
+
$result."latitude"| Should -BeOfType [Double]
532
+
$result."longitude"| Should -Be -47.522764
533
+
$result."longitude"| Should -BeOfType [Double]
534
+
$result."name"| Should -BeExactly "Rhodes Roberson"
535
+
$result."name"| Should -BeOfType [String]
536
+
$result."phone"| Should -BeExactly "+1 (883) 561-3999"
537
+
$result."phone"| Should -BeOfType [String]
538
+
$result."picture"| Should -BeExactly "http://placehold.it/32x32"
539
+
$result."picture"| Should -BeOfType [String]
540
+
$result."registered"| Should -BeExactly "2019-12-17T06:14:06 +06:00"
541
+
$result."registered"| Should -BeOfType [String]
542
+
$result."_id"| Should -BeExactly "60dd3ea9253016932039a0a2"
543
+
$result."_id"| Should -BeOfType [String]
544
+
545
+
$result.Tags| Should -BeOfType [string]
546
+
547
+
$result.Tags.count| Should -Be 7
548
+
$result.Tags[0] | Should -BeExactly "laboris"
549
+
$result.Tags| Should -Be @("laboris","voluptate","amet","ad","velit","ipsum","do")
550
+
551
+
$result.Friends| Should -BeOfType [pscustomobject]
552
+
$result.Friends[0].id | Should -Be 0
553
+
$result.Friends[0].name | Should -BeExactly "Renee Holden"
554
+
$result.Friends[1].id | Should -Be 1
555
+
$result.Friends[1].name | Should -BeExactly "Bennett Dixon"
556
+
$result.Friends[2].id | Should -Be 2
557
+
$result.Friends[2].name | Should -BeExactly "Emilia Holder"
558
+
}
559
+
560
+
It "ConvertFrom-Json chooses the appropriate number type" {
561
+
ConvertFrom-Json-InputObject "5"| should -Be 5
562
+
ConvertFrom-Json-InputObject 5| should -Be 5
563
+
ConvertFrom-Json-InputObject "5"| should -BeOfType [int64]
564
+
ConvertFrom-Json-InputObject 5| should -BeOfType [int64]
565
+
ConvertFrom-Json-InputObject 5000000000000| should -Be 5000000000000
566
+
ConvertFrom-Json-InputObject "5000000000000"| should -Be "5000000000000"
567
+
ConvertFrom-Json-InputObject "5000000000000"| should -BeOfType [int64]
568
+
ConvertFrom-Json-InputObject 5000000000000| should -BeOfType [int64]
569
+
ConvertFrom-Json-InputObject "5.0"| should -Be 5.0
570
+
ConvertFrom-Json-InputObject 5.0| should -Be 5.0
571
+
ConvertFrom-Json-InputObject "5.0"| should -BeOfType [double]
572
+
ConvertFrom-Json-InputObject 5.0| should -BeOfType [double]
573
+
574
+
# The decimal is lost but only when this is quoted
575
+
ConvertFrom-Json-InputObject "500000000000.0000000000000001"| should -Be "500000000000"
576
+
577
+
# Counter intuitively all four of these tests pass because precision is lost on both sides of the test, likely due to powershell number handling
578
+
ConvertFrom-Json-InputObject 500000000000.0000000000000001| should -Be 500000000000
579
+
ConvertFrom-Json-InputObject 500000000000.0000000000000001| should -Be 500000000000.0000000000000001
580
+
ConvertFrom-Json-InputObject 500000000000| should -Be 500000000000.0000000000000001
581
+
ConvertFrom-Json-InputObject 500000000000| should -Be 500000000000
582
+
583
+
ConvertFrom-Json-InputObject "500000000000.0000000000000001"| should -BeOfType [double]
584
+
ConvertFrom-Json-InputObject 500000000000.0000000000000001| should -BeOfType [double]
585
+
586
+
# these tests also pass because precision is lost during conversion/powershell handling
587
+
ConvertFrom-Json-InputObject "50000000000000000000000000000000000.0000000000000001"| should -Be "5E+34"
588
+
ConvertFrom-Json-InputObject 50000000000000000000000000000000000.0000000000000001| should -Be "5E+34"
589
+
590
+
ConvertFrom-Json-InputObject "50000000000000000000000000000000000.0000000000000001"| should -BeOfType [double]
591
+
ConvertFrom-Json-InputObject 50000000000000000000000000000000000.0000000000000001| should -BeOfType [double]
592
+
593
+
594
+
ConvertFrom-Json-InputObject "50000000000000000000000000000000000"| should -Be 50000000000000000000000000000000000
595
+
ConvertFrom-Json-InputObject 50000000000000000000000000000000000| should -Be 50000000000000000000000000000000000
596
+
ConvertFrom-Json-InputObject "50000000000000000000000000000000000"| should -BeOfType [BigInt]
597
+
ConvertFrom-Json-InputObject 50000000000000000000000000000000000| should -BeOfType [BigInt]
0 commit comments