Commit fe86128
committed
fix: align format numeric edge cases with Python rules
Motivation:
Jsonnet documents std.format and the % string operator as following Python-style formatting rules. sjsonnet diverged on several numeric edge cases: floating-point formats did not preserve the IEEE -0.0 sign bit, dynamic * width/precision accepted fractional values via truncation, and %g exponent selection was sensitive to floating-point log10 roundoff.
Modification:
Normalize dynamic * width and precision through a shared Python-style integer conversion path, including negative width and negative precision handling. Preserve -0.0 signs for floating-point conversions, keep integral conversions unchanged, and stabilize %g exponent calculation around powers of ten. Add focused regression coverage for negative zero, dynamic * width/precision, fractional * errors, and %g boundary values.
Result:
sjsonnet follows the official std.format Python-style contract for these numeric formatting edge cases. The PR is format-only and no longer includes unrelated manifestXmlJsonml changes.
References:
https://jsonnet.org/ref/stdlib.html#std-format1 parent e686d89 commit fe86128
8 files changed
Lines changed: 140 additions & 18 deletions
File tree
- sjsonnet
- src/sjsonnet
- test/resources/new_test_suite
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
97 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
98 | 112 | | |
| 113 | + | |
99 | 114 | | |
100 | 115 | | |
101 | | - | |
| 116 | + | |
| 117 | + | |
102 | 118 | | |
103 | 119 | | |
104 | 120 | | |
| |||
645 | 661 | | |
646 | 662 | | |
647 | 663 | | |
648 | | - | |
| 664 | + | |
649 | 665 | | |
650 | 666 | | |
651 | 667 | | |
| |||
655 | 671 | | |
656 | 672 | | |
657 | 673 | | |
658 | | - | |
| 674 | + | |
659 | 675 | | |
660 | 676 | | |
661 | 677 | | |
| |||
672 | 688 | | |
673 | 689 | | |
674 | 690 | | |
675 | | - | |
| 691 | + | |
| 692 | + | |
676 | 693 | | |
677 | 694 | | |
678 | 695 | | |
| |||
984 | 1001 | | |
985 | 1002 | | |
986 | 1003 | | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
987 | 1037 | | |
988 | 1038 | | |
989 | 1039 | | |
990 | 1040 | | |
991 | 1041 | | |
992 | 1042 | | |
993 | 1043 | | |
994 | | - | |
| 1044 | + | |
995 | 1045 | | |
996 | 1046 | | |
997 | 1047 | | |
| |||
1002 | 1052 | | |
1003 | 1053 | | |
1004 | 1054 | | |
1005 | | - | |
| 1055 | + | |
1006 | 1056 | | |
1007 | 1057 | | |
1008 | 1058 | | |
| |||
1055 | 1105 | | |
1056 | 1106 | | |
1057 | 1107 | | |
1058 | | - | |
| 1108 | + | |
1059 | 1109 | | |
1060 | 1110 | | |
1061 | | - | |
| 1111 | + | |
1062 | 1112 | | |
1063 | 1113 | | |
1064 | 1114 | | |
| |||
1069 | 1119 | | |
1070 | 1120 | | |
1071 | 1121 | | |
1072 | | - | |
| 1122 | + | |
1073 | 1123 | | |
1074 | 1124 | | |
1075 | 1125 | | |
| |||
1080 | 1130 | | |
1081 | 1131 | | |
1082 | 1132 | | |
1083 | | - | |
| 1133 | + | |
1084 | 1134 | | |
1085 | 1135 | | |
1086 | | - | |
| 1136 | + | |
1087 | 1137 | | |
1088 | 1138 | | |
1089 | | - | |
| 1139 | + | |
1090 | 1140 | | |
1091 | 1141 | | |
1092 | 1142 | | |
| |||
1097 | 1147 | | |
1098 | 1148 | | |
1099 | 1149 | | |
1100 | | - | |
| 1150 | + | |
1101 | 1151 | | |
1102 | 1152 | | |
1103 | 1153 | | |
| |||
1106 | 1156 | | |
1107 | 1157 | | |
1108 | 1158 | | |
1109 | | - | |
| 1159 | + | |
1110 | 1160 | | |
1111 | 1161 | | |
1112 | 1162 | | |
| |||
1117 | 1167 | | |
1118 | 1168 | | |
1119 | 1169 | | |
1120 | | - | |
| 1170 | + | |
1121 | 1171 | | |
1122 | 1172 | | |
1123 | 1173 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 57 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
0 commit comments