Skip to content

Cleanup & comment .chalk file writer tests #570

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 2 commits into from
Jul 12, 2020

Conversation

daboross
Copy link
Contributor

This addresses another issue raised in the final review of #430 - mainly, that none of the tests explained at all what they're doing, and multiple tests were often merged into one test function.

We've made sure that each test makes sense, has comments, and only tests a single item. This involved removing reduntant tests, and creating new test functions. The comments are useful when a test's purpose is obscured by the substantial boilerplate it requires.

super-tuple and others added 2 commits July 11, 2020 14:15
We test the program writer by parsing a program, writing it, and
reparsing the output. We compare the original Program against the
writer's output using Program's Eq impl. This Eq impl relies on item
ids, which are dependent on the order the items appear in the program
source.

Previously, we would output one type of item at a time. That meant the
original ordering would not be preserved, unless the program was written
with the items grouped, in the correct ordering.

This is a weird and frustrating quirk that makes the tests less
readable. We have updated `write_program` to preserve the ordering. The
items are sorted by their RawId, which will result in the original
ordering.

Co-authored-by: David Ross <daboross@daboross.net>
Refactored the syntax writer tests so there is only one reparse_test
call per test function. This involved removing reduntant tests, and
creating new test functions.

We also added comments for all of the test to describe what particular
functionality the test was targeted at. This is useful when a test's
purpose is obscured by the substantial boilerplate that test requires.

Co-authored-by: David Ross <daboross@daboross.net>
@@ -25,7 +25,7 @@ pub use self::state::*;

use self::utils::as_display;

pub fn write_item<F, I, T>(f: &mut F, ws: &WriterState<'_, I>, v: &T) -> Result
fn write_item<F, I, T>(f: &mut F, ws: &WriterState<'_, I>, v: &T) -> Result
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is technically unrelated, but fairly insubstantial.

Copy link
Member

Choose a reason for hiding this comment

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

Well, as long as write_items is still public and usable, this should be fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍! I think it is a positive change, just that it probably should have ended up part of #558 rather than this PR.

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

This is great :)

@jackh726 jackh726 merged commit 882787a into rust-lang:master Jul 12, 2020
@daboross daboross deleted the writer-tests branch July 18, 2020 18:32
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.

4 participants