# Contributing to zig-collate Issues and pull requests go to the Tangled mirror, . ## Getting set up The development shell has everything the build and its checks need — Zig 0.17, `reuse`, ICU for the oracle — so work inside it: ```console $ git clone https://git.jcollie.dev/jeff/zig-collate.git $ cd zig-collate $ nix develop ``` The Unicode data files the tables are generated from are committed in `data/`, so a first build needs no network beyond the Zig dependencies in `build.zig.zon`. The README's "The Unicode data" section says why. ## Before sending a change Every one of these runs in CI, and a change should pass all of them: ```console $ reuse lint $ zig fmt --exclude zig-pkg --check . $ zig build test --summary all $ zig build test-conformance $ zig build check ``` `zig build check` compiles every tool without running it, so that one nothing else builds cannot quietly stop compiling. If the change touches tailorings, the CLDR root or the repertoire option, run the configurations CI does as well: ```console $ zig build test -Dembed-cldr -Dlocales=sv,tr,pl,cs,fi,lt,hu,es,ar,yi,hr,br,ja $ zig build test-conformance-cldr -Dembed-cldr $ zig build test -Dembed-cldr -Dlocales=sv,ja \ -Drepertoire='Basic Latin,Latin-1 Supplement,Latin Extended-A,General Punctuation,Combining Diacritical Marks,Greek and Coptic,Cyrillic' ``` `-Dembed-cldr` and `-Dlocales` fetch the CLDR archive, which is 66 MB. For a change to the algorithm itself, `zig build fuzz -- 20000` runs the property checks in `tests/fuzz.zig`, and `zig build oracle -Dembed-cldr` and `zig build oracle-search -Dembed-cldr` compare the results against ICU. A change that makes the library faster or slower should say by how much, from `zig build bench -Dembed-cldr`. ## Tests Tests sit at the bottom of the file they test, named by what they establish rather than by the function they call: `"a contraction is never split"`, not `"test find"`. Where a test comes from the specification, its comment says which section or table. Every public function also has a **doctest**: a test named after the function, written directly beneath it, which the API documentation shows as that function's example. ```zig pub fn isStarter(cp: u21) bool { return combiningClass(cp) == 0; } test isStarter { try std.testing.expect(isStarter('e')); try std.testing.expect(!isStarter(0x0301)); } ``` A new public function gets one. Keep it short and self-contained, since it is read on its own in the documentation: no helpers from the rest of the test file, and a `Tailoring` written out in full rather than borrowed. When it expects a weight, quote the `allkeys.txt` line the weight comes from. A doctest inside a type is compiled only when something refers to the type. The test blocks in `src/root.zig` and `src/data.zig` call `refAllDecls` on every file so that nothing is missed; a new source file needs adding there. **Mind the restricted repertoire.** CI builds a table that covers only Basic Latin, Latin-1 Supplement, Latin Extended-A, General Punctuation, Combining Diacritical Marks, Greek and Cyrillic, and runs the whole suite against it. A test reading table entries outside those blocks skips itself unless the table has them — see `inRepertoire` in `src/collator.zig` and `have` in `src/search.zig`. A doctest should stay inside the blocks and not need to skip. ## Documentation The API documentation is generated from the doc comments and published from `main` to . Those comments carry most of the explanation, so they are held to the same standard as the code: - A `///` comment documents the declaration directly beneath it. Put any comment that explains a *neighboring* declaration on that one instead, since anything else is shown under the wrong name. - Say which part of UTS #10 or UTS #35 a piece of code implements, and why it is done this way when the obvious way was tried and failed. - `zig build docs-serve` serves the result at to check how it reads. It has to be served rather than opened as a file. Design decisions that were hard to reverse are recorded as ADRs in `docs/adr/`, and the project's vocabulary is in `GLOSSARY.md`. Use the glossary's terms, and add one there when a change introduces a concept. ## Unicode and CLDR data `tools/update-ducet.sh [version]` refreshes the Unicode files in `data/`. Their Unicode version has to match the one the `uucode` dependency ships, since step 1 reads one and step 2 the other; `zig build test-conformance` is what notices a mismatch. The CLDR version is the `cldr` dependency in `build.zig.zon`, along with the `allkeys_CLDR` and `FractionalUCA_radicals` files in `data/`, which have to come from the same release. ## Licensing The project is MIT licensed and follows [REUSE](https://reuse.software/). Every new file needs an SPDX header like the ones already in the tree, or an entry in `REUSE.toml` if it cannot hold one. `reuse lint` checks this.