typst/tests
frozolotl b0e81d4b3f
Remove restrictions to chroma and improve clamping (#2690)
This PR does a few small things:
- Oklab's a*/b* and Oklch's chroma components can be as large as desired.
- In PDF, when encoding Oklab, the range is widened from [-0.4,0.4] to [-0.5,0.5].
- In PDF, clamping is now performed on Oklch's chroma instead of a* and b*.
  This causes hue not to be distorted when clamping.

SVG and PNG export remain unchanged:
- SVG itself never had any restrictions on chroma.
  We directly use the `oklab` and `oklch` CSS colors, which should work fine for the most part.
  In the future, embedded ICC profiles might be nice. Further research is likely necessary.
- While PNG does not support color spaces like Oklab or Oklch, certain useful features exist.
  One can define gamma (gAMA) and chromacities&whitepoint (cHRM) chunks and even embed ICC profiles.
  While `image` crate does not support these features for encoding, its backend crate `png` does support gAMA and cHRM.
  It does not allow embedding ICC profiles yet, though.

As it stands, to fully support wide gamuts and more accurate colors, more work is necessary.
This PR should help a bit though.
2023-11-17 10:41:45 +01:00
..
packages Allow packages to specify their minimum compiler version 2023-09-04 16:29:57 +02:00
ref Remove restrictions to chroma and improve clamping (#2690) 2023-11-17 10:41:45 +01:00
src Move some things out of util 2023-11-08 23:42:45 +01:00
typ Remove restrictions to chroma and improve clamping (#2690) 2023-11-17 10:41:45 +01:00
Cargo.toml Extract typst-pdf crate 2023-11-08 15:09:55 +01:00
README.md Check crate docs in CI 2023-05-20 10:48:25 +02:00

Tests

Directory structure

Top level directory structure:

  • src: Testing code.
  • typ: Input files. The tests in compiler specifically test the compiler while the others test the standard library (but also the compiler indirectly).
  • ref: Reference images which the output is compared with to determine whether a test passed or failed.
  • png: PNG files produced by tests.
  • pdf: PDF files produced by tests.

Running the tests

Running all tests (including unit tests):

cargo test --workspace

Running just the integration tests (the tests in this directory):

cargo test --workspace --test tests

You may want to make yourself an alias like:

testit

Running all tests whose paths contain the string page or stack.

testit page stack

Running a test with the exact filename page.typ.

testit --exact page.typ

Debug-printing the layout trees for all executed tests.

testit --debug empty.typ

To make the integration tests go faster they don't generate PDFs by default. Pass the --pdf flag to generate those. Mind that PDFs are not tested automatically at the moment, so you should always check the output manually when making changes.

testit --pdf

Update expected images

If you created a new test or fixed a bug in an existing test, you need to update the reference image used for comparison. For this, you can use the UPDATE_EXPECT environment variable or the --update flag:

testit mytest --update

If you use the VS Code test helper extension (see the tools folder), you can alternatively use the checkmark button to update the reference image. In that case you should also install oxipng on your system so that the test helper can optimize the reference images.

Making an alias

If you want to have a quicker way to run the tests, consider adding a shortcut to your shell profile so that you can simply write something like:

testit empty.typ

Bash

Open your Bash configuration by executing nano ~/.bashrc.

alias testit="cargo test --workspace --test tests --"

PowerShell

Open your PowerShell profile by executing notepad $profile.

function testit {
    cargo test --workspace --test tests -- $args
}