-
Notifications
You must be signed in to change notification settings - Fork 222
Fixes some issues with line wrapping around inline code #215
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
Open
natecook1000
wants to merge
4
commits into
main
Choose a base branch
from
formatting-inline-code
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6087ac3
Fixes some issues with line wrapping around inline code
natecook1000 529def7
Updates a few documentation comments
natecook1000 25c0683
Merge branch 'main' into formatting-inline-code
natecook1000 caa8126
Merge branch 'main' into formatting-inline-code
natecook1000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -967,6 +967,61 @@ class MarkupFormatterLineSplittingTests: XCTestCase { | |
} | ||
} | ||
|
||
/** | ||
Test that breaks are inserted before symbolic links when necessary to | ||
honor the preferred line limit. | ||
*/ | ||
func testParagraphWithLongSymbolicLinks() { | ||
let source = """ | ||
Because options are parsed before arguments, an option that consumes or | ||
suppresses the `--` terminator can prevent a ``postTerminator`` argument | ||
array from capturing any input. In particular, the | ||
``SingleValueParsingStrategy/unconditional``, | ||
``ArrayParsingStrategy/unconditionalSingleValue``, and | ||
``ArrayParsingStrategy/remaining`` parsing strategies can all consume | ||
the terminator as part of their values. | ||
""" | ||
let expected = """ | ||
Because options are parsed before arguments, an option that consumes or | ||
suppresses the `--` terminator can prevent a ``postTerminator`` argument | ||
array from capturing any input. In particular, the | ||
``SingleValueParsingStrategy/unconditional``, | ||
``ArrayParsingStrategy/unconditionalSingleValue``, and | ||
``ArrayParsingStrategy/remaining`` parsing strategies can all consume the | ||
terminator as part of their values. | ||
""" | ||
let options = MarkupFormatter.Options(preferredLineLimit: PreferredLineLimit(maxLength: 74, breakWith: .softBreak)) | ||
let document = Document(parsing: source, options: [.parseSymbolLinks]) | ||
let printed = document.format(options: options) | ||
XCTAssertEqual(expected, printed) | ||
|
||
let expectedTreeDump = """ | ||
Document | ||
└─ Paragraph | ||
├─ Text "Because options are parsed before arguments, an option that consumes or" | ||
├─ SoftBreak | ||
├─ Text "suppresses the " | ||
├─ InlineCode `--` | ||
├─ Text " terminator can prevent a " | ||
├─ InlineCode `postTerminator` | ||
├─ Text " argument" | ||
├─ SoftBreak | ||
├─ Text "array from capturing any input. In particular, the" | ||
├─ SoftBreak | ||
├─ InlineCode `SingleValueParsingStrategy/unconditional` | ||
├─ Text "," | ||
├─ SoftBreak | ||
├─ InlineCode `ArrayParsingStrategy/unconditionalSingleValue` | ||
├─ Text ", and" | ||
├─ SoftBreak | ||
├─ InlineCode `ArrayParsingStrategy/remaining` | ||
├─ Text " parsing strategies can all consume the" | ||
├─ SoftBreak | ||
└─ Text "terminator as part of their values." | ||
""" | ||
XCTAssertEqual(expectedTreeDump, Document(parsing: printed).debugDescription()) | ||
} | ||
|
||
/** | ||
Test that line breaks maintain block structure in a flat, unordered list. | ||
*/ | ||
|
@@ -1217,7 +1272,6 @@ class MarkupFormatterLineSplittingTests: XCTestCase { | |
let expected = """ | ||
> Really really | ||
> really long line | ||
> >\u{0020} | ||
> > Whoa, really | ||
> > really really | ||
> > really long | ||
|
@@ -1372,6 +1426,52 @@ class MarkupFormatterLineSplittingTests: XCTestCase { | |
XCTAssertEqual(expected, printed) | ||
XCTAssertTrue(document.hasSameStructure(as: Document(parsing: printed))) | ||
} | ||
|
||
/** | ||
Test that wrapping at the start of a long inline code run doesn't cause | ||
an extra newline. | ||
*/ | ||
func testBreakAtLongInlineCode() { | ||
let source = "This is a long line `that contains inline code`." | ||
let document = Document(parsing: source) | ||
let printed = document.format(options: .init(preferredLineLimit: .init(maxLength: 20, breakWith: .softBreak))) | ||
let expected = """ | ||
This is a long line | ||
`that contains | ||
inline code`. | ||
""" | ||
let expectedTreeDump = """ | ||
Document | ||
└─ Paragraph | ||
├─ Text "This is a long line" | ||
├─ SoftBreak | ||
├─ InlineCode `that contains inline code` | ||
└─ Text "." | ||
""" | ||
XCTAssertEqual(expected, printed) | ||
XCTAssertEqual(expectedTreeDump, Document(parsing: printed).debugDescription()) | ||
} | ||
|
||
/** | ||
Test that wrapping at the start of a short inline code run doesn't cause | ||
an extra newline. | ||
*/ | ||
func testBreakAtShortInlineCode() { | ||
let source = """ | ||
Perform an atomic logical AND operation on the value referenced by | ||
`pointer` and return the original value, applying the specified memory | ||
ordering. | ||
""" | ||
let expected = """ | ||
Perform an atomic logical AND operation on the value referenced by | ||
`pointer` and return the original value, applying the specified memory | ||
ordering. | ||
""" | ||
Comment on lines
+1460
to
+1469
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: The input and expected output are identical. Because of this, I find it harder to reason about how this test would have behaved differently without the changes in this PR. |
||
let document = Document(parsing: source) | ||
let printed = document.format(options: .init(preferredLineLimit: .init(maxLength: 76, breakWith: .softBreak))) | ||
XCTAssertEqual(expected, printed) | ||
XCTAssertTrue(document.hasSameStructure(as: Document(parsing: printed))) | ||
} | ||
} | ||
|
||
class MarkupFormatterTableTests: XCTestCase { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: This example data confused me for a bit because the input was already wrapped almost the same as the expected output (only one word wrapped differently). Because of this, I found it difficult to reason about how this test would have behaved differently without the changes in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! That wrapping change wasn't intended – I'll fix that and change the example data to describe the behavior it's validating. (I wasn't quite sure how to go here since these are fixes for bugs that aren't exposed in the current tests.)