Skip to content

Commit

Permalink
add more info to paragraph failed asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
vsch committed Apr 11, 2020
1 parent 437bd09 commit c36ff2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
6 changes: 6 additions & 0 deletions VERSION-TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Release 0.60.0](#release-0600)
- [API Refactoring](#api-refactoring)
- [Next 0.61.xx](#next-061xx)
- [0.61.6](#0616)
- [0.61.4](#0614)
- [0.61.2](#0612)
- [0.61.0](#0610)
Expand Down Expand Up @@ -216,6 +217,11 @@ Please give feedback on the upcoming changes if you have concerns about breaking
`|` for each line that was wrapped. Otherwise, it is impossible to tell where each line
ends and another begins.

## 0.61.6

* Fix: add more information to `MarkdownParagraph.resolveTrackedOffsetsEdit` assert failures to
allow better diagnostics in reported stack traces.

## 0.61.4

* Fix: merge [#397, PR: Add base64 image support with docx rendering] thanks to [@Xaelis]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,6 @@ BasedSequence resolveTrackedOffsetsEdit(BasedSequence baseSpliced, BasedSequence
System.out.println(String.format("%saltUnwrapped anchor: `%s`", anchorResolvedBy, altUnwrapped.safeSubSequence(anchorIndex - 10, anchorIndex).toVisibleWhitespaceString() + "|" + altUnwrapped.safeSubSequence(anchorIndex, anchorIndex + 10).toVisibleWhitespaceString()));
}

assert baseSequence.safeCharAt(anchorOffset) == altUnwrapped.safeCharAt(anchorIndex + anchorDelta)
// NOTE: alt sequence could have spaces removed which would result in space in base sequence and EOL in alt sequence
|| baseSequence.isCharAt(anchorOffset, WHITESPACE) && altUnwrapped.isCharAt(anchorIndex + anchorDelta, WHITESPACE_OR_NUL)
: String.format("baseSeq.charAt: %d != altUnwrapped.charAt: %d"
, (int) baseSequence.safeCharAt(anchorOffset)
, (int) altUnwrapped.safeCharAt(anchorIndex + anchorDelta)
);

// now see where it is in the wrapped sequence
int wrappedIndex = altTracker.getOffsetInfo(anchorOffset, false).startIndex;

Expand All @@ -249,6 +241,16 @@ BasedSequence resolveTrackedOffsetsEdit(BasedSequence baseSpliced, BasedSequence
System.out.println(String.format("wrapped anchor: `%s`", wrapped.safeSubSequence(wrappedIndex - 10, wrappedIndex).toVisibleWhitespaceString() + "|" + wrapped.safeSubSequence(wrappedIndex, wrappedIndex + 10).toVisibleWhitespaceString()));
}

assert baseSequence.safeCharAt(anchorOffset) == altUnwrapped.safeCharAt(anchorIndex + anchorDelta)
// NOTE: alt sequence could have spaces removed which would result in space in base sequence and EOL in alt sequence
|| baseSequence.isCharAt(anchorOffset, WHITESPACE) && altUnwrapped.isCharAt(anchorIndex + anchorDelta, WHITESPACE_OR_NUL)
: String.format("baseSeq.charAt: %d != altUnwrapped.charAt: %d, altWrapped anchor: '%s', wrapped anchor: '%s'"
, (int) baseSequence.safeCharAt(anchorOffset)
, (int) altUnwrapped.safeCharAt(anchorIndex + anchorDelta)
, altWrapped.safeSubSequence(wrappedIndex - 10, wrappedIndex).toVisibleWhitespaceString() + "|" + altWrapped.safeSubSequence(wrappedIndex, wrappedIndex + 10).toVisibleWhitespaceString()
, wrapped.safeSubSequence(wrappedIndex - 10, wrappedIndex).toVisibleWhitespaceString() + "|" + wrapped.safeSubSequence(wrappedIndex, wrappedIndex + 10).toVisibleWhitespaceString()
);

int wrappedAdjusted = 0;
// take char start but if at whitespace, use previous for validation
if (WHITESPACE.test(altUnwrapped.safeCharAt(anchorIndex + anchorDelta))) {
Expand All @@ -273,9 +275,12 @@ BasedSequence resolveTrackedOffsetsEdit(BasedSequence baseSpliced, BasedSequence

assert altUnwrappedCharAt == wrappedCharAt
|| WHITESPACE.test(altUnwrappedCharAt) && WHITESPACE.test(wrappedCharAt)
: String.format("altUnwrapped.charAt: %s != wrapped.charAt: %s"
: String.format("altUnwrapped.charAt: '%s' != wrapped.charAt: '%s' for width=%d, unwrapped: '%s', wrapped: '%s'"
, SequenceUtils.toVisibleWhitespaceString(Character.toString(altUnwrappedCharAt))
, SequenceUtils.toVisibleWhitespaceString(Character.toString(wrappedCharAt))
, width
, SequenceUtils.toVisibleWhitespaceString(altUnwrapped)
, SequenceUtils.toVisibleWhitespaceString(altWrapped)
);

// Adjust index position and restore spaces if needed
Expand Down

0 comments on commit c36ff2b

Please sign in to comment.