@Test public void testTranslate() { DocumentRange range = new DocumentRange(5, 8); range.translate(6); Assert.assertEquals(11, range.getStartOffset()); Assert.assertEquals(14, range.getEndOffset()); }
@Test public void testCompareTo() { DocumentRange range = new DocumentRange(5, 8); Assert.assertTrue(range.compareTo(null) == 1); DocumentRange range2 = new DocumentRange(4, 8); Assert.assertTrue(range.compareTo(range2) > 0); range2 = new DocumentRange(5, 8); Assert.assertTrue(range.compareTo(range2) == 0); Assert.assertTrue(range.compareTo(range) == 0); range2 = new DocumentRange(6, 8); Assert.assertTrue(range.compareTo(range2) < 0); range2 = new DocumentRange(5, 7); Assert.assertTrue(range.compareTo(range2) > 0); range2 = new DocumentRange(5, 9); Assert.assertTrue(range.compareTo(range2) < 0); }
@Test public void testHashCode() { // NOTE: Not a good test, assumes formula of hash code! DocumentRange range = new DocumentRange(5, 8); Assert.assertEquals(5+8, range.hashCode()); }
@Override public boolean containsPosition(int pos) { return pos>=range.getStartOffset() && pos<range.getEndOffset(); }
@Test(expected = IllegalArgumentException.class) public void testSet_NegativeStart() throws Exception { new DocumentRange(1, 1).set(-1, 8); }
@Test public void testIsZeroLength() { Assert.assertFalse(new DocumentRange(1, 3).isZeroLength()); Assert.assertFalse(new DocumentRange(2, 3).isZeroLength()); Assert.assertTrue(new DocumentRange(3, 3).isZeroLength()); }
@Test public void testSet_HappyPath() { DocumentRange range = new DocumentRange(1, 1); range.set(5, 8); Assert.assertEquals(5, range.getStartOffset()); Assert.assertEquals(8, range.getEndOffset()); }
/** * Returns a list of "mark all" highlights in the text area. If there are * no such highlights, this will be an empty list. * * @return The list of "mark all" highlight ranges. */ public List<DocumentRange> getMarkAllHighlightRanges() { List<DocumentRange> list = new ArrayList<DocumentRange>( markAllHighlights.size()); for (HighlightInfo info : markAllHighlights) { int start = info.getStartOffset(); int end = info.getEndOffset() + 1; // HACK DocumentRange range = new DocumentRange(start, end); list.add(range); } return list; }
@Test public void testConstructor_HappyPath() { DocumentRange range = new DocumentRange(5, 8); Assert.assertEquals(5, range.getStartOffset()); Assert.assertEquals(8, range.getEndOffset()); }
SearchResult res = find(textArea, context); if (res.wasFound() && !res.getMatchRange().isZeroLength()) { int dot = res.getMatchRange().getStartOffset(); if (context.getSearchForward()) { int length = replacement==null ? 0 : replacement.length(); range = new DocumentRange(dot, dot);
@Test public void testGetStartOffset() { DocumentRange range = new DocumentRange(5, 8); Assert.assertEquals(5, range.getStartOffset()); range.set(9, 12); Assert.assertEquals(9, range.getStartOffset()); }
@Test public void testGetEndOffset() { DocumentRange range = new DocumentRange(5, 8); Assert.assertEquals(8, range.getEndOffset()); range.set(1, 2); Assert.assertEquals(2, range.getEndOffset()); }
@Override public int getOffset() { return range.getStartOffset(); }
DocumentRange match = res.getMatchRange().translate(start); if (match.isZeroLength()) { start = match.getEndOffset() + 1; if (start>findIn.length()) { break; start = match.getEndOffset();
if (res.getMatchRange().isZeroLength()) { if (res.getMatchRange().getStartOffset() == textArea.getDocument().getLength()) { break;
if (result.wasFound() && !result.getMatchRange().isZeroLength()) { result.getMatchRange().translate(start);
@Test public void testEquals() { DocumentRange range = new DocumentRange(5, 8); Assert.assertFalse(range.equals(null)); Assert.assertTrue(range.equals(range)); Assert.assertTrue(range.equals(new DocumentRange(5, 8))); Assert.assertFalse(range.equals(new DocumentRange(4, 8))); Assert.assertFalse(range.equals("Hello world")); }
@Test public void testToString() { DocumentRange range = new DocumentRange(5, 8); Assert.assertEquals("[DocumentRange: 5-8]", range.toString()); }
/** * Returns whether this document range is equal to another one. * * @param other Another object, presumably a document range. * @return Whether <code>other</code> is also a document range, and equal * to this one. */ @Override public boolean equals(Object other) { if (other==this) { return true; } if (other instanceof DocumentRange) { return this.compareTo((DocumentRange)other)==0; } return false; }
/** * Constructor. * * @param startOffs The starting offset in the document, inclusive. * @param endOffs The ending offset in the document, exclusive. * @throws IllegalArgumentException If <code>endOffs</code> is less than * <code>startOffs</code>, or either argument is less than zero. */ public DocumentRange(int startOffs, int endOffs) { set(startOffs, endOffs); }