mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
custom file type tests -> community
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
function aaa() {<caret>
|
||||
+1
@@ -0,0 +1 @@
|
||||
var sxy = Timeline {<caret>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
var sxy = Timeline {
|
||||
<caret>
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
function aaa() {
|
||||
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
document<caret>
|
||||
+1
@@ -0,0 +1 @@
|
||||
document[<caret>]
|
||||
+1
@@ -0,0 +1 @@
|
||||
document[]<caret>
|
||||
+1
@@ -0,0 +1 @@
|
||||
document<caret>
|
||||
+1
@@ -0,0 +1 @@
|
||||
document<caret>
|
||||
+1
@@ -0,0 +1 @@
|
||||
document(<caret>)
|
||||
+1
@@ -0,0 +1 @@
|
||||
(<caret>)
|
||||
+1
@@ -0,0 +1 @@
|
||||
document(<caret>)
|
||||
+1
@@ -0,0 +1 @@
|
||||
document()<caret>
|
||||
@@ -0,0 +1,6 @@
|
||||
aspect GetInfo {
|
||||
Object C.about() {
|
||||
println(<caret>)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
document.write(<caret>);
|
||||
@@ -0,0 +1 @@
|
||||
$a = <caret>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
aspect GetInfo {
|
||||
Object C.about() {
|
||||
println("<caret>")
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
document.write("<caret>");
|
||||
+1
@@ -0,0 +1 @@
|
||||
$a = "<caret>"
|
||||
@@ -0,0 +1,3 @@
|
||||
function a () <caret>{
|
||||
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
function a () {
|
||||
|
||||
}<caret>
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
package com.intellij.codeInsight.defaultAction;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.CodeBlockEndAction;
|
||||
import com.intellij.codeInsight.editorActions.CodeBlockStartAction;
|
||||
import com.intellij.ide.highlighter.HighlighterFactory;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.openapi.editor.highlighter.EditorHighlighter;
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.fileTypes.impl.AbstractFileType;
|
||||
import com.intellij.psi.CustomHighlighterTokenType;
|
||||
import com.intellij.psi.StringEscapesTokenTypes;
|
||||
import com.intellij.testFramework.EditorTestUtil;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.intellij.testFramework.EditorTestUtil.BACKSPACE_FAKE_CHAR;
|
||||
|
||||
/**
|
||||
* @author Maxim.Mossienko
|
||||
*/
|
||||
public class CustomFileTypeEditorTest extends LightCodeInsightTestCase {
|
||||
private static final String BASE_PATH = "/codeInsight/defaultAction/customFileType/";
|
||||
|
||||
private void _testBlockNavigation(String test, String ext) throws Exception {
|
||||
configureByFile(BASE_PATH + test + "." + ext);
|
||||
performEndBlockAction();
|
||||
checkResultByFile(BASE_PATH + test + "_after." + ext);
|
||||
|
||||
configureByFile(BASE_PATH + test + "_after." + ext);
|
||||
performStartBlockAction();
|
||||
checkResultByFile(BASE_PATH + test + "." + ext);
|
||||
}
|
||||
|
||||
private static void performStartBlockAction() {
|
||||
EditorActionHandler actionHandler = new CodeBlockStartAction().getHandler();
|
||||
|
||||
actionHandler.execute(getEditor(), getCurrentEditorDataContext());
|
||||
}
|
||||
|
||||
private static void performEndBlockAction() {
|
||||
EditorActionHandler actionHandler = new CodeBlockEndAction().getHandler();
|
||||
|
||||
actionHandler.execute(getEditor(), getCurrentEditorDataContext());
|
||||
}
|
||||
|
||||
public void testBlockNavigation() throws Exception {
|
||||
_testBlockNavigation("blockNavigation","cs");
|
||||
}
|
||||
|
||||
public void testInsertDeleteQuotes() throws Exception {
|
||||
configureByFile(BASE_PATH + "InsertDeleteQuote.cs");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '"');
|
||||
checkResultByFile(BASE_PATH + "InsertDeleteQuote_after.cs");
|
||||
|
||||
configureByFile(BASE_PATH+"InsertDeleteQuote_after.cs");
|
||||
EditorTestUtil.performTypingAction(getEditor(), BACKSPACE_FAKE_CHAR);
|
||||
checkResultByFile(BASE_PATH+"InsertDeleteQuote.cs");
|
||||
|
||||
FileType extension = FileTypeManager.getInstance().getFileTypeByExtension("pl");
|
||||
assertTrue("Test is not set up correctly:"+extension, extension instanceof AbstractFileType);
|
||||
configureByFile(BASE_PATH + "InsertDeleteQuote.pl");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '"');
|
||||
checkResultByFile(BASE_PATH + "InsertDeleteQuote_after.pl");
|
||||
|
||||
configureByFile(BASE_PATH+"InsertDeleteQuote_after.pl");
|
||||
EditorTestUtil.performTypingAction(getEditor(), BACKSPACE_FAKE_CHAR);
|
||||
checkResultByFile(BASE_PATH+"InsertDeleteQuote.pl");
|
||||
|
||||
configureByFile(BASE_PATH + "InsertDeleteQuote.aj");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '"');
|
||||
checkResultByFile(BASE_PATH + "InsertDeleteQuote_after.aj");
|
||||
|
||||
configureByFile(BASE_PATH+"InsertDeleteQuote_after.aj");
|
||||
EditorTestUtil.performTypingAction(getEditor(), BACKSPACE_FAKE_CHAR);
|
||||
checkResultByFile(BASE_PATH+"InsertDeleteQuote.aj");
|
||||
}
|
||||
|
||||
public void testInsertDeleteBracket() throws Exception {
|
||||
configureByFile(BASE_PATH + "InsertDeleteBracket.cs");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '[');
|
||||
checkResultByFile(BASE_PATH + "InsertDeleteBracket_after.cs");
|
||||
|
||||
configureByFile(BASE_PATH+"InsertDeleteBracket_after.cs");
|
||||
EditorTestUtil.performTypingAction(getEditor(), BACKSPACE_FAKE_CHAR);
|
||||
checkResultByFile(BASE_PATH+"InsertDeleteBracket.cs");
|
||||
|
||||
configureByFile(BASE_PATH+"InsertDeleteBracket_after.cs");
|
||||
EditorTestUtil.performTypingAction(getEditor(), ']');
|
||||
checkResultByFile(BASE_PATH + "InsertDeleteBracket_after2.cs");
|
||||
}
|
||||
|
||||
public void testInsertDeleteParenth() throws Exception {
|
||||
configureByFile(BASE_PATH + "InsertDeleteParenth.cs");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '(');
|
||||
checkResultByFile(BASE_PATH + "InsertDeleteParenth_after.cs");
|
||||
|
||||
configureByFile(BASE_PATH+"InsertDeleteParenth_after.cs");
|
||||
EditorTestUtil.performTypingAction(getEditor(), BACKSPACE_FAKE_CHAR);
|
||||
checkResultByFile(BASE_PATH+"InsertDeleteParenth.cs");
|
||||
|
||||
configureByFile(BASE_PATH+"InsertDeleteParenth_after.cs");
|
||||
EditorTestUtil.performTypingAction(getEditor(), ')');
|
||||
checkResultByFile(BASE_PATH+"InsertDeleteParenth_after2.cs");
|
||||
|
||||
configureByFile(BASE_PATH + "InsertDeleteParenth2_2.cs");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '(');
|
||||
checkResultByFile(BASE_PATH + "InsertDeleteParenth2_2_after.cs");
|
||||
|
||||
configureByFile(BASE_PATH + "InsertDeleteParenth2.cs");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '(');
|
||||
checkResultByFile(BASE_PATH + "InsertDeleteParenth2_after.cs");
|
||||
}
|
||||
|
||||
private void checkTyping(String fileName, String before, char typed, String after) throws IOException {
|
||||
configureFromFileText(fileName, before);
|
||||
EditorTestUtil.performTypingAction(getEditor(), typed);
|
||||
checkResultByText(after);
|
||||
}
|
||||
|
||||
public void testParenthesesBeforeNonWs() throws Exception {
|
||||
checkTyping("a.cs", "<caret>a", '(', "(<caret>a");
|
||||
checkTyping("a.cs", "<caret>@a", '(', "(<caret>@a");
|
||||
checkTyping("a.cs", "<caret>(a", '(', "(<caret>(a");
|
||||
checkTyping("a.cs", "<caret>[a", '(', "(<caret>[a");
|
||||
checkTyping("a.cs", "<caret> (a", '(', "(<caret>) (a");
|
||||
checkTyping("a.cs", "(<caret>)", '(', "((<caret>))");
|
||||
checkTyping("a.cs", "(<caret>,)", '(', "((<caret>),)");
|
||||
|
||||
checkTyping("a.cs", "<caret>a", '[', "[<caret>a");
|
||||
checkTyping("a.cs", "<caret>@a", '[', "[<caret>@a");
|
||||
checkTyping("a.cs", "<caret>(a", '[', "[<caret>(a");
|
||||
checkTyping("a.cs", "<caret>[a", '[', "[<caret>[a");
|
||||
checkTyping("a.cs", "<caret> (a", '[', "[<caret>] (a");
|
||||
}
|
||||
|
||||
public void testQuoteBeforeNonWs() throws Exception {
|
||||
checkTyping("a.cs", "<caret>a", '"', "\"<caret>a");
|
||||
checkTyping("a.cs", "<caret> ", '"', "\"<caret>\" ");
|
||||
|
||||
checkTyping("a.cs", "<caret>a", '\'', "'<caret>a");
|
||||
checkTyping("a.cs", "<caret> ", '\'', "'<caret>' ");
|
||||
}
|
||||
|
||||
public void testReplaceQuote() throws Exception {
|
||||
checkTyping("a.cs", "<caret><selection>\"</selection>a\"", '\'', "\'<caret>a\"");
|
||||
checkTyping("a.cs", "<caret><selection>\"</selection>a\'", '\'', "\'<caret>a\'");
|
||||
checkTyping("a.cs", "\"a<caret><selection>\"</selection>", '\'', "\"a\'<caret>");
|
||||
checkTyping("a.cs", "\'a<caret><selection>\"</selection>", '\'', "\'a\'<caret>");
|
||||
|
||||
checkTyping("a.cs", "<caret><selection>\'</selection>a\"", '\"', "\"<caret>a\"");
|
||||
checkTyping("a.cs", "<caret><selection>\'</selection>a\'", '\"', "\"<caret>a\'");
|
||||
checkTyping("a.cs", "\"a<caret><selection>\'</selection>", '\"', "\"a\"<caret>");
|
||||
checkTyping("a.cs", "\'a<caret><selection>\'</selection>", '\"', "\'a\"<caret>");
|
||||
}
|
||||
|
||||
public void testNoPairedBracesInPlainText() throws Exception {
|
||||
checkTyping("a.txt", "<caret>", '(', "(<caret>");
|
||||
checkTyping("a.txt", "{<caret>}", '}', "{}<caret>}");
|
||||
}
|
||||
|
||||
public void testClosingBraceInPlainText() throws Exception {
|
||||
configureFromFileText("a.txt", "<caret>");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '(');
|
||||
EditorTestUtil.performTypingAction(getEditor(), ')');
|
||||
checkResultByText("()<caret>");
|
||||
}
|
||||
|
||||
public void testInsertBraceOnEnter() throws Exception {
|
||||
configureByFile(BASE_PATH + "InsertBraceOnEnter.cs");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '\n');
|
||||
checkResultByFile(BASE_PATH + "InsertBraceOnEnter_after.cs");
|
||||
}
|
||||
|
||||
public void testInsertBraceOnEnterJavaFx() throws Exception {
|
||||
String testName = getTestName(false);
|
||||
configureByFile(BASE_PATH + testName + ".fx");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '\n');
|
||||
checkResultByFile(BASE_PATH + testName + "_after.fx");
|
||||
}
|
||||
|
||||
public void testCpp() throws Exception {
|
||||
EditorHighlighter highlighter = HighlighterFactory.createHighlighter(getProject(), "A.cpp");
|
||||
// 0123456789012345678 9 0123 45 6 7
|
||||
highlighter.setText("#include try enum \"\\xff\\z\\\"xxx\"");
|
||||
HighlighterIterator iterator = highlighter.createIterator(2);
|
||||
assertEquals(CustomHighlighterTokenType.KEYWORD_1, iterator.getTokenType());
|
||||
|
||||
iterator = highlighter.createIterator(9);
|
||||
assertEquals(CustomHighlighterTokenType.KEYWORD_2, iterator.getTokenType());
|
||||
|
||||
iterator = highlighter.createIterator(15);
|
||||
assertEquals(CustomHighlighterTokenType.KEYWORD_1, iterator.getTokenType());
|
||||
|
||||
iterator = highlighter.createIterator(19);
|
||||
assertEquals(StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN, iterator.getTokenType());
|
||||
|
||||
iterator = highlighter.createIterator(23);
|
||||
assertEquals(StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN, iterator.getTokenType());
|
||||
|
||||
iterator = highlighter.createIterator(25);
|
||||
assertEquals(StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN, iterator.getTokenType());
|
||||
|
||||
iterator = highlighter.createIterator(27);
|
||||
assertEquals(CustomHighlighterTokenType.STRING, iterator.getTokenType());
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.intellij.ide.highlighter.custom;
|
||||
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public abstract class CustomFileTypeLexerTestBase extends TestCase {
|
||||
protected Lexer lexer;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
lexer = new CustomFileTypeLexer(createSyntaxTable());
|
||||
}
|
||||
|
||||
protected abstract SyntaxTable createSyntaxTable();
|
||||
|
||||
protected void checkTypesAndTokens(String sampleCode, IElementType[] types, String[] matches) {
|
||||
lexer.start(sampleCode);
|
||||
assertEquals(types.length, matches.length);
|
||||
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
assertEquals("Failed at index=" + i, types[i], lexer.getTokenType());
|
||||
assertEquals("Failed at index=" + i, matches[i], sampleCode.substring(lexer.getTokenStart(), lexer.getTokenEnd()));
|
||||
lexer.advance();
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkSameText(String sampleCode) {
|
||||
lexer.start(sampleCode);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String result;
|
||||
while (lexer.getTokenType() != null) {
|
||||
result = sampleCode.substring(lexer.getTokenStart(), lexer.getTokenEnd());
|
||||
sb.append(result);
|
||||
lexer.advance();
|
||||
}
|
||||
|
||||
assertEquals("Text created by lexer's output does not match the original text", sampleCode, sb.toString());
|
||||
}
|
||||
|
||||
public void testNothing() throws Exception {
|
||||
//TODO[dsl] Testcase fails if there's no any testcase. So I've added an empty one.
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package com.intellij.ide.highlighter.custom;
|
||||
|
||||
import com.intellij.psi.CustomHighlighterTokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
|
||||
/**
|
||||
* @author Yura Cangea
|
||||
* @version 1.0
|
||||
*/
|
||||
public class JavaCodeTest extends CustomFileTypeLexerTestBase {
|
||||
|
||||
@Override
|
||||
public SyntaxTable createSyntaxTable() {
|
||||
SyntaxTable table = new SyntaxTable();
|
||||
|
||||
table.setLineComment("//");
|
||||
table.setStartComment("/*");
|
||||
table.setEndComment("*/");
|
||||
|
||||
table.setHexPrefix("0x");
|
||||
table.setNumPostfixChars("cfdle");
|
||||
|
||||
table.addKeyword1("package");
|
||||
table.addKeyword1("import");
|
||||
table.addKeyword1("this");
|
||||
table.addKeyword1("super");
|
||||
table.addKeyword1("public");
|
||||
table.addKeyword1("private");
|
||||
table.addKeyword1("protected");
|
||||
table.addKeyword1("null");
|
||||
table.addKeyword1("if");
|
||||
table.addKeyword1("else");
|
||||
table.addKeyword1("throws");
|
||||
table.addKeyword1("switch");
|
||||
table.addKeyword1("case");
|
||||
table.addKeyword1("break");
|
||||
table.addKeyword1("default");
|
||||
table.addKeyword1("continue");
|
||||
table.addKeyword1("goto");
|
||||
table.addKeyword1("boolean");
|
||||
table.addKeyword1("true");
|
||||
table.addKeyword1("false");
|
||||
table.addKeyword1("final");
|
||||
table.addKeyword1("class");
|
||||
table.addKeyword1("static");
|
||||
table.addKeyword1("final");
|
||||
table.addKeyword1("void");
|
||||
table.addKeyword1("int");
|
||||
table.addKeyword1("while");
|
||||
table.addKeyword1("new");
|
||||
table.addKeyword1("for");
|
||||
table.addKeyword1("byte");
|
||||
table.addKeyword1("float");
|
||||
table.addKeyword1("double");
|
||||
table.addKeyword1("short");
|
||||
table.addKeyword1("extends");
|
||||
table.addKeyword1("implements");
|
||||
table.addKeyword1("interface");
|
||||
table.addKeyword1("abstract");
|
||||
table.addKeyword1("char");
|
||||
table.addKeyword1("try");
|
||||
table.addKeyword1("catch");
|
||||
table.addKeyword1("finally");
|
||||
table.addKeyword1("synchronized");
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
public void testParseSampleCode() {
|
||||
String sampleCode =
|
||||
"private some text f b g\n\n\n// 1\n public static void main(String[] args) {\n}\n-10 - 10\n\"dsfdfdf\"\n/* a\n *bc */";
|
||||
String sampleCode2 = "/*";
|
||||
String sampleCode3 = "//";
|
||||
String sampleCode4 = "";
|
||||
String sampleCode5 = " ";
|
||||
|
||||
checkSameText(sampleCode);
|
||||
String result;
|
||||
|
||||
|
||||
IElementType[] types = new IElementType[]{CustomHighlighterTokenType.KEYWORD_1, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.WHITESPACE, CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.WHITESPACE, CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.LINE_COMMENT, CustomHighlighterTokenType.WHITESPACE, CustomHighlighterTokenType.KEYWORD_1, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.KEYWORD_1, CustomHighlighterTokenType.WHITESPACE, CustomHighlighterTokenType.KEYWORD_1, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.CHARACTER, CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.CHARACTER,
|
||||
CustomHighlighterTokenType.CHARACTER, CustomHighlighterTokenType.WHITESPACE, CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.CHARACTER,
|
||||
CustomHighlighterTokenType.WHITESPACE, CustomHighlighterTokenType.CHARACTER, CustomHighlighterTokenType.WHITESPACE, CustomHighlighterTokenType.CHARACTER,
|
||||
CustomHighlighterTokenType.WHITESPACE, CustomHighlighterTokenType.CHARACTER, CustomHighlighterTokenType.NUMBER, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.CHARACTER, CustomHighlighterTokenType.WHITESPACE, CustomHighlighterTokenType.NUMBER, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.STRING, CustomHighlighterTokenType.WHITESPACE, CustomHighlighterTokenType.MULTI_LINE_COMMENT,
|
||||
};
|
||||
|
||||
String[] matches = new String[]{"private", " ", "some", " ", "text", " ", "f", " ", "b", " ", "g", "\n\n\n", "// 1", "\n ", "public",
|
||||
" ", "static", " ", "void", " ", "main", "(",
|
||||
"String", "[", "]", " ", "args", ")", " ", "{", "\n", "}", "\n", "-", "10",
|
||||
" ", "-", " ", "10", "\n", "\"dsfdfdf\"", "\n", "/* a\n *bc */",
|
||||
};
|
||||
|
||||
checkTypesAndTokens(sampleCode, types, matches);
|
||||
|
||||
lexer.start(sampleCode2);
|
||||
assertEquals(CustomHighlighterTokenType.MULTI_LINE_COMMENT, lexer.getTokenType());
|
||||
assertEquals("/*", sampleCode2.substring(lexer.getTokenStart(), lexer.getTokenEnd()));
|
||||
|
||||
lexer.start(sampleCode3);
|
||||
assertEquals(CustomHighlighterTokenType.LINE_COMMENT, lexer.getTokenType());
|
||||
assertEquals("//", sampleCode3.substring(lexer.getTokenStart(), lexer.getTokenEnd()));
|
||||
|
||||
lexer.start(sampleCode4);
|
||||
assertEquals(null, lexer.getTokenType());
|
||||
assertEquals("", sampleCode4.substring(lexer.getTokenStart(), lexer.getTokenEnd()));
|
||||
|
||||
lexer.start(sampleCode5);
|
||||
assertEquals(CustomHighlighterTokenType.WHITESPACE, lexer.getTokenType());
|
||||
assertEquals(" ", sampleCode5.substring(lexer.getTokenStart(), lexer.getTokenEnd()));
|
||||
}
|
||||
|
||||
public void testParseSampleCodeFromTo() {
|
||||
String sampleCode = " int n=123;\n float z=1;";
|
||||
lexer.start(sampleCode, 5, 5);
|
||||
assertEquals(lexer.getTokenType(), null);
|
||||
lexer.start(sampleCode, 5, 6);
|
||||
lexer.getTokenType();
|
||||
assertEquals(5, lexer.getTokenStart());
|
||||
assertEquals(6, lexer.getTokenEnd());
|
||||
assertEquals(6, lexer.getBufferEnd());
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package com.intellij.ide.highlighter.custom;
|
||||
|
||||
import com.intellij.psi.CustomHighlighterTokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public class PropertiesFileTest extends CustomFileTypeLexerTestBase {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
lexer = new CustomFileTypeLexer(createSyntaxTable());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SyntaxTable createSyntaxTable() {
|
||||
SyntaxTable table = new SyntaxTable();
|
||||
|
||||
table.setLineComment("#");
|
||||
table.setIgnoreCase(true);
|
||||
|
||||
table.addKeyword1("value");
|
||||
table.addKeyword2("Value");
|
||||
table.setNumPostfixChars("LGH");
|
||||
return table;
|
||||
}
|
||||
|
||||
public void testSimple() {
|
||||
String sampleFile =
|
||||
"# Comment\n" +
|
||||
"x.1.a=12.2L\n" +
|
||||
" y.2.b=13.4 # comment\n" +
|
||||
"VALUE value VaLuE Value1 17.00h 11.0k";
|
||||
checkSameText(sampleFile);
|
||||
IElementType[] types = {
|
||||
CustomHighlighterTokenType.LINE_COMMENT, CustomHighlighterTokenType.WHITESPACE,
|
||||
|
||||
CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.PUNCTUATION,
|
||||
CustomHighlighterTokenType.NUMBER, CustomHighlighterTokenType.PUNCTUATION,
|
||||
CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.CHARACTER,
|
||||
CustomHighlighterTokenType.NUMBER, CustomHighlighterTokenType.WHITESPACE,
|
||||
|
||||
CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.PUNCTUATION,
|
||||
CustomHighlighterTokenType.NUMBER, CustomHighlighterTokenType.PUNCTUATION,
|
||||
CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.CHARACTER,
|
||||
CustomHighlighterTokenType.NUMBER, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.LINE_COMMENT, CustomHighlighterTokenType.WHITESPACE,
|
||||
|
||||
CustomHighlighterTokenType.KEYWORD_1, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.KEYWORD_1, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.KEYWORD_1, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.NUMBER, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.NUMBER, CustomHighlighterTokenType.PUNCTUATION,
|
||||
CustomHighlighterTokenType.NUMBER,
|
||||
CustomHighlighterTokenType.IDENTIFIER
|
||||
};
|
||||
|
||||
String[] matches = {
|
||||
"# Comment", "\n",
|
||||
|
||||
"x", ".", "1", ".", "a", "=", "12.2L", "\n ",
|
||||
"y", ".", "2", ".", "b", "=", "13.4", " ", "# comment", "\n",
|
||||
"VALUE", " ", "value", " ", "VaLuE", " ", "Value1", " ", "17.00h", " ", "11", ".", "0", "k"
|
||||
};
|
||||
|
||||
checkTypesAndTokens(sampleFile, types, matches);
|
||||
}
|
||||
|
||||
public void testNumber() {
|
||||
String sample = "1.23=1.24";
|
||||
checkSameText(sample);
|
||||
IElementType[] types = {
|
||||
CustomHighlighterTokenType.NUMBER, CustomHighlighterTokenType.CHARACTER, CustomHighlighterTokenType.NUMBER
|
||||
};
|
||||
String[] matches = { "1.23", "=", "1.24" };
|
||||
checkTypesAndTokens(sample, types, matches);
|
||||
}
|
||||
|
||||
public void testPostfix() {
|
||||
String sample = "abc 1.2ltext";
|
||||
checkSameText(sample);
|
||||
IElementType[] types = {
|
||||
CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.WHITESPACE,
|
||||
CustomHighlighterTokenType.NUMBER, CustomHighlighterTokenType.IDENTIFIER
|
||||
};
|
||||
String[] matches = { "abc", " ", "1.2l", "text" };
|
||||
checkTypesAndTokens(sample, types, matches);
|
||||
}
|
||||
|
||||
public void testWeird() {
|
||||
String sample = "test.1.";
|
||||
checkSameText(sample);
|
||||
IElementType[] types = {
|
||||
CustomHighlighterTokenType.IDENTIFIER, CustomHighlighterTokenType.PUNCTUATION, CustomHighlighterTokenType.NUMBER
|
||||
};
|
||||
String[] matches = { "test", ".", "1." };
|
||||
checkTypesAndTokens(sample, types, matches);
|
||||
}
|
||||
|
||||
public void testParenths() throws Exception {
|
||||
String sample = "value(255)";
|
||||
checkSameText(sample);
|
||||
IElementType[] types = {
|
||||
CustomHighlighterTokenType.KEYWORD_1, CustomHighlighterTokenType.CHARACTER,
|
||||
CustomHighlighterTokenType.NUMBER, CustomHighlighterTokenType.CHARACTER
|
||||
};
|
||||
String[] matches = { "value", "(", "255", ")" };
|
||||
checkTypesAndTokens(sample, types, matches);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user