Skip to content

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbylight committed Jun 22, 2024
1 parent cab6506 commit fbfcd8c
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void testMxml_actionScript_chars_invalid() {
assertAllTokensOfType(TokenTypes.ERROR_CHAR,
MxmlTokenMaker.INTERNAL_IN_AS,
"'c",
"'\\uff07"
"'\\uff07",
"'\\ufffx'"
);
}

Expand Down Expand Up @@ -124,6 +125,24 @@ void testMxml_actionScript_endScriptTag() {
}


@Test
void testMxml_actionScript_endTag() {

String code = "</body>";
Segment segment = createSegment(code);
TokenMaker tm = createTokenMaker();

Token token = tm.getTokenList(segment, 0, 0);
Assertions.assertTrue(token.is(TokenTypes.MARKUP_TAG_DELIMITER, "</"));

token = token.getNextToken();
Assertions.assertTrue(token.is(TokenTypes.MARKUP_TAG_NAME, "body"));

token = token.getNextToken();
Assertions.assertTrue(token.is(TokenTypes.MARKUP_TAG_DELIMITER, ">"));
}


@Test
void testMxml_actionScript_eolComments() {
assertAllTokensOfType(TokenTypes.COMMENT_EOL,
Expand All @@ -136,7 +155,7 @@ void testMxml_actionScript_eolComments() {
void testMxml_actionScript_eolComments_url() {

String[] eolCommentLiterals = {
"// Hello world https://www.google.com",
"// Hello world https://www.google.com trailing text",
};

for (String code : eolCommentLiterals) {
Expand All @@ -152,6 +171,8 @@ void testMxml_actionScript_eolComments_url() {
Assertions.assertEquals(TokenTypes.COMMENT_EOL, token.getType());
Assertions.assertEquals("https://www.google.com", token.getLexeme());

token = token.getNextToken();
Assertions.assertTrue(token.is(TokenTypes.COMMENT_EOL, " trailing text"));
}

}
Expand Down Expand Up @@ -599,6 +620,7 @@ void testMxml_doctype() {
"<!doctype html>",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">",
"<!DOCTYPE note [ xxx ]>",
};

for (String code : doctypes) {
Expand All @@ -611,6 +633,16 @@ void testMxml_doctype() {
}


@Test
void testMXML_doctype_continuedFromPriorLine() {
assertAllTokensOfType(TokenTypes.MARKUP_DTD,
TokenTypes.MARKUP_DTD,
"continued from prior line unterminated",
"continued from prior line>"
);
}


@Test
void testMxml_entityReferences() {
assertAllTokensOfType(TokenTypes.MARKUP_ENTITY_REFERENCE,
Expand All @@ -619,6 +651,18 @@ void testMxml_entityReferences() {
}


@Test
void testXML_getSetCompleteCloseTags() {
try {
Assertions.assertTrue(MxmlTokenMaker.getCompleteCloseMarkupTags());
MxmlTokenMaker.setCompleteCloseTags(false);
Assertions.assertFalse(MxmlTokenMaker.getCompleteCloseMarkupTags());
} finally {
MxmlTokenMaker.setCompleteCloseTags(true);
}
}


@Test
void testMxml_happyPath_tagWithAttributes() {

Expand Down Expand Up @@ -652,6 +696,80 @@ void testMxml_happyPath_tagWithAttributes() {
}


@Test
void testMXML_inAttrDouble() {
assertAllTokensOfType(TokenTypes.MARKUP_TAG_ATTRIBUTE_VALUE,
MxmlTokenMaker.INTERNAL_ATTR_DOUBLE,
"continued to next line",
"ends on this line\""
);
}


@Test
void testMXML_inAttrDouble_scriptTag() {
assertAllTokensOfType(TokenTypes.MARKUP_TAG_ATTRIBUTE_VALUE,
MxmlTokenMaker.INTERNAL_ATTR_DOUBLE_QUOTE_SCRIPT,
"continued to next line",
"ends on this line\""
);
}


@Test
void testMXML_inAttrSingle() {
assertAllTokensOfType(TokenTypes.MARKUP_TAG_ATTRIBUTE_VALUE,
MxmlTokenMaker.INTERNAL_ATTR_SINGLE,
"continued to next line",
"ends on this line'"
);
}


@Test
void testMXML_inAttrSingle_scriptTag() {
assertAllTokensOfType(TokenTypes.MARKUP_TAG_ATTRIBUTE_VALUE,
MxmlTokenMaker.INTERNAL_ATTR_SINGLE_QUOTE_SCRIPT,
"continued to next line",
"ends on this line'"
);
}


@Test
void testMXML_inProcessingInstruction() {
assertAllTokensOfType(TokenTypes.MARKUP_PROCESSING_INSTRUCTION,
TokenTypes.MARKUP_PROCESSING_INSTRUCTION,
"continued to next line",
"ends on this line ?>"
);
}


@Test
void testMXML_inTag_attributeNames() {
assertAllTokensOfType(TokenTypes.MARKUP_TAG_ATTRIBUTE,
MxmlTokenMaker.INTERNAL_INTAG,
"foo",
"value123",
"cszčšž",
"xmlns:cszčšž"
);
}


@Test
void testMXML_inTagScript_attributeNames() {
assertAllTokensOfType(TokenTypes.MARKUP_TAG_ATTRIBUTE,
MxmlTokenMaker.INTERNAL_INTAG_SCRIPT,
"foo",
"value123",
"cszčšž",
"xmlns:cszčšž"
);
}


@Test
void testMxml_processingInstructions() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void testXML_doctype() {
"<!doctype html>",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">",
"<!DOCTYPE note [ xxx ]>",
};

for (String code : doctypes) {
Expand All @@ -154,6 +155,26 @@ void testXML_doctype() {
}


@Test
void testXML_doctype_continuedFromPriorLine() {
assertAllTokensOfType(TokenTypes.MARKUP_DTD,
XMLTokenMaker.INTERNAL_DTD,
"continued from prior line unterminated",
"continued from prior line>"
);
}


@Test
void testXML_doctypeInternal_continuedFromPriorLine() {
assertAllTokensOfType(TokenTypes.MARKUP_DTD,
XMLTokenMaker.INTERNAL_DTD_INTERNAL,
"continued from prior line unterminated",
"continued from prior line]>"
);
}


@Test
void testXML_entityReferences() {

Expand All @@ -171,6 +192,18 @@ void testXML_entityReferences() {
}


@Test
void testXML_getSetCompleteCloseTags() {
try {
Assertions.assertTrue(XMLTokenMaker.getCompleteCloseMarkupTags());
XMLTokenMaker.setCompleteCloseTags(false);
Assertions.assertFalse(XMLTokenMaker.getCompleteCloseMarkupTags());
} finally {
XMLTokenMaker.setCompleteCloseTags(true);
}
}


@Test
void testXML_happyPath_tagWithAttributes() {

Expand Down Expand Up @@ -246,6 +279,18 @@ void testXML_inTag_attributeNames() {
}


@Test
void testXML_inTagScript_attributeNames() {
assertAllTokensOfType(TokenTypes.MARKUP_TAG_ATTRIBUTE,
XMLTokenMaker.INTERNAL_INTAG,
"foo",
"value123",
"cszčšž",
"xmlns:cszčšž"
);
}


@Test
void testXML_openingTag_tagNames() {
String[] openingTags = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.swing.event.HyperlinkListener;

import org.fife.ui.rsyntaxtextarea.*;
import org.fife.ui.rsyntaxtextarea.parser.ParserNotice;
import org.fife.ui.rtextarea.FoldIndicatorStyle;
import org.fife.ui.rtextarea.Gutter;
import org.fife.ui.rtextarea.RTextScrollPane;
Expand Down Expand Up @@ -52,7 +53,17 @@ public class DemoRootPane extends JRootPane implements HyperlinkListener,
URL url = getClass().getResource("bookmark.png");
gutter.setBookmarkIcon(new ImageIcon(url));
getContentPane().add(scrollPane);
ErrorStrip errorStrip = new ErrorStrip(textArea);
ErrorStrip errorStrip = new ErrorStrip(textArea) {
protected void paintParserNoticeMarker(Graphics2D g, ParserNotice notice, int width, int height) {
GradientPaint paint = new GradientPaint(
0, 0, Color.RED,
width, height, Color.GREEN);

g.setPaint(paint);
g.fillOval(0, 0, width, height);
// g.fillRect(0,0, width,height);
}
};
//errorStrip.setBackground(java.awt.Color.blue);
getContentPane().add(errorStrip, BorderLayout.LINE_END);
setJMenuBar(createMenuBar());
Expand Down

0 comments on commit fbfcd8c

Please sign in to comment.