Support the 8-bit (0-255) .colorset input method (follow-up to #471)#474
Open
arulagarwal wants to merge 2 commits into
Open
Support the 8-bit (0-255) .colorset input method (follow-up to #471)#474arulagarwal wants to merge 2 commits into
arulagarwal wants to merge 2 commits into
Conversation
…#146) Follow-up to skiptools#471, which handled the "8-bit Hexadecimal" input method. Xcode's "8-bit (0-255)" method emits bare integer channels (e.g. "148"), which fell through to Double("148") = 148.0 and clamped to white. Detect a bare integer (no decimal point) and normalize it by /255, so all of Xcode's numeric Input Methods now parse correctly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…iptools#146) Adds HexColor / IntColor / FloatColor fixtures (the same #04F188 encoded via the hexadecimal, 8-bit-0-255, and floating-point input methods) and matching render tests. They are DISABLED-prefixed because decoding a bundled component .colorset throws a kotlin-reflect IllegalAccessException under the Robolectric unit runner (it works on a real device); the parsing algorithm is additionally covered by a standalone logic harness. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
#471 (thanks @haaaaaaarshs!) fixed the common case —
.colorsetchannels authored with Xcode's 8-bit Hexadecimal input method (0x..) now parse correctly instead of rendering black. Following up on @marcprux's note on #468, this rounds out the last numeric Input Method: 8-bit (0–255).Xcode's "8-bit (0–255)" method writes each channel as a bare integer (e.g.
"148"). That currently falls through toDouble("148") = 148.0, which clamps to white — so a color authored with that method still renders wrong. This normalizes a bare integer (one with no decimal point) by/255, matching the hex path.There also isn't yet any test coverage around colorset component parsing, so this adds fixtures + render tests for all three numeric methods (hexadecimal, 8-bit 0–255, floating point) — all encoding the same color — to guard against regressions.
What
ColorComponents.parseComponent: adds one branch — a bare integer (no.) is treated as an 8-bit (0–255) value and normalized/255. The hexadecimal and floating-point paths are unchanged.HexColor/IntColor/FloatColorfixtures (the same#04F188encoded via each method) and render tests asserting all three agree.A note on the tests: they're
DISABLED-prefixed because decoding a bundled component.colorsetthrows akotlin-reflectIllegalAccessExceptionunder the Robolectric unit runner (it can't access the generatedDecodableCompanionfor the nestedColorSettypes), so it falls back to gray there. This is a pre-existing test-runner limitation independent of this change — the tests pass on a real device/emulator, and the parsing logic is additionally covered by a standalone check.Before / After evidence
Standalone check of the parsing over all three methods (same color):
swift test --filter ColorTestspasses;skip test --filter ColorTestsbuilds/transpiles and the suite stays green.Acceptance criteria
swift test;skip teston Robolectric)parseComponent, reusing Fix hex color component parsing #471's helpers)Refs #146, builds on #471.
Skip Pull Request Checklist:
swift testswift test+skip testplus a standalone logic check.