Repository navigation
Commit 3bc3f4b
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. Normalizing the element to the number
it denotes 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 fixtures can now be right at once.
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.
- str(Decimal) switches to exponent notation below 1e-6, so '0.0000001'
rendered 1E-7.
- format(value, 'f') is exact and plain 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.
Conformance, run by file path against a venv built from this branch:
base/jobs/3.4.1.1--int-range-intstring-elements-normalized passes, and
base/jobs/3.4.1.2--float-range-floatstring-elements-normalized now emits
`W:2.50` from '02.50'. That fixture asserts `W:2.5` and passes only because the
runner matches substrings; openjd-specifications#179 carries it and is being
corrected. The two controls this must not move -- a FLOAT `default: "3.500"`
rendering 3.500, and <float> numeric literals [1.0, 2.5] rendering 1.0 and 2.5
-- both hold.
Note that openjd-rs, which backs this package's `openjd.model._v1` API, still
normalizes trailing zeros away: it stores a FLOAT range as Vec<f64>, so
'02.50' renders 2.5 there. A matching fix is in flight.
Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>1 parent e7a17b3 commit 3bc3f4b
3 files changed
Lines changed: 86 additions & 132 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 | + | |
| 1253 | + | |
| 1254 | + | |
1248 | 1255 | | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
1254 | 1265 | | |
1255 | 1266 | | |
| 1267 | + | |
| 1268 | + | |
1256 | 1269 | | |
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 | | - | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
1312 | 1281 | | |
1313 | 1282 | | |
1314 | 1283 | | |
1315 | 1284 | | |
| 1285 | + | |
1316 | 1286 | | |
1317 | 1287 | | |
1318 | 1288 | | |
| |||
1330 | 1300 | | |
1331 | 1301 | | |
1332 | 1302 | | |
1333 | | - | |
1334 | | - | |
1335 | | - | |
1336 | | - | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
1337 | 1312 | | |
1338 | 1313 | | |
1339 | 1314 | | |
| |||
| 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 | 621 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
451 | 458 | | |
452 | 459 | | |
453 | 460 | | |
| |||
471 | 478 | | |
472 | 479 | | |
473 | 480 | | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
483 | 494 | | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
500 | 502 | | |
501 | 503 | | |
502 | 504 | | |
503 | | - | |
| 505 | + | |
504 | 506 | | |
505 | 507 | | |
506 | 508 | | |
507 | | - | |
| 509 | + | |
508 | 510 | | |
509 | 511 | | |
510 | 512 | | |
511 | 513 | | |
512 | 514 | | |
513 | | - | |
| 515 | + | |
514 | 516 | | |
515 | 517 | | |
516 | 518 | | |
517 | 519 | | |
518 | 520 | | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | 521 | | |
523 | 522 | | |
524 | | - | |
525 | | - | |
526 | | - | |
| 523 | + | |
| 524 | + | |
527 | 525 | | |
528 | 526 | | |
529 | | - | |
| 527 | + | |
530 | 528 | | |
531 | | - | |
| 529 | + | |
| 530 | + | |
532 | 531 | | |
533 | 532 | | |
534 | 533 | | |
535 | 534 | | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
541 | 539 | | |
542 | 540 | | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
| 541 | + | |
564 | 542 | | |
565 | 543 | | |
566 | 544 | | |
| |||
0 commit comments