@Test public void rotateForward_BufferWithTwoElement_FirstElementAdded() { KillRing killRing = new KillRing(); killRing.addElt("Test1"); killRing.addElt("Test2"); assertThat(killRing.currentElt(), is(equalTo("Test2"))); killRing.rotateForward(); assertThat(killRing.currentElt(), is(equalTo("Test1"))); }
public void contentRemoved(int offset, int length, String text, boolean clearDirty) { Edit last = getLastEdit(); Edit toMerge = getMergeEdit(); if (!clearDirty && toMerge instanceof Remove && redosFirst == null) { Remove rem = (Remove) toMerge; if (rem.offset == offset) { rem.content.str = rem.content.str.concat(text); rem.content.hashcode = rem.content.str.hashCode(); rem.length += length; KillRing.getInstance().changed(rem.content); return; } else if (offset + length == rem.offset) { rem.content.str = text.concat(rem.content.str); rem.content.hashcode = rem.content.str.hashCode(); rem.length += length; rem.offset = offset; KillRing.getInstance().changed(rem.content); return; } } Remove rem = new Remove(this, offset, length, text); if (clearDirty) { redoClearDirty = last; undoClearDirty = rem; } if (compoundEdit != null) compoundEdit.add(rem); else { reviseUndoId(); addEdit(rem); } KillRing.getInstance().add(rem.content); }
// {{{ contentRemoved() method public void contentRemoved(int offset, int length, String text, boolean clearDirty) { Edit toMerge = getMergeEdit(); if (!clearDirty && toMerge instanceof Remove && redosFirst == null) { Remove rem = (Remove) toMerge; if (rem.offset == offset) { String newStr = rem.str.concat(text); KillRing.getInstance().changed(rem.str, newStr); rem.str = newStr; return; } else if (offset + length == rem.offset) { String newStr = text.concat(rem.str); KillRing.getInstance().changed(rem.str, newStr); rem.offset = offset; rem.str = newStr; return; } } // use String.intern() here as new Strings are created in // JEditBuffer.remove() via undoMgr.contentRemoved(... getText() ...); Remove rem = new Remove(offset, text.intern()); if (clearDirty) { redoClearDirty = getLastEdit(); undoClearDirty = rem; } if (compoundEdit != null) compoundEdit.add(this, rem); else { reviseUndoId(); addEdit(rem); } KillRing.getInstance().add(rem.str); } // }}}
@Test public void currentElt_OneElement_CurrentElement() { KillRing killRing = new KillRing(); killRing.addElt("Test"); assertThat(killRing.currentElt(), is(equalTo("Test"))); }
@Test public void isEmpty_JustCreatedBuffer_True() { KillRing killRing = new KillRing(); assertThat(killRing.isEmpty(), is(true)); }
@Test public void addElt_BufferNearlyFull_NoException() { KillRing killRing = new KillRing(new LinkedList<String>(Collections.nCopies(KillRing.TAILLE_MAX - 1, "Test"))); killRing.addElt("Test"); }
@Test(expected = BufferOverflowException.class) public void addElt_BufferAlreadyFull_ThrowException() { KillRing killRing = new KillRing(new LinkedList<String>(Collections.nCopies(KillRing.TAILLE_MAX, "Test"))); killRing.addElt("Test"); }