public void testShift() throws Exception { Annotation annotation = new Annotation("key", "value", 5 , 10); annotation.shift(4, 2); assertEquals(7, annotation.getRange().getStart()); assertEquals(12, annotation.getRange().getEnd()); annotation = new Annotation("key", "value", 5 , 10); annotation.shift(5, 3); assertEquals(8, annotation.getRange().getStart()); assertEquals(13, annotation.getRange().getEnd()); annotation = new Annotation("key", "value", 5 , 10); annotation.shift(9, 2); assertEquals(5, annotation.getRange().getStart()); assertEquals(12, annotation.getRange().getEnd()); annotation = new Annotation("key", "value", 5 , 10); annotation.shift(10, 2); assertEquals(5, annotation.getRange().getStart()); assertEquals(12, annotation.getRange().getEnd()); } }
public void testInsertBeforeAnnotationStartPoint() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 4, 9))); blip.at(4).insert("d and"); assertEquals(new Range(9, 14), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testInsertBeforeAnnotationStartPoint() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 4, 9))); blip.at(4).insert("d and"); assertEquals(new Range(9, 14), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testShift() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 1, 3); annotations.add("name2", "value", 3, 5); annotations.add("name2", "value", 10, 15); annotations.shift(2, 3); assertEquals(new Range(1, 6), annotations.get("name").get(0).getRange()); assertEquals(new Range(6, 8), annotations.get("name2").get(0).getRange()); assertEquals(new Range(13, 18), annotations.get("name2").get(1).getRange()); annotations = new Annotations(); annotations.add("name", "value", 1, 3); annotations.add("name", "value", 5, 8); annotations.shift(5, -2); assertEquals(1, annotations.get("name").size()); assertEquals(new Range(1, 6), annotations.get("name").get(0).getRange()); } }
public void testShift() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 1, 3); annotations.add("name2", "value", 3, 5); annotations.add("name2", "value", 10, 15); annotations.shift(2, 3); assertEquals(new Range(1, 6), annotations.get("name").get(0).getRange()); assertEquals(new Range(6, 8), annotations.get("name2").get(0).getRange()); assertEquals(new Range(13, 18), annotations.get("name2").get(1).getRange()); annotations = new Annotations(); annotations.add("name", "value", 1, 3); annotations.add("name", "value", 5, 8); annotations.shift(5, -2); assertEquals(1, annotations.get("name").size()); assertEquals(new Range(1, 6), annotations.get("name").get(0).getRange()); } }
public void testAdd() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 3, 5); assertEquals(1, annotations.get("name").size()); annotations.add("name", "value", 1, 2); annotations.add("name", "value", 10, 15); assertEquals(3, annotations.get("name").size()); annotations.add("name", "value", 4, 7); assertEquals(3, annotations.get("name").size()); assertEquals(new Range(3, 7), annotations.get("name").get(2).getRange()); annotations.add("name", "value2", 6, 7); assertEquals(4, annotations.get("name").size()); assertEquals(new Range(3, 6), annotations.get("name").get(2).getRange()); assertEquals("value", annotations.get("name").get(2).getValue()); assertEquals(new Range(6, 7), annotations.get("name").get(3).getRange()); assertEquals("value2", annotations.get("name").get(3).getValue()); }
public void testAdd() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 3, 5); assertEquals(1, annotations.get("name").size()); annotations.add("name", "value", 1, 2); annotations.add("name", "value", 10, 15); assertEquals(3, annotations.get("name").size()); annotations.add("name", "value", 4, 7); assertEquals(3, annotations.get("name").size()); assertEquals(new Range(3, 7), annotations.get("name").get(2).getRange()); annotations.add("name", "value2", 6, 7); assertEquals(4, annotations.get("name").size()); assertEquals(new Range(3, 6), annotations.get("name").get(2).getRange()); assertEquals("value", annotations.get("name").get(2).getValue()); assertEquals(new Range(6, 7), annotations.get("name").get(3).getRange()); assertEquals("value2", annotations.get("name").get(3).getValue()); }
/** * Copies the content of the source blip into the target blip. * * @param fromBlip the source blip. * @param toBlip the target blip. */ public static void copyBlipContents(Blip fromBlip, Blip toBlip) { for (BlipContent blipContent: fromBlip.all().values()) { toBlip.append(blipContent); } for (Annotation annotation : fromBlip.getAnnotations()) { Range range = annotation.getRange(); toBlip.range(range.getStart() + 1, range.getEnd() + 1).annotate(annotation.getName(), annotation.getValue()); } }
public void testDeleteRangeThatSpansAcrossAnnotationEndPoint() throws Exception { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 3))); // Delete "oo" blip.range(2, 4).delete(); assertEquals("\nF bar.", blip.getContent()); assertEquals(new Range(1, 2), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testReplaceSpanAnnotation() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 4))); // Replace "oo bar." with "". blip.range(2, 9).replace(""); assertEquals("\nF", blip.getContent()); assertEquals(new Range(1, 2), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testDeleteRangeThatSpansAcrossAnnotationEndPoint() throws Exception { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 3))); // Delete "oo" blip.range(2, 4).delete(); assertEquals("\nF bar.", blip.getContent()); assertEquals(new Range(1, 2), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testReplaceSpanAnnotation() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 4))); // Replace "oo bar." with "". blip.range(2, 9).replace(""); assertEquals("\nF", blip.getContent()); assertEquals(new Range(1, 2), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testDeleteRangeInsideAnnotation() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 5))); // Delete "oo" blip.range(2, 4).delete(); assertEquals("\nF bar.", blip.getContent()); assertEquals(new Range(1, 3), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testReplaceInsideAnnotation() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 5))); // Replace "oo" with "ooo". blip.range(2, 4).replace("ooo"); assertEquals("\nFooo bar.", blip.getContent()); assertEquals(new Range(1, 6), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); // Replace "ooo" with "o". blip.range(2, 5).replace("o"); assertEquals("\nFo bar.", blip.getContent()); assertEquals(new Range(1, 4), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testReplaceInsideAnnotation() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 5))); // Replace "oo" with "ooo". blip.range(2, 4).replace("ooo"); assertEquals("\nFooo bar.", blip.getContent()); assertEquals(new Range(1, 6), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); // Replace "ooo" with "o". blip.range(2, 5).replace("o"); assertEquals("\nFo bar.", blip.getContent()); assertEquals(new Range(1, 4), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testDeleteRangeInsideAnnotation() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 5))); // Delete "oo" blip.range(2, 4).delete(); assertEquals("\nF bar.", blip.getContent()); assertEquals(new Range(1, 3), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testDelete() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 1, 2); annotations.add("name2", "value", 3, 5); annotations.add("name2", "value", 10, 15); annotations.delete("name", 2, 3); assertEquals(1, annotations.get("name").size()); annotations.delete("name", 1, 2); assertNull(annotations.get("name")); annotations.delete("name2", 1, 6); assertEquals(1, annotations.get("name2").size()); annotations.delete("name2", 10, 12); assertEquals(1, annotations.get("name2").size()); assertEquals(new Range(12, 15), annotations.get("name2").get(0).getRange()); }
public void testDelete() throws Exception { Annotations annotations = new Annotations(); annotations.add("name", "value", 1, 2); annotations.add("name2", "value", 3, 5); annotations.add("name2", "value", 10, 15); annotations.delete("name", 2, 3); assertEquals(1, annotations.get("name").size()); annotations.delete("name", 1, 2); assertNull(annotations.get("name")); annotations.delete("name2", 1, 6); assertEquals(1, annotations.get("name2").size()); annotations.delete("name2", 10, 12); assertEquals(1, annotations.get("name2").size()); assertEquals(new Range(12, 15), annotations.get("name2").get(0).getRange()); }