Skip to content

Add unit tests for BitTricks.isAsciiOnly - #706

Merged
Ladicek merged 1 commit into
smallrye:mainfrom
basteez:test/bittricks-isasciionly-coverage
Aug 24, 2026
Merged

Ladicek merged 1 commit into
smallrye:mainfrom
basteez:test/bittricks-isasciionly-coverage

Conversation

@basteez

@basteez basteez commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

BitTricks.isAsciiOnly had no direct tests, even though it sits on the ASCII fast path used when writing UTF-8 strings during index serialization, and it has two implementations that must be kept in sync: the plain byte loop in src/main/java and the VarHandle variant in src/main/java11 that reads eight bytes at a time followed by a byte-by-byte tail.

This PR adds a BitTricksTest that pins the contract: empty input, single-byte high-bit and boundary values (0x7F must pass, 0x80 and 0xFF must fail), non-ASCII bytes in short inputs, and that bytes outside the [off, off+len) window are ignored. It also poisons every byte position across two full batches so each lane and the batch seam are covered. The input lengths (0, 1, 7, 8, 11, 16) are chosen around the eight-byte batch boundary so the same cases exercise the java11 variant's batch and tail paths as well.

The test lives in package org.jboss.jandex because both the class and the method are package-private; all existing tests are in org.jboss.jandex.test, so this introduces the first same-package test. Happy to move it or take a different approach if you would rather keep tests out of the production package.

One thing worth flagging: a normal mvn test runs against the base byte-loop implementation only. The java11 VarHandle variant is layered into the multi-release JAR at package time, after the test phase, so it is not on the test classpath and these tests do not actually execute it. The class comment says as much. Genuinely exercising the java11 variant (and adding a differential test that compares it against the base loop, which would be the real guard against the two drifting) needs some surefire or multi-release test wiring. I left that out to keep this change small, but I am happy to follow up with it if you are interested.

Verified locally with mvn -pl core test -Dtest=BitTricksTest on JDK 21: 15 tests, all passing.

BitTricks.isAsciiOnly had no direct tests, despite having two
implementations that must be kept in sync (the byte loop in
src/main/java and the VarHandle variant in src/main/java11) and being
on the ASCII fast path of UTF-8 index serialization.

These tests pin the base implementation's contract across the empty
input, single-byte high-bit and boundary values (0x7F and 0x80),
non-ASCII bytes in short inputs, and window/offset handling. Input
lengths are chosen around the eight-byte batch boundary (0, 1, 7, 8,
11, 16) so the same cases also cover the java11 variant's batch and
tail paths if that variant is ever placed on the test classpath.

Signed-off-by: Tiziano Basile <[email protected]>
@Ladicek Ladicek added this to the 3.6.1 milestone Aug 24, 2026
@Ladicek
Ladicek merged commit fc3ab0d into smallrye:main Aug 24, 2026
83 of 86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants