Skip to content

Commit

Permalink
add test for setDefaultStyle()
Browse files Browse the repository at this point in the history
  • Loading branch information
koentsje committed Apr 5, 2014
1 parent 5da448e commit c1e67f3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void setDefaultStyle() {
StyleRange styleRange = defaultStyle.getStyleRange();
styleRange.start = delegateDocument.getLength();
styleRange.length = 0;
setCurrentStyle(defaultStyle);
setCurrentStyle(new StyleImpl(styleRange));
}

public Document getDelegate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class StyleImpl implements Style {

private StyleRange styleRange;
StyleRange styleRange;

public StyleImpl(StyleRange styleRange) {
this.styleRange = styleRange;
Expand Down Expand Up @@ -209,6 +209,10 @@ public int getLength() {
return styleRange.length;
}

public int getStart() {
return styleRange.start;
}

private void reverseVideo() {
Color foreground = styleRange.foreground;
Color background = styleRange.background;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.swt.custom.StyleRange;
import org.jboss.tools.aesh.core.document.Style;
import org.jboss.tools.aesh.ui.internal.util.ColorConstants;
import org.jboss.tools.aesh.ui.internal.util.FontManager;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -101,4 +104,23 @@ public void testGetLenght() {
Assert.assertEquals(4, documentImpl.getLength());
}

@Test
public void testSetDefaultStyle() {
documentImpl.delegateDocument = testDocument;
StyleRange oldRange = new StyleRange(0, 0, ColorConstants.BLUE, ColorConstants.CYAN);
oldRange.font = FontManager.INSTANCE.getItalicBold();
StyleImpl oldStyle = new StyleImpl(oldRange);
documentImpl.currentStyle = oldStyle;
Assert.assertEquals(0, oldStyle.getLength());
Assert.assertEquals(0, oldStyle.getStart());
testDocument.set("blah");
documentImpl.setDefaultStyle();
StyleImpl newStyle = documentImpl.currentStyle;
Assert.assertEquals(0, newStyle.getLength());
Assert.assertEquals(4, newStyle.getStart());
Assert.assertEquals(ColorConstants.BLACK, newStyle.styleRange.foreground);
Assert.assertEquals(ColorConstants.WHITE, newStyle.styleRange.background);
Assert.assertEquals(FontManager.INSTANCE.getDefault(), newStyle.styleRange.font);
}

}

0 comments on commit c1e67f3

Please sign in to comment.