mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
moved rest dependent code from python to python-rest
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.rest.fixtures.RestFixtureTestCase;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestGotoDeclarationTest extends RestFixtureTestCase {
|
||||
|
||||
public void testFootnote() {
|
||||
doTest("[1]");
|
||||
}
|
||||
|
||||
public void testCitation() {
|
||||
doTest("[CIT01]");
|
||||
}
|
||||
|
||||
public void testHyperlink() {
|
||||
doTest("_Reddit:");
|
||||
}
|
||||
|
||||
public void testEscapedHyperlink() {
|
||||
doTest("_Reddit and digg:");
|
||||
}
|
||||
|
||||
public void testSubstitution() {
|
||||
doTest("|text|");
|
||||
}
|
||||
|
||||
public void testAnonimousHyperlink() {
|
||||
doTest("__");
|
||||
}
|
||||
|
||||
public void testTitle() {
|
||||
doTest("=============\nTitle\n=============\n");
|
||||
}
|
||||
|
||||
public void testInsideFootnote() {
|
||||
doTest("_Reddit:");
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
RestGotoProvider provider = new RestGotoProvider();
|
||||
final String path = "/goto/empty.rst";
|
||||
myFixture.configureByFile(path);
|
||||
int e = myFixture.getCaretOffset();
|
||||
PsiElement result = provider.getGotoDeclarationTarget(myFixture.getFile().findElementAt(e), myFixture.getEditor());
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
private void doTest(String expected) {
|
||||
RestGotoProvider provider = new RestGotoProvider();
|
||||
final String path = "/goto/" + getTestName(true);
|
||||
myFixture.configureByFile(path + ".rst");
|
||||
|
||||
int e = myFixture.getCaretOffset();
|
||||
PsiElement result = provider.getGotoDeclarationTarget(myFixture.getFile().findElementAt(e), myFixture.getEditor());
|
||||
assertNotNull(result);
|
||||
assertEquals(expected, result.getText());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.jetbrains.rest.lexer._RestFlexLexer;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestLexerTest extends TestCase {
|
||||
|
||||
public void testTitle() throws IOException {
|
||||
doTest("\n" +
|
||||
".. _quickstart:\n" +
|
||||
"\n" +
|
||||
"Quick start guide\n" +
|
||||
"=================\n",
|
||||
"[\n, WHITESPACE]",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[_quickstart:, HYPERLINK]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[Quick start guide\n" +
|
||||
"=================\n" +
|
||||
", TITLE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testDirective() throws IOException {
|
||||
doTest("\n" +
|
||||
".. note::\n" +
|
||||
" Please",
|
||||
"[\n, WHITESPACE]",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[note::, DIRECTIVE]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[ , WHITESPACE]",
|
||||
"[Please, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testSubstitution() throws IOException {
|
||||
doTest(".. |grappelli| replace:: Grappelli",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[|grappelli|, SUBSTITUTION]",
|
||||
"[ , WHITESPACE]",
|
||||
"[replace::, DIRECTIVE]",
|
||||
"[ Grappelli, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testField() throws IOException {
|
||||
doTest(".. figure:: image.png\n" +
|
||||
" :width: 300pt",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[figure::, DIRECTIVE]",
|
||||
"[ image.png, LINE]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[ , WHITESPACE]",
|
||||
"[:width:, FIELD]",
|
||||
"[ , LINE]",
|
||||
"[300pt, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testRole() throws IOException { //PY-3810
|
||||
doTest(" role :roole1:`some text` :notparsed: text\n" +
|
||||
":list field:\n" +
|
||||
" :second field:\n",
|
||||
"[ , LINE]",
|
||||
"[role, LINE]",
|
||||
"[ , LINE]",
|
||||
"[:roole1:, FIELD]",
|
||||
"[`some text`, INTERPRETED]",
|
||||
"[ , LINE]",
|
||||
"[:, LINE]",
|
||||
"[notparsed, LINE]",
|
||||
"[:, LINE]",
|
||||
"[ , LINE]",
|
||||
"[text, LINE]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[:list field:, FIELD]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[ , LINE]",
|
||||
"[:second field:, FIELD]",
|
||||
"[\n, WHITESPACE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testFootnote() throws IOException {
|
||||
doTest(".. [2] Random",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[[2], FOOTNOTE]",
|
||||
"[ , LINE]",
|
||||
"[Random, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testHyperlink() throws IOException {
|
||||
doTest(".. _`dvipng`: http://savannah.nongnu.org/projects/dvipng/",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[_`dvipng`:, HYPERLINK]",
|
||||
"[ , LINE]",
|
||||
"[http://savannah.nongnu.org/projects/dvipng/, DIRECT_HYPERLINK]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testItalics() throws IOException {
|
||||
doTest("*italics* highlighting",
|
||||
"[*italics*, ITALIC]",
|
||||
"[ , LINE]",
|
||||
"[highlighting, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testBold() throws IOException {
|
||||
doTest("**bold** highlighting",
|
||||
"[**bold**, BOLD]",
|
||||
"[ , LINE]",
|
||||
"[highlighting, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
private static void doTest(String text, String... expected) throws IOException {
|
||||
_RestFlexLexer lexer = createLexer(text);
|
||||
for (String expectedTokenText : expected) {
|
||||
IElementType type = lexer.advance();
|
||||
if (type == null) {
|
||||
fail("Not enough tokens");
|
||||
}
|
||||
String tokenText = "[" + lexer.yytext() + ", " + type + "]";
|
||||
assertEquals(expectedTokenText, tokenText);
|
||||
}
|
||||
}
|
||||
|
||||
public static _RestFlexLexer createLexer(String text) {
|
||||
_RestFlexLexer lexer = new _RestFlexLexer((Reader)null);
|
||||
lexer.reset(text, 0, text.length(), _RestFlexLexer.YYINITIAL);
|
||||
return lexer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.testFramework.ParsingTestCase;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import com.jetbrains.rest.parsing.RestParserDefinition;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestParsingTest extends ParsingTestCase {
|
||||
|
||||
public RestParsingTest() {
|
||||
super("", "rst", new RestParserDefinition());
|
||||
PyTestCase.initPlatformPrefix();
|
||||
}
|
||||
|
||||
public void testTitle() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testInjection() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testReference() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testReferenceTarget() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testSubstitution() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return PathManager.getHomePath() + "/python/testData/rest/psi";
|
||||
}
|
||||
|
||||
|
||||
protected boolean checkAllPsiRoots() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.jetbrains.rest.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.impl.CamelHumpMatcher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.jetbrains.rest.fixtures.RestFixtureTestCase;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestDirectiveCompletionTest extends RestFixtureTestCase {
|
||||
|
||||
public void testNote() {
|
||||
CamelHumpMatcher.forceStartMatching(getTestRootDisposable());
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInline() {
|
||||
final String filePath = "/completion/directive/inline.rst";
|
||||
myFixture.configureByFiles(filePath);
|
||||
final LookupElement[] items = myFixture.completeBasic();
|
||||
assertNotNull(items);
|
||||
assertEquals(0, items.length);
|
||||
}
|
||||
|
||||
public void testMultiple() {
|
||||
CamelHumpMatcher.forceStartMatching(getTestRootDisposable());
|
||||
final String filePath = "/completion/directive/multiple.rst";
|
||||
myFixture.configureByFiles(filePath);
|
||||
final LookupElement[] items = myFixture.completeBasic();
|
||||
assertNotNull(items);
|
||||
assertEquals(7, items.length);
|
||||
|
||||
assertEquals("caution::", items[0].getLookupString());
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
final String path = "/completion/directive/" + getTestName(true);
|
||||
myFixture.configureByFile(path + ".rst");
|
||||
myFixture.completeBasic();
|
||||
myFixture.checkResultByFile(path + ".after.rst");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.jetbrains.rest.completion;
|
||||
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.jetbrains.rest.fixtures.RestFixtureTestCase;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestOptionCompletionTest extends RestFixtureTestCase {
|
||||
|
||||
public void testFootnote() {
|
||||
final String filePath = "/completion/option/footnote.rst";
|
||||
myFixture.configureByFiles(filePath);
|
||||
final LookupElement[] items = myFixture.completeBasic();
|
||||
assertNotNull(items);
|
||||
assertEquals(0, items.length);
|
||||
}
|
||||
|
||||
public void testImage() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testOutsideDirective() {
|
||||
final String filePath = "/completion/option/outside.rst";
|
||||
myFixture.configureByFiles(filePath);
|
||||
final LookupElement[] items = myFixture.completeBasic();
|
||||
assertNotNull(items);
|
||||
assertEquals(0, items.length);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
final String path = "/completion/option/" + getTestName(true);
|
||||
myFixture.configureByFile(path + ".rst");
|
||||
myFixture.completeBasic();
|
||||
myFixture.checkResultByFile(path + ".after.rst");
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.jetbrains.rest.completion;
|
||||
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.jetbrains.rest.fixtures.RestFixtureTestCase;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestRefereneceCompletionTest extends RestFixtureTestCase {
|
||||
|
||||
public void testFootnote() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCitation() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testHyperlink() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAnonimHyperlink() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSubstitution() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUnderscore() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAlreadyFilled() {
|
||||
final String path = "/completion/reference/alreadyFilled.rst";
|
||||
myFixture.configureByFile(path);
|
||||
LookupElement[] lookups = myFixture.completeBasic();
|
||||
assertNotNull(lookups);
|
||||
assertEquals(0, lookups.length);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
final String path = "/completion/reference/" + getTestName(true);
|
||||
myFixture.configureByFile(path + ".rst");
|
||||
myFixture.completeBasic();
|
||||
myFixture.checkResultByFile(path + ".after.rst");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.jetbrains.rest.fixtures;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.module.EmptyModuleType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
|
||||
import com.intellij.testFramework.fixtures.TestFixtureBuilder;
|
||||
import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
@TestDataPath("$CONTENT_ROOT/../testData/rest")
|
||||
public abstract class RestFixtureTestCase extends UsefulTestCase {
|
||||
private static final RestDescriptor ourDescriptor = new RestDescriptor();
|
||||
|
||||
protected CodeInsightTestFixture myFixture;
|
||||
private static boolean ourPlatformPrefixInitialized;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
PyTestCase.initPlatformPrefix();
|
||||
IdeaTestFixtureFactory factory = IdeaTestFixtureFactory.getFixtureFactory();
|
||||
TestFixtureBuilder<IdeaProjectTestFixture> fixtureBuilder = factory.createLightFixtureBuilder(getProjectDescriptor());
|
||||
final IdeaProjectTestFixture fixture = fixtureBuilder.getFixture();
|
||||
myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(fixture,
|
||||
new LightTempDirTestFixtureImpl(true));
|
||||
myFixture.setUp();
|
||||
|
||||
myFixture.setTestDataPath(getTestDataPath());
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return PathManager.getHomePath() + "/python/testData/rest";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myFixture.tearDown();
|
||||
myFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected RestDescriptor getProjectDescriptor() {
|
||||
return ourDescriptor;
|
||||
}
|
||||
|
||||
protected static class RestDescriptor implements LightProjectDescriptor {
|
||||
public RestDescriptor() {}
|
||||
|
||||
@Override
|
||||
public ModuleType getModuleType() {
|
||||
return EmptyModuleType.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.jetbrains.rest.inspections;
|
||||
|
||||
import com.jetbrains.rest.fixtures.RestFixtureTestCase;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestInspectionTest extends RestFixtureTestCase {
|
||||
public void testUndefinedRole() {
|
||||
doTest(RestRoleInspection.class);
|
||||
}
|
||||
|
||||
public void testHyperlinkAnnotator() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFootnoteAnnotator() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testReferenceTargetAnnotator() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest(Class<? extends RestInspection> inspection) {
|
||||
myFixture.configureByFile("/inspections/" + getTestName(true) + ".rst");
|
||||
if (inspection != null)
|
||||
myFixture.enableInspections(inspection);
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user