Repository navigation
Commit af89643
committed
fix: Keep the trailing zeros of a floatstring range element
Review on #342 pointed out that the string form of a <FloatRangeList> element
exists in order to carry the scale it was written with: a range element written
'2.50' is asking for `2.50` on a command line, and a renderer handed `2.5`
instead has been given a different string. It is also the only way a template
can ask for a fixed number of decimal places, because a <float> literal of 2.50
is the same literal as 2.5 once parsed. #342 normalized the element to the number
it denotes and threw that away.
Split the two kinds of zero, which are not the same thing:
- Leading zeros are not part of the number and still go. '02' on an INT range
is the task value 2, and forwarding the text renders `--frame 02`.
- Trailing zeros are the author's chosen scale and are kept. '02.50' renders
`2.50`, not `2.5`.
The already-landed conformance fixture EXPR/jobs/expr1.3.4--float-passthrough
pins the same rule for a FLOAT parameter default, so both it and
base/jobs/3.4.1.2 can now be right at once. openjd-specifications#180 states the
rule as Template Schemas §7.5.
A <floatstring> therefore renders as its own text less any redundant leading
zeros, which is a substring operation rather than a numeric one. That is what
removes the machinery the two preceding commits added, because every problem
they were solving came from having to choose a notation in which to re-render a
Decimal:
- normalize() and quantize() round to getcontext().prec, so an embedding
application's decimal context changed what this library rendered: measured,
'1.2345678901234567890123456789012345678901' came back as '1.2346' under
getcontext().prec = 5.
- str(Decimal) switches to exponent notation once the adjusted exponent falls
below -6, so '0.0000001' rendered 1E-7.
- format(value, 'f') is exact and plain at every magnitude but unbounded in the
exponent, so '1e999999999' -- 11 characters of template text -- expanded to
~10**9 characters and needed a length bound to stay safe.
Text needs none of those decisions. '1e999999999' now costs its own 11
characters, so the exponent bound and its boundary cases are gone with it, and an
element can no longer silently exceed TaskParameterStringValueAsJob's
1024-character cap and fall through to a numeric member of the union.
An <intstring> is unaffected: int() already discards leading zeros and there are
no fractional digits to preserve.
Verification. Model suite 5527 -> 5529 passed, 24 skipped, 3 xfailed; ruff, black
and mypy clean at the CI-pinned versions. Three mutants confirm the tests pin
both halves of the rule: dropping the leading-zero strip fails 7 tests,
restoring the trailing-zero strip fails 7, and dropping the int() conversion
fails 3.
Full 2023-09 conformance suite, run from source against openjd-cli mainline
7c7ece4 with openjd-sessions 0.10.14, on openjd-specifications#180's tree: 1162
passed, 0 failed. The baseline at e7a17b3 passes 1161 and fails only
base/jobs/7.5--numeric-string-zeros-in-range-elements, so this closes that one
fixture and moves nothing else. Both controls hold --
base/jobs/3.4--float-parameter and EXPR/jobs/expr1.3.4--float-passthrough.
Relative to released 0.11.6 the only behaviour change here is the leading-zero
trim: every element whose rendering differs from 0.11.6 differs by a removed
leading zero.
openjd-rs, which backs this package's `openjd.model._v1` API, needs the matching
change; that is OpenJobDescription/openjd-rs#354. With both in place the two
implementations render every range-element case tested identically, including
the zero and exponent forms.
Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>1 parent e7a17b3 commit af89643
3 files changed
Lines changed: 68 additions & 153 deletions
File tree
- src/openjd/model/v2023_09
- test/openjd/model_v0
- v2023_09
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1245 | 1245 | | |
1246 | 1246 | | |
1247 | 1247 | | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
1248 | 1253 | | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
1254 | 1260 | | |
1255 | 1261 | | |
1256 | | - | |
1257 | | - | |
1258 | | - | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
1262 | | - | |
1263 | | - | |
1264 | | - | |
1265 | | - | |
1266 | | - | |
1267 | | - | |
1268 | | - | |
1269 | | - | |
1270 | | - | |
1271 | | - | |
1272 | | - | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | | - | |
1279 | | - | |
1280 | | - | |
1281 | | - | |
1282 | | - | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
1296 | | - | |
1297 | | - | |
1298 | | - | |
1299 | | - | |
1300 | | - | |
1301 | | - | |
1302 | | - | |
1303 | | - | |
1304 | | - | |
1305 | | - | |
1306 | | - | |
1307 | | - | |
1308 | | - | |
1309 | | - | |
1310 | | - | |
1311 | | - | |
1312 | | - | |
1313 | | - | |
1314 | | - | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
1315 | 1269 | | |
| 1270 | + | |
1316 | 1271 | | |
1317 | 1272 | | |
1318 | 1273 | | |
| |||
1327 | 1282 | | |
1328 | 1283 | | |
1329 | 1284 | | |
1330 | | - | |
1331 | | - | |
1332 | | - | |
1333 | | - | |
1334 | | - | |
1335 | | - | |
1336 | | - | |
1337 | | - | |
1338 | | - | |
1339 | | - | |
1340 | | - | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
1341 | 1289 | | |
1342 | | - | |
1343 | | - | |
1344 | | - | |
1345 | | - | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
1346 | 1293 | | |
1347 | 1294 | | |
1348 | 1295 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
613 | 613 | | |
614 | 614 | | |
615 | 615 | | |
616 | | - | |
617 | | - | |
| 616 | + | |
| 617 | + | |
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
441 | 441 | | |
442 | 442 | | |
443 | 443 | | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
451 | 450 | | |
452 | 451 | | |
453 | 452 | | |
| |||
471 | 470 | | |
472 | 471 | | |
473 | 472 | | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
483 | 486 | | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
500 | 494 | | |
501 | 495 | | |
502 | 496 | | |
503 | | - | |
| 497 | + | |
504 | 498 | | |
505 | 499 | | |
506 | 500 | | |
507 | | - | |
| 501 | + | |
508 | 502 | | |
509 | 503 | | |
510 | 504 | | |
511 | 505 | | |
512 | 506 | | |
513 | | - | |
| 507 | + | |
514 | 508 | | |
515 | 509 | | |
516 | 510 | | |
517 | 511 | | |
518 | 512 | | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | 513 | | |
523 | 514 | | |
524 | | - | |
525 | | - | |
526 | | - | |
| 515 | + | |
| 516 | + | |
527 | 517 | | |
528 | 518 | | |
529 | | - | |
530 | | - | |
531 | | - | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
532 | 522 | | |
533 | 523 | | |
534 | 524 | | |
535 | 525 | | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
541 | 529 | | |
542 | 530 | | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
| 531 | + | |
564 | 532 | | |
565 | 533 | | |
566 | 534 | | |
| |||
573 | 541 | | |
574 | 542 | | |
575 | 543 | | |
576 | | - | |
577 | | - | |
| 544 | + | |
| 545 | + | |
578 | 546 | | |
579 | 547 | | |
580 | 548 | | |
| |||
0 commit comments