8000 Test that all the builders produce the same results. by xStrom · Pull Request #366 · linebender/parley · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Test that all the builders produce the same results. #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 1, 2025

Conversation

xStrom
Copy link
Member
@xStrom xStrom commented May 24, 2025

This will help ensure that the builders won't diverge in behavior as we continue modifying them. It also tests the reusability of LayoutContext.

There are known cases where the builders do currently diverge. For example:

  • Using only default styles.
    Would be good to have it catch the builders disagreeing on default font size or missing scale multipliers. While adding this test is trivial within the framework of this PR, unfortunately the solution isn't super trivial. So I will add the default style test along with the code fix in a separate PR.
  • When adding a span with the same style as the currently active span.
    For example see Add a test for nesting spans with the tree builder. #365.
    However, this gets into questions about supporting things like margin/padding on spans and how exactly the common core span API should look like.

I wanted to keep this PR here limited to the cases that don't require any builder modification. So that we can at least start protecting the partial commonality that the builders have. This will also mean that the follow-up PRs that do change builder code won't be burdened by the noise of adding a bunch of this testing framework code.

Copy link
Contributor
@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally seems good, but I'd like to make sure we're aligned on our understanding of how LayoutContexts work (I don't understand why you're using multiple in these tests).

/// LayoutContext D - Tree for dirt
/// LayoutContext D - Ranged from dirty
/// ```
fn compute(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this ought to be called something more specific. assert_builders_produce_same_result or something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Or just builders_produce_same_result)

Comment on lines +44 to +91
let mut lcx_a: LayoutContext<ColorBrush> = LayoutContext::new();
let mut lcx_b: LayoutContext<ColorBrush> = LayoutContext::new();
let mut lcx_c: LayoutContext<ColorBrush> = LayoutContext::new();
let mut lcx_d: LayoutContext<ColorBrush> = LayoutContext::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you want to test this separately, but my understanding is that you should be able to reuse the same LayoutContext for all builders without affecting results.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(unless my mental model is wrong, I would consider violations of that a bug)

Copy link
Member Author
@xStrom xStrom May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your understanding is correct and this test converts that "should" part into a "must". The test won't pass unless it's actually true. It tests various ways that a LayoutContext could fail to meet that goal.

Violations of this would indeed be a bug. A bug that this test is designed to reveal.

);

// Testing idempotence of ranged builder creation
let mut lcx_a_rb_two = lcx_a.ranged_builder(&mut fcx, text, scale, quantize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this would read a lot clearer if only the actual LayoutContexts had lcx in the name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I refactored the function so that the layout creation happens in a different function. This allowed me to remove these confusing variable names.

@xStrom xStrom added this pull request to the merge queue Jun 1, 2025
Merged via the queue into linebender:main with commit 90c79c0 Jun 1, 2025
24 checks passed
@xStrom xStrom deleted the test-builders branch June 1, 2025 10:49
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.

3 participants
0