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

Feature: Allow inline statements and added tests for Windows #13

Merged
merged 33 commits into from
Jun 29, 2023

Conversation

remirth
Copy link
Contributor

@remirth remirth commented Jun 28, 2023

Inline Statements

This solves issue #9 by running two regex's, one for statements containing a linefeed, and one without. Then passing down a feature flag based on if the statement is inline or not. I have added unit tests as well as regression tests for this feature.

Windows Tests

This PR also solves the problems with running tests on Windows discussed in PR #10. The same solution can probably be expanded to solve issue #7 as well.

Exsjabe and others added 30 commits June 27, 2023 16:25
Merge pull request FauconFan#10 from exsjabe/master
Copy link
Owner

@FauconFan FauconFan 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 really good, thank you for this PR. I have made some comments, but it is peanuts compared to the work you've done. When you fix them, it will be good to merge.

README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/cmdrun.rs Show resolved Hide resolved
src/cmdrun.rs Outdated
Comment on lines 109 to 131
let mut res = String::with_capacity(str.len());
match inline {
true => {
let str = str.trim_end();
let count = str.lines().count();
for (i, line) in str.lines().enumerate() {
res.push_str(line);
if i < count - 1 {
res.push_str("\r\n");
}
}

res
}
false => {
for line in str.lines() {
res.push_str(line);
res.push_str("\r\n");
}

res
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

This behavior should be documented. I'm not sure what this does. Does that replace '\n' by '\r\n' when the generated output from scripts run by Windows Shell? Because these scripts does not separate lines using \r\n by default? Maybe it is my poor understanding of how Windows IO works...

Copy link
Owner

Choose a reason for hiding this comment

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

Maybe the inline match block can be replaced by a string join, then when inline is false, add an additional \r\n.

Something like:

let mut res = str.lines().iter().collect::Vec<_>::().join("\r\n");

if !inline {
  res.push_str("\r\n");
}

If that's a performance choice, I can hear it, but everything is linear here, we don't really care about performance for this tool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure myself if it's even necessary, I was working backwards from trying to get the regression tests to work.
Some commands like yes output unix-style linebreaks which don't start with\r and that caused the tests to break. In practice, a user wouldn't notice the difference, but I suppose there is value in having consistency? Either way your solution is way cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Theoretically someone could be using a tool to verify the resulting markdown and not be able to easily validate it because of inconsistent line breaks, I suppose

Copy link
Owner

Choose a reason for hiding this comment

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

This is interesting ahah. Thank you for the fix!

src/lib.rs Outdated Show resolved Hide resolved
@remirth
Copy link
Contributor Author

remirth commented Jun 28, 2023

This should fix the issues you pointed out in the comments 😁

Copy link
Owner

@FauconFan FauconFan left a comment

Choose a reason for hiding this comment

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

Good to go!

@FauconFan FauconFan merged commit e5891b1 into FauconFan:master Jun 29, 2023
@FauconFan FauconFan mentioned this pull request Jun 29, 2023
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.

2 participants