Repository navigation
Replace code generation with hand-kept constants and JSON test data - #348
Merged
Merged
Conversation
A Python generator for sixteen arrays that change only when a built-in space arrives cost the build a second language and CI a step of its own. ColorConstantsDerivationTest recomputes every derived literal in exact fractions and fails on a one-ulp difference, printing the list to paste. The matrices CSS publishes are checked against its printed text, and against the whites they must carry, to within 6e-16.
It rendered correctly but read as a jumble in the source; README's tables are padded, and this one now is too.
A rename on its own, so history follows the file through the rewrite that makes it export JSON instead of writing Kotlin.
The WPT lists and the color.js vectors lived in Kotlin files that a script wrote as string literals and listOf tables, one of them ported by a script that was never committed. They are now two JSON files under commonTest/resources: export.mjs writes them with JSON.stringify, and the tests read them through kotlinx-resources and decode them into @serializable classes, on JVM, Android host, wasm and iOS alike. Every case carries over unchanged: 206 valid colors, 25 color() templates, 405 invalid texts and 348 conversions from WPT, 1,000 conversions and 400 Okhsl/Okhsv colors from color.js. export.mjs also fails on a failed fetch or an empty list, where it used to write empty data that passed.
NAMED_COLORS was tested for its size and two entries only. export.mjs now takes the named-color table from CSS Color 4's Bikeshed source at the 2026-09-13 Editor's Draft, checking each row's hex against its decimal, and the test holds the library's table to it exactly: every name with its value, none missing, none extra, and each one parsing to that color. WPT's computed named-color list could not serve as the reference: it leaves out rebeccapurple.
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.
Builds on #347. Nothing in the repository writes Kotlin any more.
tools/generate_color_constants.pyand its CI step are gone;ColorConstants.ktis edited by hand.ColorConstantsDerivationTest(JVM) derives the whites, the sRGB and Display P3 matrices, their inverses and the four LMS shortcuts in exact fractions and requires each literal to be the nearest double, bit for bit, printing the list to paste on failure. The Bradford and Oklab matrices are checked against CSS Color 4's printed text and against the whites they must carry, within 1e-15 (they hold to 5.7e-16).listOftables written by a script. They are now JSON undercolor/src/commonTest/resources/reference/, read through kotlinx-resources and decoded strictly into@Serializableclasses on JVM, Android host, wasm and iOS.tools/reference/export.mjs(renamed fromgenerate.mjs) writes them withJSON.stringifyand fails on a failed fetch or an empty list. Every case carries over unchanged: 206 valid colors, 25color()templates, 405 invalid texts and 348 conversions from WPT; 1,000 conversions and 400 Okhsl/Okhsv colors from color.js.NAMED_COLORSis checked against the named-color table in CSS Color 4's own source, pinned at the 2026-09-13 Editor's Draft: every name with its value, none missing, none extra.toColorValue's KDoc is aligned in the source.New test-only dependencies: kotlinx-serialization-json 1.11.0 and kotlinx-resources 0.16.2.
A literal moved by one ulp, a changed or misspelled named color, and a broken case in either JSON file each fail the tests; the broken JSON fails on JVM, Android host and wasm alike. Tests: color 171 JVM, 162 Android host, 162 wasm;
apiCheckclean.