@@ -537,6 +537,14 @@ func TestStringFormat(t *testing.T) {
537
537
expectedRuntimeCost : 13 ,
538
538
expectedEstimatedCost : checker.CostEstimate {Min : 13 , Max : 13 },
539
539
},
540
+ {
541
+ name : "negative binary formatting clause" ,
542
+ format : "this is -5 in binary: %b" ,
543
+ formatArgs : "-5" ,
544
+ expectedOutput : "this is -5 in binary: -101" ,
545
+ expectedRuntimeCost : 13 ,
546
+ expectedEstimatedCost : checker.CostEstimate {Min : 13 , Max : 13 },
547
+ },
540
548
{
541
549
name : "uint support for binary formatting" ,
542
550
format : "unsigned 64 in binary: %b" ,
@@ -561,6 +569,14 @@ func TestStringFormat(t *testing.T) {
561
569
expectedRuntimeCost : 11 ,
562
570
expectedEstimatedCost : checker.CostEstimate {Min : 11 , Max : 11 },
563
571
},
572
+ {
573
+ name : "negative octal formatting clause" ,
574
+ format : "%o" ,
575
+ formatArgs : "-11" ,
576
+ expectedOutput : "-13" ,
577
+ expectedRuntimeCost : 11 ,
578
+ expectedEstimatedCost : checker.CostEstimate {Min : 11 , Max : 11 },
579
+ },
564
580
{
565
581
name : "uint support for octal formatting clause" ,
566
582
format : "this is an unsigned octal: %o" ,
@@ -571,9 +587,9 @@ func TestStringFormat(t *testing.T) {
571
587
},
572
588
{
573
589
name : "lowercase hexadecimal formatting clause" ,
574
- format : "%x is 20 in hexadecimal" ,
590
+ format : "%x is 30 in hexadecimal" ,
575
591
formatArgs : "30" ,
576
- expectedOutput : "1e is 20 in hexadecimal" ,
592
+ expectedOutput : "1e is 30 in hexadecimal" ,
577
593
expectedRuntimeCost : 13 ,
578
594
expectedEstimatedCost : checker.CostEstimate {Min : 13 , Max : 13 },
579
595
},
@@ -585,6 +601,14 @@ func TestStringFormat(t *testing.T) {
585
601
expectedRuntimeCost : 13 ,
586
602
expectedEstimatedCost : checker.CostEstimate {Min : 13 , Max : 13 },
587
603
},
604
+ {
605
+ name : "negative hexadecimal formatting clause" ,
606
+ format : "%x is -30 in hexadecimal" ,
607
+ formatArgs : "-30" ,
608
+ expectedOutput : "-1e is -30 in hexadecimal" ,
609
+ expectedRuntimeCost : 13 ,
610
+ expectedEstimatedCost : checker.CostEstimate {Min : 13 , Max : 13 },
611
+ },
588
612
{
589
613
name : "unsigned support for hexadecimal formatting clause" ,
590
614
format : "%X is 6000 in hexadecimal" ,
@@ -617,6 +641,14 @@ func TestStringFormat(t *testing.T) {
617
641
expectedRuntimeCost : 11 ,
618
642
expectedEstimatedCost : checker.CostEstimate {Min : 11 , Max : 11 },
619
643
},
644
+ {
645
+ name : "byte support with hexadecimal formatting clause leading zero" ,
646
+ format : "%x" ,
647
+ formatArgs : `b"\x00\x00byte string\x00"` ,
648
+ expectedOutput : "00006279746520737472696e6700" ,
649
+ expectedRuntimeCost : 11 ,
650
+ expectedEstimatedCost : checker.CostEstimate {Min : 11 , Max : 11 },
651
+ },
620
652
{
621
653
name : "byte support with uppercase hexadecimal formatting clause" ,
622
654
format : "%X" ,
@@ -661,6 +693,42 @@ func TestStringFormat(t *testing.T) {
661
693
expectedEstimatedCost : checker.CostEstimate {Min : 11 , Max : 11 },
662
694
locale : "en_US" ,
663
695
},
696
+ {
697
+ name : "default precision for string" ,
698
+ format : "%s" ,
699
+ formatArgs : "2.71" ,
700
+ expectedOutput : "2.71" ,
701
+ expectedRuntimeCost : 11 ,
702
+ expectedEstimatedCost : checker.CostEstimate {Min : 11 , Max : 11 },
703
+ locale : "en_US" ,
704
+ },
705
+ {
706
+ name : "default list precision for string" ,
707
+ format : "%s" ,
708
+ formatArgs : "[2.71]" ,
709
+ expectedOutput : "[2.710000]" ,
710
+ expectedRuntimeCost : 21 ,
711
+ expectedEstimatedCost : checker.CostEstimate {Min : 21 , Max : 21 },
712
+ locale : "en_US" ,
713
+ },
714
+ {
715
+ name : "default scientific notation for string" ,
716
+ format : "%s" ,
717
+ formatArgs : "0.000000002" ,
718
+ expectedOutput : "2e-09" ,
719
+ expectedRuntimeCost : 11 ,
720
+ expectedEstimatedCost : checker.CostEstimate {Min : 11 , Max : 11 },
721
+ locale : "en_US" ,
722
+ },
723
+ {
724
+ name : "default list scientific notation for string" ,
725
+ format : "%s" ,
726
+ formatArgs : "[0.000000002]" ,
727
+ expectedOutput : "[0.000000]" ,
728
+ expectedRuntimeCost : 21 ,
729
+ expectedEstimatedCost : checker.CostEstimate {Min : 21 , Max : 21 },
730
+ locale : "en_US" ,
731
+ },
664
732
{
665
733
name : "unicode output for scientific notation" ,
666
734
format : "unescaped unicode: %e, escaped unicode: %e" ,
@@ -697,6 +765,30 @@ func TestStringFormat(t *testing.T) {
697
765
expectedEstimatedCost : checker.CostEstimate {Min : 11 , Max : 11 },
698
766
locale : "en_US" ,
699
767
},
768
+ {
769
+ name : "NaN support for string" ,
770
+ format : "%s" ,
771
+ formatArgs : `double("NaN")` ,
772
+ expectedOutput : "NaN" ,
773
+ },
774
+ {
775
+ name : "positive infinity support for string" ,
776
+ format : "%s" ,
777
+ formatArgs : `double("Inf")` ,
778
+ expectedOutput : "+Inf" ,
779
+ },
780
+ {
781
+ name : "negative infinity support for string" ,
782
+ format : "%s" ,
783
+ formatArgs : `double("-Inf")` ,
784
+ expectedOutput : "-Inf" ,
785
+ },
786
+ {
787
+ name : "infinity list support for string" ,
788
+ format : "%s" ,
789
+ formatArgs : `[double("NaN"),double("+Inf"), double("-Inf")]` ,
790
+ expectedOutput : `["NaN", "+Inf", "-Inf"]` ,
791
+ },
700
792
{
701
793
name : "uint support for decimal clause" ,
702
794
format : "%d" ,
@@ -753,6 +845,14 @@ func TestStringFormat(t *testing.T) {
753
845
expectedRuntimeCost : 12 ,
754
846
expectedEstimatedCost : checker.CostEstimate {Min : 12 , Max : 12 },
755
847
},
848
+ {
849
+ name : "small duration support for string" ,
850
+ format : "%s" ,
851
+ formatArgs : `duration("2ns")` ,
852
+ expectedOutput : "0.000000002s" ,
853
+ expectedRuntimeCost : 12 ,
854
+ expectedEstimatedCost : checker.CostEstimate {Min : 12 , Max : 12 },
855
+ },
756
856
{
757
857
name : "list support for string" ,
758
858
format : "%s" ,
0 commit comments