Skip to content

Commit

Permalink
Unit test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbylight committed Oct 23, 2024
1 parent 7cf0346 commit 3f7e06d
Show file tree
Hide file tree
Showing 122 changed files with 6,720 additions and 1,044 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,17 @@ protected void yybegin(int state, int languageIndex) {
}


public abstract char yycharat(int pos);


public abstract int yylength();


public abstract void yypushback(int count);


public abstract int yystate();


public abstract String yytext();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.*;

import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
Expand Down Expand Up @@ -104,8 +100,7 @@ public synchronized CodeTemplate getTemplate(RSyntaxTextArea textArea) {
int index = Collections.binarySearch(templates, s, comparator);
return index>=0 ? templates.get(index) : null;
} catch (BadLocationException ble) {
ble.printStackTrace();
throw new InternalError("Error in CodeTemplateManager");
throw new InternalError("Error in CodeTemplateManager", ble);

Check warning on line 103 in RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/CodeTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/CodeTemplateManager.java#L103

Added line #L103 was not covered by tests
}
}

Expand Down Expand Up @@ -219,9 +214,6 @@ public synchronized void replaceTemplates(CodeTemplate[] newTemplates) {
*/
public synchronized boolean saveTemplates() {

if (templates==null) {
return true;
}
if (directory==null || !directory.isDirectory()) {
return false;
}
Expand Down Expand Up @@ -292,10 +284,13 @@ public synchronized int setTemplateDirectory(File dir) {
}
temp.add((CodeTemplate)obj);
d.close();
} catch (/*IO, NoSuchElement*/Exception e) {
} catch (IOException | ArrayIndexOutOfBoundsException | NoSuchElementException e) {
// NoSuchElementException can be thrown when reading
// an XML file not in the format expected by XMLDecoder.
// (e.g. CodeTemplates in an old format).
// ArrayIndexOutOfBoundsException is thrown by XMLDecoder
// in certain circumstances for XML that isn't an encoded
// Java object.
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.fife.ui.rtextarea.RTextAreaHighlighter.HighlightInfo;



/**
* Manages running a parser object for an <code>RSyntaxTextArea</code>.
*
Expand Down Expand Up @@ -84,7 +83,7 @@ class ParserManager implements DocumentListener, ActionListener,
/**
* Whether to print debug messages while running parsers.
*/
private static final boolean DEBUG_PARSING;
private boolean debugParsing;

/**
* The default delay between the last key press and when the document
Expand Down Expand Up @@ -113,6 +112,7 @@ class ParserManager implements DocumentListener, ActionListener,
* parsing.
*/
ParserManager(int delay, RSyntaxTextArea textArea) {
debugParsing = getDefaultDebugParsing();
this.textArea = textArea;
textArea.getDocument().addDocumentListener(this);
textArea.addPropertyChangeListener("document", this);
Expand All @@ -138,7 +138,7 @@ public void actionPerformed(ActionEvent e) {
}

long begin = 0;
if (DEBUG_PARSING) {
if (debugParsing) {
begin = System.currentTimeMillis();
}

Expand All @@ -150,7 +150,7 @@ public void actionPerformed(ActionEvent e) {
int lastLine = lastOffsetModded==null ? root.getElementCount()-1 :
root.getElementIndex(lastOffsetModded.getOffset());
firstOffsetModded = lastOffsetModded = null;
if (DEBUG_PARSING) {
if (debugParsing) {
System.out.println("[DEBUG]: Minimum lines to parse: " + firstLine + "-" + lastLine);
}

Expand All @@ -172,7 +172,7 @@ public void actionPerformed(ActionEvent e) {
doc.readUnlock();
}

if (DEBUG_PARSING) {
if (debugParsing) {
float time = (System.currentTimeMillis()-begin)/1000f;
System.out.println("Total parsing time: " + time + " seconds");
}
Expand Down Expand Up @@ -220,7 +220,7 @@ private void addParserNoticeHighlights(ParseResult res) {
return;
}

if (DEBUG_PARSING) {
if (debugParsing) {
System.out.println("[DEBUG]: Adding parser notices from " +
res.getParser());
}
Expand All @@ -238,7 +238,7 @@ private void addParserNoticeHighlights(ParseResult res) {
textArea.getHighlighter();

for (ParserNotice notice : notices) {
if (DEBUG_PARSING) {
if (debugParsing) {
System.out.println("[DEBUG]: ... adding: " + notice);
}
try {
Expand All @@ -255,7 +255,7 @@ private void addParserNoticeHighlights(ParseResult res) {

}

if (DEBUG_PARSING) {
if (debugParsing) {
System.out.println("[DEBUG]: Done adding parser notices from " +
res.getParser());
}
Expand Down Expand Up @@ -348,6 +348,18 @@ public void forceReparsing(int parser) {
}


private static boolean getDefaultDebugParsing() {
boolean debugParsing;
try {
debugParsing = Boolean.getBoolean(PROPERTY_DEBUG_PARSING);
} catch (AccessControlException ace) {

Check warning on line 355 in RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/ParserManager.java

View check run for this annotation

Codecov / codecov/patch

RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/ParserManager.java#L355

Added line #L355 was not covered by tests
// Likely an applet's security manager.
debugParsing = false; // FindBugs

Check warning on line 357 in RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/ParserManager.java

View check run for this annotation

Codecov / codecov/patch

RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/ParserManager.java#L357

Added line #L357 was not covered by tests
}
return debugParsing;
}


/**
* Returns the delay between the last "concurrent" edit and when the
* document is reparsed.
Expand Down Expand Up @@ -664,7 +676,7 @@ private void removeParserNotices(ParseResult res) {
i.remove();
removed = true;
}
if (DEBUG_PARSING) {
if (debugParsing) {
String text = removed ? "[DEBUG]: ... notice removed: " :
"[DEBUG]: ... notice not removed: ";
System.out.println(text + pair.notice);
Expand Down Expand Up @@ -716,6 +728,18 @@ public void restartParsing() {
}


/**
* Toggles whether debug information about parsing is
* written to stdout.
*
* @param debugParsing Whether debug parsing information
* is enabled.
*/
public void setDebugParsing(boolean debugParsing) {
this.debugParsing = debugParsing;
}


/**
* Sets the delay between the last "concurrent" edit and when the document
* is reparsed.
Expand Down Expand Up @@ -747,7 +771,7 @@ public void setDelay(int millis) {
private boolean shouldRemoveNotice(ParserNotice notice,
ParseResult res) {

if (DEBUG_PARSING) {
if (debugParsing) {
System.out.println("[DEBUG]: ... ... shouldRemoveNotice " +
notice + ": " + (notice.getParser()==res.getParser()));
}
Expand Down Expand Up @@ -791,16 +815,4 @@ private static class NoticeHighlightPair {
}


static {
boolean debugParsing;
try {
debugParsing = Boolean.getBoolean(PROPERTY_DEBUG_PARSING);
} catch (AccessControlException ace) {
// Likely an applet's security manager.
debugParsing = false; // FindBugs
}
DEBUG_PARSING = debugParsing;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.text.BreakIterator;
import java.text.CharacterIterator;
import java.util.ResourceBundle;
import java.util.Stack;
Expand Down Expand Up @@ -1048,7 +1049,7 @@ protected int getPreviousWord(RTextArea textArea, int offs)
}
else { // offs == start => previous word is on previous line
if (line == 0) {
return -1;
return BreakIterator.DONE;
}
elem = root.getElement(--line);
offs = elem.getEndOffset() - 1;
Expand Down Expand Up @@ -1169,6 +1170,25 @@ private static boolean isIdentifierChar(char ch) {
}


/**
* Moves the caret to the end of the document, taking into account code
* folding.
*/
public static class EndAction extends RTextAreaEditorKit.EndAction {

public EndAction(String name, boolean select) {
super(name, select);
}

@Override
protected int getVisibleEnd(RTextArea textArea) {
RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
return rsta.getLastVisibleOffset();
}

}


/**
* Positions the caret at the end of the word. This class is here to
* better handle finding the "end of the word" in programming languages.
Expand Down Expand Up @@ -1322,24 +1342,6 @@ protected Fold getClosestFold(RSyntaxTextArea textArea) {
public static class GoToMatchingBracketAction
extends RecordableTextAction {

/**
* Moves the caret to the end of the document, taking into account code
* folding.
*/
public static class EndAction extends RTextAreaEditorKit.EndAction {

public EndAction(String name, boolean select) {
super(name, select);
}

@Override
protected int getVisibleEnd(RTextArea textArea) {
RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
return rsta.getLastVisibleOffset();
}

}

private static final long serialVersionUID = 1L;

private Point bracketInfo;
Expand Down Expand Up @@ -1956,7 +1958,7 @@ protected int getNextWord(RTextArea textArea, int offs)
Element root = doc.getDefaultRootElement();
int line = root.getElementIndex(offs);
int end = root.getElement(line).getEndOffset() - 1;
if (offs==end) {// If we're already at the end of the line...
if (offs==end) { // If we're already at the end of the line...
RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
if (rsta.isCodeFoldingEnabled()) { // Start of next visible line
FoldManager fm = rsta.getFoldManager();
Expand Down Expand Up @@ -2033,34 +2035,28 @@ public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {

if (RSyntaxTextArea.getTemplatesEnabled()) {

Document doc = textArea.getDocument();
if (doc != null) {

try {

CodeTemplateManager manager = RSyntaxTextArea.
getCodeTemplateManager();
CodeTemplate template = manager==null ? null :
manager.getTemplate(rsta);

// A non-null template means modify the text to insert!
if (template!=null) {
template.invoke(rsta);
}
try {

// No template - insert default text. This is
// exactly what DefaultKeyTypedAction does.
else {
doDefaultInsert(rsta);
}
CodeTemplateManager manager = RSyntaxTextArea.
getCodeTemplateManager();
CodeTemplate template = manager==null ? null :
manager.getTemplate(rsta);

} catch (BadLocationException ble) {
UIManager.getLookAndFeel().
provideErrorFeedback(textArea);
// A non-null template means modify the text to insert!
if (template!=null) {
template.invoke(rsta);
}

// No template - insert default text. This is
// exactly what DefaultKeyTypedAction does.
else {
doDefaultInsert(rsta);
}

} // End of if (doc!=null).
} catch (BadLocationException ble) {
UIManager.getLookAndFeel().
provideErrorFeedback(textArea);

Check warning on line 2058 in RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxTextAreaEditorKit.java

View check run for this annotation

Codecov / codecov/patch

RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxTextAreaEditorKit.java#L2056-L2058

Added lines #L2056 - L2058 were not covered by tests
}

} // End of if (textArea.getTemplatesEnabled()).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void changeBaseFont(Font oldFont, Font newFont) {
for (Style style : styles) {
if (style != null && style.font != null) {
if (style.font.getFamily().equals(oldFont.getFamily()) &&
style.font.getSize() == oldFont.getSize()) {
style.font.getSize2D() == oldFont.getSize2D()) {
int styleFontStyle = style.font.getStyle(); // Keep bold or italic
style.font = newFont.deriveFont(styleFontStyle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public void keyPressed(KeyEvent e) {
}
else if (e.getKeyCode()==KeyEvent.VK_F2) {
if (tipWindow!=null && !tipWindow.getFocusableWindowState()) {
tipWindow.actionPerformed(null);
tipWindow.actionPerformed();

Check warning on line 377 in RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/focusabletip/FocusableTip.java

View check run for this annotation

Codecov / codecov/patch

RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/focusabletip/FocusableTip.java#L377

Added line #L377 was not covered by tests
e.consume(); // Don't do bookmarking stuff
}
}
Expand Down
Loading

0 comments on commit 3f7e06d

Please sign in to comment.