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

Fix line number 0 unaligned display #142

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

chengr4
Copy link

@chengr4 chengr4 commented Aug 20, 2024

fix #57


// for issue 57
#[test]
fn test_line_number_0() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you change up the commits so this test case is the first commit, with it passing ie showing the bad behavior?

Benefits

  • For someone viewing the commit with the behavior change, it makes it obvious what the intended behavior change is
  • It shows to you and reviewers that the test tests the intended case

Copy link
Author

Choose a reason for hiding this comment

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

got it!

Copy link
Contributor

Choose a reason for hiding this comment

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

For someone viewing the commit with the behavior change, it makes it obvious what the intended behavior change is

This means the commit that changes behavior should also include test updates. Every commit should pass tests

Copy link
Contributor

Choose a reason for hiding this comment

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

As reminder, every commit should pass tests

Copy link
Contributor

Choose a reason for hiding this comment

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

ae4694f is said to be a fix and changes behavior but there is no test update in that commit.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry I did not see the comment and please check out the update. Thanks.

tests/formatter.rs Outdated Show resolved Hide resolved
thread 'test_line_number_0' panicked at tests/formatter.rs:928:5:

---- expected: tests/formatter.rs:919:20
++++ actual:   In-memory
   1    1 | error: dummy
   2      -  --> file/path:0:3
   3      -   |
   4      - 0 | foo
   5      -   |   ^
   6      -   |∅
        2 + --> file/path:0:3
        3 +  |
        4 + 0 |foo
        5 +  |   ^
        6 +  |∅
@chengr4
Copy link
Author

chengr4 commented Aug 21, 2024

BTW, I was thinking to add unit tests for eg. the format_line method. it seemed quite challenging 😅, so I gave up. If anyone is willing to guide me on this, I would be very happy to give it another try.

@chengr4 chengr4 marked this pull request as ready for review August 21, 2024 13:32
@chengr4
Copy link
Author

chengr4 commented Aug 23, 2024

FYI
In the last commit, I extracted the calculation to another method. I'm not sure if it is proper, but I'm trying to make fmt adhere more closely to the Single Responsibility Principle

src/renderer/display_list.rs Outdated Show resolved Hide resolved
src/renderer/display_list.rs Outdated Show resolved Hide resolved
src/renderer/display_list.rs Outdated Show resolved Hide resolved
src/renderer/display_list.rs Outdated Show resolved Hide resolved
src/renderer/display_list.rs Fixed Show resolved Hide resolved
@chengr4
Copy link
Author

chengr4 commented Aug 26, 2024

@epage
I thought about it and decided to refactor like this. If you feel the last commit is over-engineering, please let me know, and I'll delete it. Thanks.

src/renderer/display_list.rs Outdated Show resolved Hide resolved
@epage
Copy link
Contributor

epage commented Aug 26, 2024

I thought about it and decided to refactor like this. If you feel the last commit is over-engineering, please let me know, and I'll delete it. Thanks.

For myself, I don't think its needed.

btw I've not been looking too deeply at this until the commits get cleaned up

src/renderer/display_list.rs Fixed Show fixed Hide fixed
src/renderer/display_list.rs Fixed Show fixed Hide fixed
@chengr4 chengr4 force-pushed the fix-unalign branch 2 times, most recently from 11f6daf to f758ef6 Compare August 27, 2024 12:27
@epage
Copy link
Contributor

epage commented Aug 27, 2024

btw I've not been looking too deeply at this until the commits get cleaned up

Please clean up the commits to be how you want them reviewed and merged.

I would recommend

  • refactor commits
  • test demonstrating the problem
  • fix with test update showing new behavior

@chengr4
Copy link
Author

chengr4 commented Aug 27, 2024

I feel it is a little difficult to put refactor commits in advance. So I I put them at the end instead.

src/renderer/display_list.rs Outdated Show resolved Hide resolved
	- Line number width is 1 if max line number is 0
	- Line number witdh is 0 if max line number is None
	- Update test_line_number_0 in tests/formatter.rs to reflect new behavior
	- Fix issue rust-lang#57
		The fold chaining is to find max line number rather than line number width
@chengr4
Copy link
Author

chengr4 commented Oct 16, 2024

@epage I know this PR isn't a very necessary fix, but I'm curious if we can continue with it or if you'd prefer to close it?

@epage
Copy link
Contributor

epage commented Oct 16, 2024

Looks like the commits aren't atomic. The "fix" commit doesn't include any test changes.

Note when i asked for a test commit, I asked that it show the existing behavior (it should pass) and that the fix commit then makes the test to work with the fix. This makes it very clear what the change in behavior is.

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.

Unaligned display when one line source given
3 participants