/** * Returns the default document used by <code>RSyntaxTextArea</code>s. * * @return The document. */ @Override public Document createDefaultDocument() { return new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_NONE); }
/** * Returns the document to use for an <code>RSyntaxTextArea</code>. * * @return The document. */ @Override protected Document createDefaultModel() { return new RSyntaxDocument(SYNTAX_STYLE_NONE); }
@Test public void test1ArgConstructor() { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_JAVA; doc = new RSyntaxDocument(syntaxStyle); //Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); }
@Test public void testIterator() { // Not much to test here String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertNotNull(doc.iterator()); }
@Test public void testGetOccurrenceMarker() { // Not really much we can test here String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertNotNull(doc.getOccurrenceMarker()); }
@Test(expected = IndexOutOfBoundsException.class) public void testGetLastTokenTypeOnLine_InvalidIndex() throws Exception { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); insertHelloWorldC(doc); Assert.assertEquals(TokenTypes.NULL, doc.getLastTokenTypeOnLine(1000)); }
@Test public void testGetPreviousWord_manyLinesInBetween() throws Exception { DumbCompleteWordAction action = new DumbCompleteWordAction(); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_JAVA); RSyntaxTextArea textArea = new RSyntaxTextArea(doc); textArea.setText("aaron arthur aardvark\nfoo bar\n// bad code\namazing\n a"); Assert.assertEquals(textArea.getDocument().getLength()-1, action.getPreviousWord(textArea, textArea.getDocument().getLength())); Assert.assertEquals("aaron arthur aardvark\nfoo bar\n// bad code\n".length(), action.getPreviousWord(textArea, textArea.getDocument().getLength()-2)); Assert.assertEquals("aaron arthur ".length(), action.getPreviousWord(textArea, 22)); Assert.assertEquals("aaron ".length(), action.getPreviousWord(textArea, 8)); }
@Test public void testGetMarkOccurrencesOfTokenType() { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertTrue(doc.getMarkOccurrencesOfTokenType(TokenTypes.IDENTIFIER)); Assert.assertFalse(doc.getMarkOccurrencesOfTokenType(TokenTypes.COMMENT_EOL)); }
@Test public void testParse_emptyDocument() throws Exception { XmlParser parser = new XmlParser(); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_XML); ParseResult res = parser.parse(doc, doc.getSyntaxStyle()); assertCleanParseResult_oneLineDocument(parser, res); }
@Test public void testGetClosestStandardTokenTypeForInternalType() throws Exception { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT; doc = new RSyntaxDocument(syntaxStyle); JavaScriptTokenMaker tokenMaker = new JavaScriptTokenMaker(); for (int i=0; i<TokenTypes.DEFAULT_NUM_TOKEN_TYPES; i++) { int expected = tokenMaker.getClosestStandardTokenTypeForInternalType(i); int actual = doc.getClosestStandardTokenTypeForInternalType(i); Assert.assertEquals(expected, actual); } }
@Test public void testIsIdentifierChar() { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertTrue(doc.isIdentifierChar(0, 'a')); Assert.assertFalse(doc.isIdentifierChar(0, '%')); }
@Test public void testParse_happyPath() throws Exception { XmlParser parser = new XmlParser(); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_XML); doc.insertString(0, "<?xml version='1.0'?><books></books>", null); ParseResult res = parser.parse(doc, doc.getSyntaxStyle()); assertCleanParseResult_oneLineDocument(parser, res); }
@Test public void testInsertBreakSpecialHandling() { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertTrue(doc.insertBreakSpecialHandling(null)); // Language that does not use curly braces syntaxStyle = SyntaxConstants.SYNTAX_STYLE_XML; doc.setSyntaxStyle(syntaxStyle); Assert.assertFalse(doc.insertBreakSpecialHandling(null)); }
@Test public void testGetLanguageIsMarkup() { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertFalse(doc.getLanguageIsMarkup()); // Language that does not use curly braces syntaxStyle = SyntaxConstants.SYNTAX_STYLE_XML; doc.setSyntaxStyle(syntaxStyle); Assert.assertTrue(doc.getLanguageIsMarkup()); }
@Test public void testSetSyntaxStyle_CustomTokenMaker() { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); TokenMaker tokenMaker = new HTMLTokenMaker(); doc.setSyntaxStyle(tokenMaker); Assert.assertNotEquals(syntaxStyle, doc.getSyntaxStyle()); }
@Test public void testGetLastTokenTypeOnLine() throws Exception { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); insertHelloWorldC(doc); Assert.assertEquals(TokenTypes.NULL, doc.getLastTokenTypeOnLine(0)); Assert.assertEquals(TokenTypes.COMMENT_MULTILINE, doc.getLastTokenTypeOnLine(1)); Assert.assertEquals(TokenTypes.NULL, doc.getLastTokenTypeOnLine(2)); }
@Test public void testActionPerformed_dollarSignImportant() throws Exception { RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT); RSyntaxTextArea textArea = new RSyntaxTextArea(doc); DumbCompleteWordAction action = getDumbCompleteWordAction(textArea); textArea.setText("$routeProvider routeSkip $ro"); action.actionPerformed(createActionEvent(textArea)); String actual = textArea.getText(); Assert.assertEquals("$routeProvider routeSkip $routeProvider", actual); }
@Test public void testGetSyntaxStyle() { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); syntaxStyle = SyntaxConstants.SYNTAX_STYLE_XML; doc.setSyntaxStyle(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); syntaxStyle = "text/custom"; doc.setSyntaxStyle(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); }
@Test public void testSetSyntaxStyle() { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); syntaxStyle = SyntaxConstants.SYNTAX_STYLE_XML; doc.setSyntaxStyle(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); syntaxStyle = "text/custom"; doc.setSyntaxStyle(syntaxStyle); Assert.assertEquals(syntaxStyle, doc.getSyntaxStyle()); }
@Test public void testGetShouldIndentNextLine() throws Exception { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); insertHelloWorldC(doc); Assert.assertFalse(doc.getShouldIndentNextLine(0)); Assert.assertFalse(doc.getShouldIndentNextLine(1)); Assert.assertFalse(doc.getShouldIndentNextLine(2)); Assert.assertFalse(doc.getShouldIndentNextLine(3)); Assert.assertTrue(doc.getShouldIndentNextLine(4)); }