@@ -526,7 +526,53 @@ public void Specifying_an_option_argument_overrides_the_default_value()
526
526
527
527
value . Should ( ) . Be ( 456 ) ;
528
528
}
529
-
529
+
530
+
531
+ [ Fact ]
532
+ public void Values_can_be_correctly_converted_to_DateTime_without_the_parser_specifying_a_custom_converter ( )
533
+ {
534
+ var option = new Option < DateTime > ( "-x" ) ;
535
+
536
+ var dateString = "2022-02-06T01:46:03.0000000-08:00" ;
537
+ var value = option . Parse ( $ "-x { dateString } ") . GetValueForOption ( option ) ;
538
+
539
+ value . Should ( ) . Be ( DateTime . Parse ( dateString ) ) ;
540
+ }
541
+
542
+
543
+ [ Fact ]
544
+ public void Values_can_be_correctly_converted_to_nullable_DateTime_without_the_parser_specifying_a_custom_converter ( )
545
+ {
546
+ var option = new Option < DateTime ? > ( "-x" ) ;
547
+
548
+ var dateString = "2022-02-06T01:46:03.0000000-08:00" ;
549
+ var value = option . Parse ( $ "-x { dateString } ") . GetValueForOption ( option ) ;
550
+
551
+ value . Should ( ) . Be ( DateTime . Parse ( dateString ) ) ;
552
+ }
553
+
554
+ [ Fact ]
555
+ public void Values_can_be_correctly_converted_to_DateTimeOffset_without_the_parser_specifying_a_custom_converter ( )
556
+ {
557
+ var option = new Option < DateTimeOffset > ( "-x" ) ;
558
+
559
+ var dateString = "2022-02-06T09:52:54.5275055-08:00" ;
560
+ var value = option . Parse ( $ "-x { dateString } ") . GetValueForOption ( option ) ;
561
+
562
+ value . Should ( ) . Be ( DateTime . Parse ( dateString ) ) ;
563
+ }
564
+
565
+ [ Fact ]
566
+ public void Values_can_be_correctly_converted_to_nullable_DateTimeOffset_without_the_parser_specifying_a_custom_converter ( )
567
+ {
568
+ var option = new Option < DateTimeOffset ? > ( "-x" ) ;
569
+
570
+ var dateString = "2022-02-06T09:52:54.5275055-08:00" ;
571
+ var value = option . Parse ( $ "-x { dateString } ") . GetValueForOption ( option ) ;
572
+
573
+ value . Should ( ) . Be ( DateTime . Parse ( dateString ) ) ;
574
+ }
575
+
530
576
[ Fact ]
531
577
public void Values_can_be_correctly_converted_to_decimal_without_the_parser_specifying_a_custom_converter ( )
532
578
{
@@ -536,6 +582,16 @@ public void Values_can_be_correctly_converted_to_decimal_without_the_parser_spec
536
582
537
583
value . Should ( ) . Be ( 123.456m ) ;
538
584
}
585
+
586
+ [ Fact ]
587
+ public void Values_can_be_correctly_converted_to_nullable_decimal_without_the_parser_specifying_a_custom_converter ( )
588
+ {
589
+ var option = new Option ( "-x" , arity : ArgumentArity . ZeroOrOne ) ;
590
+
591
+ var value = option . Parse ( "-x 123.456" ) . GetValueForOption < decimal ? > ( option ) ;
592
+
593
+ value . Should ( ) . Be ( 123.456m ) ;
594
+ }
539
595
540
596
[ Fact ]
541
597
public void Values_can_be_correctly_converted_to_double_without_the_parser_specifying_a_custom_converter ( )
@@ -546,6 +602,36 @@ public void Values_can_be_correctly_converted_to_double_without_the_parser_speci
546
602
547
603
value . Should ( ) . Be ( 123.456d ) ;
548
604
}
605
+
606
+ [ Fact ]
607
+ public void Values_can_be_correctly_converted_to_nullable_double_without_the_parser_specifying_a_custom_converter ( )
608
+ {
609
+ var option = new Option ( "-x" , arity : ArgumentArity . ZeroOrOne ) ;
610
+
611
+ var value = option . Parse ( "-x 123.456" ) . GetValueForOption < double ? > ( option ) ;
612
+
613
+ value . Should ( ) . Be ( 123.456d ) ;
614
+ }
615
+
616
+ [ Fact ]
617
+ public void Values_can_be_correctly_converted_to_float_without_the_parser_specifying_a_custom_converter ( )
618
+ {
619
+ var option = new Option < float > ( "-x" ) ;
620
+
621
+ var value = option . Parse ( "-x 123.456" ) . GetValueForOption ( option ) ;
622
+
623
+ value . Should ( ) . Be ( 123.456f ) ;
624
+ }
625
+
626
+ [ Fact ]
627
+ public void Values_can_be_correctly_converted_to_nullable_float_without_the_parser_specifying_a_custom_converter ( )
628
+ {
629
+ var option = new Option < float ? > ( "-x" ) ;
630
+
631
+ var value = option . Parse ( "-x 123.456" ) . GetValueForOption ( option ) ;
632
+
633
+ value . Should ( ) . Be ( 123.456f ) ;
634
+ }
549
635
550
636
[ Fact ]
551
637
public void Values_can_be_correctly_converted_to_Uri_without_the_parser_specifying_a_custom_converter ( )
@@ -574,6 +660,28 @@ public void Options_with_arguments_specified_can_be_correctly_converted_to_bool_
574
660
option . Parse ( "-x true" ) . GetValueForOption < bool > ( option ) . Should ( ) . BeTrue ( ) ;
575
661
}
576
662
663
+
664
+ [ Fact ]
665
+ public void Values_can_be_correctly_converted_to_long_without_the_parser_specifying_a_custom_converter ( )
666
+ {
667
+ var option = new Option < long > ( "-x" ) ;
668
+
669
+ var value = option . Parse ( "-x 123456790" ) . GetValueForOption ( option ) ;
670
+
671
+ value . Should ( ) . Be ( 123456790L ) ;
672
+ }
673
+
674
+ [ Fact ]
675
+ public void Values_can_be_correctly_converted_to_nullable_long_without_the_parser_specifying_a_custom_converter ( )
676
+ {
677
+ var option = new Option < long ? > ( "-x" ) ;
678
+
679
+ var value = option . Parse ( "-x 1234567890" ) . GetValueForOption ( option ) ;
680
+
681
+ value . Should ( ) . Be ( 1234567890L ) ;
682
+ }
683
+
684
+
577
685
[ Fact ]
578
686
public void Values_can_be_correctly_converted_to_array_of_int_without_the_parser_specifying_a_custom_converter ( )
579
687
{
0 commit comments