From c36ff2bc6d94d8b2e9575ba25dde1a7bde0c97a2 Mon Sep 17 00:00:00 2001 From: Vladimir Schneider Date: Sat, 11 Apr 2020 09:08:42 -0400 Subject: [PATCH] add more info to paragraph failed asserts --- VERSION-TODO.md | 6 +++++ .../util/format/MarkdownParagraph.java | 23 +++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/VERSION-TODO.md b/VERSION-TODO.md index 4e5a034a1..31a15d1fd 100644 --- a/VERSION-TODO.md +++ b/VERSION-TODO.md @@ -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) @@ -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] diff --git a/flexmark-util-format/src/main/java/com/vladsch/flexmark/util/format/MarkdownParagraph.java b/flexmark-util-format/src/main/java/com/vladsch/flexmark/util/format/MarkdownParagraph.java index e5cd8aaef..269f5fe04 100644 --- a/flexmark-util-format/src/main/java/com/vladsch/flexmark/util/format/MarkdownParagraph.java +++ b/flexmark-util-format/src/main/java/com/vladsch/flexmark/util/format/MarkdownParagraph.java @@ -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; @@ -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))) { @@ -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