-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86819d4
commit 71d9b96
Showing
8 changed files
with
181 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package helpers; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.roots.ContentEntry; | ||
import com.intellij.openapi.roots.ModifiableRootModel; | ||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor; | ||
|
||
import de.vette.idea.neos.Settings; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Enable the Neos Project plugin | ||
*/ | ||
public class NeosProjectDescriptor extends DefaultLightProjectDescriptor { | ||
@Override | ||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) { | ||
super.configureModule(module, model, contentEntry); | ||
Settings.getInstance(module.getProject()).pluginEnabled = true; | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/test/java/nodeTypeReferences/NodeTypeReferencesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package nodeTypeReferences; | ||
|
||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.ResolveResult; | ||
import com.intellij.testFramework.LightProjectDescriptor; | ||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; | ||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; | ||
|
||
import de.vette.idea.neos.lang.yaml.references.nodeType.NodeTypeReference; | ||
|
||
import org.jetbrains.yaml.psi.YAMLKeyValue; | ||
|
||
import java.util.function.Function; | ||
|
||
import helpers.NeosProjectDescriptor; | ||
|
||
/** | ||
* Testcase for node type references | ||
*/ | ||
public class NodeTypeReferencesTest extends LightPlatformCodeInsightFixtureTestCase { | ||
|
||
@Override | ||
protected String getTestDataPath() { | ||
return "testData/nodeTypeReferences"; | ||
} | ||
|
||
@Override | ||
protected boolean isWriteActionRequired() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected LightProjectDescriptor getProjectDescriptor() { | ||
return new NeosProjectDescriptor(); | ||
} | ||
|
||
public void testSupertypeInSameFile() { | ||
doRunTest( | ||
"NodeTypes.supertypeInSameFile.yaml", | ||
1, | ||
"Neos.NodeTypes:Page", | ||
"NodeTypes.supertypeInSameFile.yaml", | ||
offset -> offset < 5 | ||
); | ||
} | ||
|
||
public void testSupertypeInOtherFile() { | ||
doRunTest( | ||
"NodeTypes.supertypeInOtherFile.yaml", | ||
1, | ||
"Neos.NodeTypes:Image", | ||
"NodeTypes.Basic.yaml", | ||
offset -> offset > 20 | ||
); | ||
} | ||
|
||
public void testConstraint() { | ||
doRunTest( | ||
"NodeTypes.constraint.yaml", | ||
1, | ||
"Neos.NodeTypes:Image", | ||
"NodeTypes.Basic.yaml", | ||
offset -> offset > 20 | ||
); | ||
} | ||
|
||
public void testAllDefinitionsAreFound() { | ||
doRunTest( | ||
"NodeTypes.allDefinitionsAreFound.yaml", | ||
3, | ||
"Neos.NodeTypes:Text", | ||
"NodeTypes.Basic.yaml", | ||
offset -> true | ||
); | ||
} | ||
|
||
/** | ||
* Helper actually running the testcase | ||
*/ | ||
private void doRunTest(String fileNameToInclude, int expectedNumberOfSuggestions, String targetPsiElementKeyText, String targetFile, Function<Integer, Boolean> offsetChecker) { | ||
myFixture.configureByFiles(fileNameToInclude, "NodeTypes.Basic.yaml"); | ||
|
||
// actually trigger indexing | ||
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject()); | ||
|
||
PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent(); | ||
|
||
ResolveResult[] resolveResult = ((NodeTypeReference) element.getReferences()[0]).multiResolve(false); | ||
assertEquals("Length does not match", expectedNumberOfSuggestions, resolveResult.length); | ||
|
||
YAMLKeyValue yamlKeyValue = assertInstanceOf(resolveResult[0].getElement(), YAMLKeyValue.class); | ||
|
||
assertEquals("keyText does not match", targetPsiElementKeyText, yamlKeyValue.getKeyText()); | ||
assertEquals("wrong file name", targetFile, yamlKeyValue.getContainingFile().getName()); | ||
assertTrue("Text offset fits", offsetChecker.apply(yamlKeyValue.getTextOffset())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'Neos.NodeTypes:Headline': | ||
abstract: true | ||
'Neos.NodeTypes:Text': | ||
abstract: true | ||
'Neos.NodeTypes:Image': | ||
abstract: true |
5 changes: 5 additions & 0 deletions
5
testData/nodeTypeReferences/NodeTypes.allDefinitionsAreFound.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'Neos.NodeTypes:T<caret>ext': | ||
foo: bar | ||
|
||
'Neos.NodeTypes:Text': | ||
foo: baz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'Neos.Demo:Homepage': | ||
constraints: | ||
nodeTypes: | ||
'Neos.<caret>NodeTypes:Image': TRUE |
3 changes: 3 additions & 0 deletions
3
testData/nodeTypeReferences/NodeTypes.supertypeInOtherFile.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'Neos.Demo:Homepage': | ||
superTypes: | ||
'Neos.NodeTypes:<caret>Image': TRUE |
11 changes: 11 additions & 0 deletions
11
testData/nodeTypeReferences/NodeTypes.supertypeInSameFile.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'Neos.NodeTypes:Page': | ||
constraints: | ||
nodeTypes: | ||
'*': FALSE | ||
'Neos.NodeTypes:Headline': TRUE | ||
'Neos.NodeTypes:Text': TRUE | ||
'Neos.NodeTypes:Image': TRUE | ||
|
||
'Neos.Demo:Homepage': | ||
superTypes: | ||
'Neos.NodeTypes:Page<caret>': TRUE |