Skip to content
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

test(format/grit): add tests for grit formatter #3937

Merged
merged 24 commits into from
Sep 23, 2024

Conversation

branberry
Copy link
Contributor

@branberry branberry commented Sep 16, 2024

Summary

Add basic testing setup for the Grit formatter. Also added some additional configuration to handle Grit files.

Test Plan

Verify that tests for Grit execute successfully

@github-actions github-actions bot added A-Project Area: project A-Formatter Area: formatter labels Sep 16, 2024
Copy link

codspeed-hq bot commented Sep 16, 2024

CodSpeed Performance Report

Merging #3937 will not alter performance

Comparing branberry:feat/grit-formatter-tests (1f185f2) with main (c921aeb)

Summary

✅ 107 untouched benchmarks

@github-actions github-actions bot added the A-Parser Area: parser label Sep 17, 2024
slotmap = { workspace = true, features = ["serde"] }
tracing = { workspace = true, features = ["attributes", "log"] }
biome_grit_syntax = { workspace = true }

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 the formatting changes might have been due to the newline here.


#[derive(Debug, Default, PartialEq, Eq)]

pub(crate) struct GritFileHandler;
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that we're adding a file handler for Grit 👍

Copy link
Contributor Author

@branberry branberry Sep 19, 2024

Choose a reason for hiding this comment

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

Glad to hear! Haha. I've been following some of the other examples, and I've seen that we typically create a file handler struct as a part of the testing process.

Not sure if I'm doing too much work here, but it sounds like I'm working in the right direction!

As a side note, I'm a Rust newbie so any pointers on how I can improve my Rust code is welcome and appreciated :D

@branberry branberry changed the title (DRAFT) feat(formatter/grit): add tests feat(formatter/grit): add tests for grit formatter Sep 19, 2024
@branberry branberry changed the title feat(formatter/grit): add tests for grit formatter test(formatter/grit): add tests for grit formatter Sep 19, 2024
@branberry branberry changed the title test(formatter/grit): add tests for grit formatter test(format/grit): add tests for grit formatter Sep 19, 2024
@branberry branberry marked this pull request as ready for review September 19, 2024 13:35
branberry and others added 2 commits September 19, 2024 09:29
Co-authored-by: Carson McManus <dyc3@users.noreply.github.com>
@github-actions github-actions bot added the L-HTML Language: HTML label Sep 19, 2024
@dyc3 dyc3 removed the L-HTML Language: HTML label Sep 19, 2024
Copy link
Contributor

@arendjr arendjr left a comment

Choose a reason for hiding this comment

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

Nice!

@arendjr
Copy link
Contributor

arendjr commented Sep 19, 2024

Note there does seem to be a test failure still.

@branberry
Copy link
Contributor Author

Hey @arendjr ! I see that test failure, and I'm currently working to resolve it. Thank you for the speedy review!

Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

In order for the tests to work, biome_service needs to know how to handle the file. You'll need to add the language to the DocumentFileSource enum. IIRC, can_parse is the actual function that's used.

You should go ahead and add a experimental-grit feature flag too, just like how html is set up. You can use #3967 for reference.

@github-actions github-actions bot added the A-Tooling Area: internal tools label Sep 20, 2024
@dyc3
Copy link
Contributor

dyc3 commented Sep 20, 2024

It looks like the codegen is failing and the tests are failing.

To fix the codegen: just gen-all should do it.

@branberry
Copy link
Contributor Author

Gotcha, thanks for the codegen stuff! I'm digging through the code a bit more now, and I think the test failures are due to me missing some additional configuration.

I confirmed here that can_format.supports_format() returns false and that is why the test is failing. Digging into that function a bit more to see if there's something else that I've missed

@dyc3
Copy link
Contributor

dyc3 commented Sep 20, 2024

There was one more feature thing I forgot that will fix the tests:

In biome_grit_formatter in the Cargo.toml, import biome_service like this to make sure the feature flag is enabled.

biome_service = { workspace = true, features = ["experimental-grit"] }

@branberry
Copy link
Contributor Author

@dyc3 Thanks! That resolved the file handler issue. Still have some more errors, but these are related to differences in implementation. It looks like in the biome_grit_parser/tests/spec_test.rs, we don't use the snapshot builder, but manually build out the snapshot tests. I'm assuming that's because of features that we still need to implement for grit. With that said, I'll refactor the test to look like the biome_grit_parser snapshot tests, and I'll push what I have so far.

@github-actions github-actions bot added the L-CSS Language: CSS label Sep 20, 2024
@arendjr
Copy link
Contributor

arendjr commented Sep 20, 2024

It looks like in the biome_grit_parser/tests/spec_test.rs, we don't use the snapshot builder, but manually build out the snapshot tests. I'm assuming that's because of features that we still need to implement for grit

What’s the snapshot builder? In any case, I’m not entirely sure why I did it like that anymore… it might just have been an oversight 😅

@branberry
Copy link
Contributor Author

@arendjr I was following the biome_html_formatter/tests/spec_test.rs as a reference for my changes. If that's something that you don't think using this helper is necessary, then I'll go ahead with the other example I referenced 👍

@arendjr
Copy link
Contributor

arendjr commented Sep 21, 2024

Ah, I see what you mean. I haven’t created formatter tests before, but it looks like that will be useful for formatter tests indeed. I hadn’t done that for the parser indeed, but those look a bit different anyway (I think I had based the parser tests on those for the CSS parser).

@branberry
Copy link
Contributor Author

branberry commented Sep 21, 2024

@arendjr Yeah, I'm conflicted now. Because the parser tests I would imagine are different for a reason, so I'm debugging the issue I'm having with the snapshot builder

Here's the exact line that is panicking

Here's the error as well

byte index 142 is out of bounds of ``function $name ($args) { $body }` as $func where {
  $func => `const $name = ($args) => { $body }`,
  $args <: contains `apple` => `mango`
}`
stack backtrace:

@branberry branberry closed this Sep 21, 2024
@branberry branberry reopened this Sep 21, 2024
@dyc3 dyc3 added the L-Grit Language: GritQL label Sep 22, 2024
@github-actions github-actions bot removed the L-CSS Language: CSS label Sep 23, 2024
Co-authored-by: Carson McManus <dyc3@users.noreply.github.com>
@arendjr
Copy link
Contributor

arendjr commented Sep 23, 2024

I’m not sure what caused the issue with that other test, but I might have a chance to look at it this week. If you like you can leave it in this PR in a disabled state, then I’ll follow up with a separate PR to enable it.

@dyc3
Copy link
Contributor

dyc3 commented Sep 23, 2024

I went ahead and fixed the merge conflict for you.

@branberry branberry marked this pull request as draft September 23, 2024 11:41
@branberry
Copy link
Contributor Author

@arendjr I figured out the issue with the test failure. I needed to run cargo insta accept to generate the new snapshot test. Rookie mistake on my part... haha!

@branberry branberry marked this pull request as ready for review September 23, 2024 12:39
@dyc3 dyc3 merged commit 5df4e8b into biomejs:main Sep 23, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: CLI A-Formatter Area: formatter A-Parser Area: parser A-Project Area: project A-Tooling Area: internal tools L-Grit Language: GritQL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants