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

deer: testing framework #1701

Merged
merged 22 commits into from
Jan 6, 2023
Merged

deer: testing framework #1701

merged 22 commits into from
Jan 6, 2023

Conversation

indietyp
Copy link
Member

@indietyp indietyp commented Dec 20, 2022

🌟 What is the purpose of this PR?

Currently, we have no way of testing the built-in types that are to be implemented (#1700). This remedies it by creating a testing framework that works on tokens (similar to serde_test). To make reuse easier it is a separate internal-only package called deer-desert (name TBD)

🔗 Related links

🚫 Blocked by

🔍 What does this change?

Creates a new internal-only crate for testing deserialize implementations independent of an actual deserializer.

🛡 What tests cover this?

Unit tests will be provided for the testing framework to ensure everything is ok.

An example test has been provided, but more tests will follow once std #1700 has progressed further. Otherwise, the Deserialize would be implemented multiple times for the "atomic" types.


desert as in deserialize test

@codecov
Copy link

codecov bot commented Dec 20, 2022

Codecov Report

Merging #1701 (9585170) into main (814d8df) will decrease coverage by 1.52%.
The diff coverage is 13.30%.

@@            Coverage Diff             @@
##             main    #1701      +/-   ##
==========================================
- Coverage   53.72%   52.19%   -1.53%     
==========================================
  Files         229      237       +8     
  Lines       15227    15826     +599     
  Branches      411      411              
==========================================
+ Hits         8180     8261      +81     
- Misses       7042     7560     +518     
  Partials        5        5              
Flag Coverage Δ
backend-integration-tests 2.87% <ø> (ø)
deer 54.28% <13.30%> (-10.00%) ⬇️
unit-tests 1.58% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/libs/deer/desert/src/array.rs 0.00% <0.00%> (ø)
packages/libs/deer/desert/src/assert.rs 0.00% <0.00%> (ø)
packages/libs/deer/desert/src/deserializer.rs 0.00% <0.00%> (ø)
packages/libs/deer/desert/src/object.rs 0.00% <0.00%> (ø)
packages/libs/deer/desert/src/tape.rs 0.00% <0.00%> (ø)
packages/libs/deer/desert/src/token.rs 0.00% <0.00%> (ø)
packages/libs/deer/json/src/error.rs 0.00% <ø> (ø)
packages/libs/deer/json/src/lib.rs 0.24% <0.00%> (-0.01%) ⬇️
packages/libs/deer/src/context.rs 95.34% <0.00%> (-1.13%) ⬇️
packages/libs/deer/src/error/internal.rs 0.00% <0.00%> (ø)
... and 3 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@vercel
Copy link

vercel bot commented Dec 21, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
hash 🔄 Building (Inspect) Jan 5, 2023 at 5:40PM (UTC)
hash-design-system 🔄 Building (Inspect) Jan 5, 2023 at 5:40PM (UTC)
hashdotdev 🔄 Building (Inspect) Jan 5, 2023 at 5:40PM (UTC)

@indietyp indietyp marked this pull request as ready for review December 21, 2022 18:42
Copy link
Contributor

@thehabbos007 thehabbos007 left a comment

Choose a reason for hiding this comment

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

Very cool, Bilal! I left some comments :)
Excited to see it in action

///
/// assert_tokens(&Bool(true), &[Token::Bool(true)])
/// ```
Bool(bool),
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why only bool has this full test and the rest dont? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is more of a showcase. Building this out, I realized that most of the code is duplicated for these kinds of tests on the primitive types, so the idea was to showcase the examples instead of using the existing primitive Visitor and Deserialize implementations that are in the follow-up PR.

use crate::token::Token;

#[derive(Debug)]
enum Trivia<'a> {
Copy link
Contributor

Choose a reason for hiding this comment

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

May I ask what the origin of this naming is? Seems interesting 🐮

Copy link
Member Author

@indietyp indietyp Jan 5, 2023

Choose a reason for hiding this comment

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

Yes, for sure! This is taken from rust-analyzer, where whitespace and comments are regarded as trivia. The idea, in this case, is basically:

{"key1": 1, "key2": 2, "key3": 3}

Taking this, the whitespace would be considered trivia. When we then search for a key, the key and value span are both "erased" and converted to trivia, e.g., taking key2, our object internally turns into:

{"key1": 1,            "key3": 3}

https://github.com/rust-lang/rust-analyzer/blob/80cabf726068187d8686b5ccf37aac484da84904/crates/parser/src/syntax_kind.rs#L24-L29

packages/libs/deer/desert/src/tape.rs Outdated Show resolved Hide resolved
packages/libs/deer/desert/src/tape.rs Show resolved Hide resolved
packages/libs/deer/desert/src/tape.rs Show resolved Hide resolved
packages/libs/deer/desert/src/object.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@thehabbos007 thehabbos007 left a comment

Choose a reason for hiding this comment

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

Looks good to me! Great stuff :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/libs > deer Affects the `deer` crate (library)
Development

Successfully merging this pull request may close these issues.

None yet

2 participants