public void testDeleteRangeIndices() { String str = "123<b>asdf</b>34<x/>5"; init(str); for (int i = 0; i <= 14; i++) { assertCollapsedAt(i, doc.deleteRange(i, i)); assertResult(str); } // delete start or end tag does nothing assertRangeAt(3, 4, doc.deleteRange(3, 4)); assertResult(str); assertRangeAt(8, 9, doc.deleteRange(8, 9)); assertResult(str); // text only init("12345678"); assertCollapsedAt(1, doc.deleteRange(1, 3)); // middle assertResult("145678"); assertCollapsedAt(0, doc.deleteRange(0, 1)); // start assertResult("45678"); assertCollapsedAt(3, doc.deleteRange(3, 5)); // end assertResult("456"); assertCollapsedAt(0, doc.deleteRange(0, 3)); // all assertResult(""); }
protected void assertRangeAt( int start, int end, PointRange<Node> actual) { PointRange<Node> expected = new PointRange<Node>(l(start), l(end)); assertEquals(expected, actual); }
/** Test a simple set annotation */ public void testSetAnnotation() { init("<p>abcdef</p>"); doc.setAnnotation(3, 6, "style/color", "stix"); assertOperationResult( "<p>ab<?a \"style/color\"=\"stix\"?>cde<?a \"style/color\"?>f</p>"); }
/** * Test that trying to add an annotation with a negative range throws * an IndexOutOfBoundsException. */ public void testNegativeRangeSetAnnotationThrowsException() throws Exception { init("<p>abcdef</p>"); try { doc.setAnnotation(4, 1, "style/color", "slarken"); // Doh - no exception thrown. Fail the test fail(); } catch (IndexOutOfBoundsException iae) { // expected } }
init("<p>abcdef</p>"); LinkedList<RangedValue<String>> annos = new LinkedList<RangedValue<String>>(); 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" + "<?a \"style/color\"=\"tallulah\"?>e<?a \"style/color\"?>f</p>"); fail();
/** * Test basic get attribute. */ public void testGetAttributes() { init("<p t=\"0\" s=\"hi\">hello</p>"); Element e = (Element) doc.getFirstChild(doc.getDocumentElement()); assertEquals("0", doc.getAttribute(e, "t")); assertEquals("hi", doc.getAttribute(e, "s")); }
protected void assertRangeAt( int start, int end, Range actual) { assertEquals(start, actual.getStart()); assertEquals(end, actual.getEnd()); }
/** * Test that trying to reset an annotation with a negative start throws * an IndexOutOfBoundsException. */ public void testNegativeStartResetAnnotationThrowsException() throws Exception { init("<p>abcdef</p>"); try { doc.resetAnnotation(-1, 4, "style/color", "frub"); // Doh - no exception thrown. Fail the test assert false; } catch (IndexOutOfBoundsException iae) { // expected } }
/** Init document state */ protected void init(String initialContent) { indexed = DocProviders.POJO.parse(initialContent); // Get a mutable doc view of our target and hook it up with the // "remote" document as the sink of outgoing ops. doc = new MutableDocumentImpl<Node, Element, Text>( createSequencer(indexed), indexed); }
init("<p>abcdef</p>"); LinkedList<RangedValue<String>> annos = new LinkedList<RangedValue<String>>(); 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" + "<?a \"style/color\"=\"tallulah\"?>e<?a \"style/color\"?>f</p>"); fail();
/** * Test basic get attribute. */ public void testGetAttributes() { init("<p t=\"0\" s=\"hi\">hello</p>"); Element e = (Element) doc.getFirstChild(doc.getDocumentElement()); assertEquals("0", doc.getAttribute(e, "t")); assertEquals("hi", doc.getAttribute(e, "s")); }
/** * Test that trying to add an annotation with a negative range throws * an IndexOutOfBoundsException. */ public void testNegativeRangeSetAnnotationThrowsException() throws Exception { init("<p>abcdef</p>"); try { doc.setAnnotation(4, 1, "style/color", "slarken"); // Doh - no exception thrown. Fail the test fail(); } catch (IndexOutOfBoundsException iae) { // expected } }
protected void assertRangeAt( int start, int end, Range actual) { assertEquals(start, actual.getStart()); assertEquals(end, actual.getEnd()); }
/** * Test that trying to add an annotation with a negative start throws * an IndexOutOfBoundsException. */ public void testNegativeStartSetAnnotationThrowsException() throws Exception { init("<p>abcdef</p>"); try { doc.setAnnotation(-1, 4, "style/color", "frub"); // Doh - no exception thrown. Fail the test assert false; } catch (IndexOutOfBoundsException iae) { // expected } }
/** Init document state */ protected void init(String initialContent) { indexed = DocProviders.POJO.parse(initialContent); // Get a mutable doc view of our target and hook it up with the // "remote" document as the sink of outgoing ops. doc = new MutableDocumentImpl<Node, Element, Text>( createSequencer(indexed), indexed); }
public void testDeleteRangeIndices() { String str = "123<b>asdf</b>34<x/>5"; init(str); for (int i = 0; i <= 14; i++) { assertCollapsedAt(i, doc.deleteRange(i, i)); assertResult(str); } // delete start or end tag does nothing assertRangeAt(3, 4, doc.deleteRange(3, 4)); assertResult(str); assertRangeAt(8, 9, doc.deleteRange(8, 9)); assertResult(str); // text only init("12345678"); assertCollapsedAt(1, doc.deleteRange(1, 3)); // middle assertResult("145678"); assertCollapsedAt(0, doc.deleteRange(0, 1)); // start assertResult("45678"); assertCollapsedAt(3, doc.deleteRange(3, 5)); // end assertResult("456"); assertCollapsedAt(0, doc.deleteRange(0, 3)); // all assertResult(""); }
/** Test a simple reset annotation */ public void testResetAnnotation() { init("<p>abcdef</p>"); doc.resetAnnotation(3, 6, "style/color", "pocoyo"); assertOperationResult( "<p>ab<?a \"style/color\"=\"pocoyo\"?>cde<?a \"style/color\"?>f</p>"); }
init("<p>23456789</p>"); LinkedList<RangedValue<String>> annos = new LinkedList<RangedValue<String>>(); doc.setAnnotation(1, 2, "style/color", "marv"); annos.add(new RangedValue<String>(3, 6, "eddie")); doc.resetAnnotationsInRange(1, 8, "style/color", annos); assertOperationResult( "<p>" + "<?a \"style/color\"=\"marv\"?>2<?a \"style/color\"?>" + "</p>"); fail();
protected void assertRangeAt( int start, int end, PointRange<Node> actual) { PointRange<Node> expected = new PointRange<Node>(l(start), l(end)); assertEquals(expected, actual); }
/** * Test set attribute overrides and removes old attributes, as opposed to * update. */ public void testSetAttributes() { init("<p t=\"0\" s=\"hi\">hello</p>"); Element e = (Element) doc.getFirstChild(doc.getDocumentElement()); doc.setElementAttributes(e, new AttributesImpl("just", "this")); assertEquals(null, doc.getAttribute(e, "t")); assertEquals(null, doc.getAttribute(e, "s")); assertEquals("this", doc.getAttribute(e, "just")); }