### Question:
PotentialBracketEndDelimiter extends InlineWithText { boolean eligibleForReferenceDefinition(PotentialBracketDelimiter openingDelimiter, Cursor cursor) { boolean linkDelimiter = openingDelimiter.isLinkDelimiter(); if (!linkDelimiter) { return false; } int cursorRelativeOffset = cursor.toCursorOffset(openingDelimiter.getOffset()); for (int x = cursorRelativeOffset - 1; x >= 0; --x) { char c = cursor.getChar(x); if (c == '\n') { return true; } else if (c != ' ') { return false; } if (cursorRelativeOffset - x == 4) { return false; } } int cursorRelativeEndOffset = cursor.toCursorOffset(getOffset()); for (int x = cursorRelativeOffset + 1; x < cursorRelativeEndOffset; ++x) { char c = cursor.getChar(x); if (c == '[' && !precededByBackslashEscape(cursor, x)) { return false; } } return true; } PotentialBracketEndDelimiter(Line line, int offset); @Override void emit(DocumentBuilder builder); @Override void apply(ProcessingContext context, List<Inline> inlines, Cursor cursor); void truncate(List<Inline> inlines, int indexOfOpeningDelimiter);  }### Answer:
@Test public void eligibleForReferenceDefinitionImage() { PotentialBracketEndDelimiter delimiter = new PotentialBracketEndDelimiter(line, 0); PotentialBracketDelimiter openingDelimiter = new PotentialBracketDelimiter(line, 0, 2, "!["); assertFalse(delimiter.eligibleForReferenceDefinition(openingDelimiter, Cursors.createCursor("!["))); }
@Test public void eligibleForReferenceDefinitionLinkStartOfLine() { PotentialBracketEndDelimiter delimiter = new PotentialBracketEndDelimiter(line, 0); assertTrue(delimiter.eligibleForReferenceDefinition(new PotentialBracketDelimiter(line, 0, 1, "["), Cursors.createCursor("["))); assertTrue(delimiter.eligibleForReferenceDefinition(new PotentialBracketDelimiter(line, 2, 1, "["), Cursors.createCursor("a\n["))); }
@Test public void eligibleForReferenceDefinitionLinkIndented() { PotentialBracketEndDelimiter delimiter = new PotentialBracketEndDelimiter(line, 0); assertTrue(delimiter.eligibleForReferenceDefinition(new PotentialBracketDelimiter(line, 3, 1, "["), Cursors.createCursor("a\n ["))); assertTrue(delimiter.eligibleForReferenceDefinition(new PotentialBracketDelimiter(line, 5, 1, "["), Cursors.createCursor("a\n ["))); assertFalse(delimiter.eligibleForReferenceDefinition(new PotentialBracketDelimiter(line, 6, 1, "["), Cursors.createCursor("a\n ["))); assertFalse(delimiter.eligibleForReferenceDefinition(new PotentialBracketDelimiter(line, 4, 1, "["), Cursors.createCursor(" ["))); assertTrue(delimiter.eligibleForReferenceDefinition(new PotentialBracketDelimiter(line, 3, 1, "["), Cursors.createCursor(" ["))); assertFalse(delimiter.eligibleForReferenceDefinition(new PotentialBracketDelimiter(line, 3, 1, "["), Cursors.createCursor("a ["))); }