/** * Test that trying to reset an annotation with an end bigger than the document * an IndexOutOfBoundsException. */ public void testResetAnnotationPastDocEndThrowsException() throws Exception { init("<p>abcdef</p>"); try { doc.resetAnnotation(1, doc.size() + 1, "style/color", "frub"); // Doh - no exception thrown. Fail the test assert false; } catch (IndexOutOfBoundsException iae) { // expected } }
/** * Test that trying to reset an annotation with an end bigger than the document * an IndexOutOfBoundsException. */ public void testResetAnnotationPastDocEndThrowsException() throws Exception { init("<p>abcdef</p>"); try { doc.resetAnnotation(1, doc.size() + 1, "style/color", "frub"); // Doh - no exception thrown. Fail the test assert false; } catch (IndexOutOfBoundsException iae) { // expected } }
@Override public void insertText(int location, String text) { Preconditions.checkPositionIndex(location, size()); // TODO(danilatos): Get the schema constraints from the document // and use the corresponding permitted characters from there. // text = getPermittedCharactersForPoint(point).convertString(text); try { begin(); consume(insertText(text, at(location))); } finally { end(); } }
/** Test adding an annotation over the whole document */ public void testSetAnnotationOverWholeDocument() { init("<p>abcdef</p>"); doc.setAnnotation(0, doc.size(), "style/color", "flim"); assertOperationResult( "<?a \"style/color\"=\"flim\"?><p>abcdef</p><?a \"style/color\"?>"); }
/** Test adding an annotation over the whole document */ public void testSetAnnotationOverWholeDocument() { init("<p>abcdef</p>"); doc.setAnnotation(0, doc.size(), "style/color", "flim"); assertOperationResult( "<?a \"style/color\"=\"flim\"?><p>abcdef</p><?a \"style/color\"?>"); }
/** * Test that trying to add an annotation with an end past the size throws * an IndexOutOfBoundsException. */ public void testSetAnnotationPastDocEndThrowsException() throws Exception { init("<p>abcdef</p>"); try { doc.setAnnotation(1, doc.size() + 1, "style/color", "frub"); // Doh - no exception thrown. Fail the test fail(); } catch (IndexOutOfBoundsException iae) { // expected } }
/** * Test that trying to add an annotation with an end past the size throws * an IndexOutOfBoundsException. */ public void testSetAnnotationPastDocEndThrowsException() throws Exception { init("<p>abcdef</p>"); try { doc.setAnnotation(1, doc.size() + 1, "style/color", "frub"); // Doh - no exception thrown. Fail the test fail(); } catch (IndexOutOfBoundsException iae) { // expected } }
/** Test a simple set and reset annotation */ public void testSetAndResetAnnotation() { init("<p>abcdef</p>"); doc.setAnnotation(0, doc.size(), "style/color", "pato"); doc.resetAnnotation(3, 6, "style/color", "pato"); assertOperationResult( "<p>ab<?a \"style/color\"=\"pato\"?>cde<?a \"style/color\"?>f</p>"); }
/** Test a simple set and reset annotation */ public void testSetAndResetAnnotation() { init("<p>abcdef</p>"); doc.setAnnotation(0, doc.size(), "style/color", "pato"); doc.resetAnnotation(3, 6, "style/color", "pato"); assertOperationResult( "<p>ab<?a \"style/color\"=\"pato\"?>cde<?a \"style/color\"?>f</p>"); }
@Override public Range deleteRange(int start, int end) { Preconditions.checkPositionIndexes(start, end, size()); // TODO(davidbyttow/danilatos): Handle this more efficiently. PointRange<N> range = deleteRange(doc.locate(start), doc.locate(end)); return new Range(doc.getLocation(range.getFirst()), doc.getLocation(range.getSecond())); }
/** Test a simple set and unset of an annotation */ public void testSetAndUnsetAnnotation() { init("<p>abcdef</p>"); doc.setAnnotation(3, 6, "style/color", "maisy"); doc.setAnnotation(0, doc.size(), "style/color", null); assertOperationResult("<p>abcdef</p>"); }
/** Test a simple set and unset of an annotation */ public void testSetAndUnsetAnnotation() { init("<p>abcdef</p>"); doc.setAnnotation(3, 6, "style/color", "maisy"); doc.setAnnotation(0, doc.size(), "style/color", null); assertOperationResult("<p>abcdef</p>"); }
annos.add(new RangedValue<String>(2, 4, "cyril")); annos.add(new RangedValue<String>(5, 6, "tallulah")); doc.resetAnnotationsInRange(0, doc.size(), "style/color", annos); assertOperationResult( "<p>a<?a \"style/color\"=\"cyril\"?>bc<?a \"style/color\"?>d" +
annos.add(new RangedValue<String>(2, 4, "cyril")); annos.add(new RangedValue<String>(5, 6, "tallulah")); doc.resetAnnotationsInRange(0, doc.size(), "style/color", annos); assertOperationResult( "<p>a<?a \"style/color\"=\"cyril\"?>bc<?a \"style/color\"?>d" +
/** * Test that using a zero range reset annotation clears the annotation over * the whole document. */ public void testZeroRangeResetAnnotationClearsDocument() { init("<p>abcdef</p>"); doc.setAnnotation(1, 4, "style/color", "spot"); doc.resetAnnotation(0, 0, "style/color", "spot"); assertOperationResult("<p>abcdef</p>"); init("<p>abcdef</p>"); doc.setAnnotation(1, 4, "style/color", "spot"); doc.resetAnnotation(2, 2, "style/color", "spot"); assertOperationResult("<p>abcdef</p>"); init("<p>abcdef</p>"); doc.setAnnotation(1, 4, "style/color", "spot"); doc.resetAnnotation(doc.size(), doc.size(), "style/color", "spot"); assertOperationResult("<p>abcdef</p>"); }
/** * Test that using a zero range reset annotation clears the annotation over * the whole document. */ public void testZeroRangeResetAnnotationClearsDocument() { init("<p>abcdef</p>"); doc.setAnnotation(1, 4, "style/color", "spot"); doc.resetAnnotation(0, 0, "style/color", "spot"); assertOperationResult("<p>abcdef</p>"); init("<p>abcdef</p>"); doc.setAnnotation(1, 4, "style/color", "spot"); doc.resetAnnotation(2, 2, "style/color", "spot"); assertOperationResult("<p>abcdef</p>"); init("<p>abcdef</p>"); doc.setAnnotation(1, 4, "style/color", "spot"); doc.resetAnnotation(doc.size(), doc.size(), "style/color", "spot"); assertOperationResult("<p>abcdef</p>"); }