public class TestOperations {
// The test case for the message-based implementation should also use this.
public static DocOp getBasicTestOp() {
DocOpBuffer b = new DocOpBuffer();
// The operation starts with characters/deleteCharacters of various lengths
// and case, mixed with some retains and nested element start/end with
// different mixes of attributes.
b.characters("hello");
b.characters("z");
b.retain(1);
b.deleteCharacters("ab");
b.characters("world");
b.retain(2);
b.deleteCharacters("cd");
b.elementStart("a", Attributes.EMPTY_MAP);
b.characters("hEllo");
b.elementStart("b", new AttributesImpl("a", "1"));
b.characters("world");
b.elementStart("B", new AttributesImpl("A", "1", "b", "abc12"));
b.elementEnd();
// A non-ASCII Unicode character.
b.characters("\u2603");
b.elementEnd();
b.elementEnd();
b.deleteElementStart("a", new AttributesImpl("a", "2", "c", ""));
b.deleteCharacters("asdf");
b.deleteElementEnd();
// Now some replaceAttributes with different size and case.
b.replaceAttributes(new AttributesImpl("a", "b"), new AttributesImpl("b", "c", "c", "d"));
b.replaceAttributes(Attributes.EMPTY_MAP, new AttributesImpl("Aa", "aA"));
b.replaceAttributes(new AttributesImpl("B", "A"), new AttributesImpl());
// Try both a fresh empty AttributesImpl() instance and the preallocated
// EMPTY_MAP.
b.replaceAttributes(new AttributesImpl(), Attributes.EMPTY_MAP);
// Now we add similar cases for annotation boundaries. Since consecutive annotation
// boundaries would make the operation ill-formed, we interleave them with further
// updateAttributes tests.
b.annotationBoundary(AnnotationBoundaryMapImpl.builder().build());
b.updateAttributes(new AttributesUpdateImpl());
b.annotationBoundary(AnnotationBoundaryMapImpl.builder()
.updateValues("b", "XZ", "yz", "f-", null, null,
"g-", "a", null, "k-", "b", "", "r", "", "2")
.build());
b.updateAttributes(new AttributesUpdateImpl("a", null, "1"));
b.annotationBoundary(AnnotationBoundaryMapImpl.builder()
.initializationEnd("b", "g-", "k-", "r")
.updateValues("e", "166", null, "f-", null, null)
.build());
b.updateAttributes(new AttributesUpdateImpl("P", null, "", ":wq", "ZZ", null));
b.annotationBoundary(AnnotationBoundaryMapImpl.builder()
.initializationEnd("e", "f-")
.build());
return b.finish();
}