Skip to content

Commit 90963a2

Browse files
authored
Fix YAML tests for platform >= 2018 3 (Haehnchen#1307)
Fix YAML tests for platform >= 2018 3
2 parents 3c3fb72 + 453774c commit 90963a2

File tree

7 files changed

+58
-16
lines changed

7 files changed

+58
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ env:
2525
- PHPSTORM_ENV="skip incomplete" IDEA_VERSION="IU-183.2153.8" PHP_PLUGIN_VERSION="183.2153.44" TWIG_PLUGIN_VERSION="183.2153.44" TOOLBOX_PLUGIN_VERSION="0.4.6" ANNOTATION_PLUGIN_VERSION="5.3"
2626
- PHPSTORM_ENV="skip incomplete" IDEA_VERSION="IU-2018.2.5" PHP_PLUGIN_VERSION="182.4892.16" TWIG_PLUGIN_VERSION="182.3458.35" TOOLBOX_PLUGIN_VERSION="0.4.6" ANNOTATION_PLUGIN_VERSION="5.3"
2727
- PHPSTORM_ENV="skip incomplete" IDEA_VERSION="IU-2018.2" PHP_PLUGIN_VERSION="182.3684.42" TWIG_PLUGIN_VERSION="182.3458.35" TOOLBOX_PLUGIN_VERSION="0.4.6" ANNOTATION_PLUGIN_VERSION="5.3"
28-
- PHPSTORM_ENV="skip incomplete" IDEA_VERSION="IU-2018.3" PHP_PLUGIN_VERSION="183.4284.150" TWIG_PLUGIN_VERSION="183.3795.24" TOOLBOX_PLUGIN_VERSION="0.4.6" ANNOTATION_PLUGIN_VERSION="5.3"
28+
- PHPSTORM_ENV="skip incomplete" IDEA_VERSION="IU-2018.3.6" PHP_PLUGIN_VERSION="183.5429.47" TWIG_PLUGIN_VERSION="183.3795.24" TOOLBOX_PLUGIN_VERSION="0.4.6" ANNOTATION_PLUGIN_VERSION="5.3"
2929

3030
script:
3131
- "./gradlew check verifyPlugin buildPlugin"

build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ plugins {
1616
def htmlFixer = { htmlFile -> file(htmlFile).text.replace('<html>', '').replace('</html>', '') }
1717

1818
apply plugin: 'idea'
19-
apply plugin: 'org.jetbrains.intellij'
19+
2020
apply plugin: 'java'
21+
sourceCompatibility = 1.8
22+
targetCompatibility = 1.8
2123

24+
apply plugin: 'org.jetbrains.intellij'
2225
intellij {
2326
version ideaVersion
2427
updateSinceUntilBuild false

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#toolboxPluginVersion = 0.4.6
55
#annotationPluginVersion = 5.3
66

7-
ideaVersion = IU-2018.3
8-
phpPluginVersion = 183.4284.150
7+
ideaVersion = IU-2018.3.6
8+
phpPluginVersion = 183.5429.47
99
twigPluginVersion = 183.3795.24
1010
toolboxPluginVersion = 0.4.6
1111
annotationPluginVersion = 5.3
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Sun Apr 28 18:02:14 CEST 2019
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/yaml/YamlUnquotedColon.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.jetbrains.yaml.psi.YAMLCompoundValue;
1313
import org.jetbrains.yaml.psi.YAMLKeyValue;
1414

15+
import static fr.adrienbrault.idea.symfony2plugin.util.VersionUtil.productVersionGreaterThanOrEqual;
16+
1517
/**
1618
* @author Daniel Espendiller <daniel@espendiller.net>
1719
*/
@@ -39,7 +41,7 @@ private static class MyPsiElementVisitor extends PsiElementVisitor {
3941
public void visitElement(PsiElement element) {
4042
// every array element implements this interface
4143
// check for inside "foo: <foo: foo>"
42-
if(!(element instanceof YAMLCompoundValue) || element.getNode().getElementType() != YAMLElementTypes.COMPOUND_VALUE) {
44+
if(!isIllegalColonExpression(element)) {
4345
super.visitElement(element);
4446
return;
4547
}
@@ -67,5 +69,14 @@ public void visitElement(PsiElement element) {
6769

6870
super.visitElement(element);
6971
}
72+
73+
private boolean isIllegalColonExpression(PsiElement element) {
74+
75+
if (productVersionGreaterThanOrEqual(2018, 3)) {
76+
return (element instanceof YAMLCompoundValue) && element.getNode().getElementType() == YAMLElementTypes.MAPPING;
77+
}
78+
79+
return (element instanceof YAMLCompoundValue) && element.getNode().getElementType() == YAMLElementTypes.COMPOUND_VALUE;
80+
}
7081
}
7182
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package fr.adrienbrault.idea.symfony2plugin.util;
2+
3+
import com.intellij.openapi.application.ApplicationInfo;
4+
5+
public class VersionUtil {
6+
public static boolean productVersionGreaterThanOrEqual(int major, int minor) {
7+
ApplicationInfo instance = ApplicationInfo.getInstance();
8+
9+
return Integer.valueOf(instance.getMajorVersion()) > major || (Integer.valueOf(instance.getMajorVersion()).equals(major) && Integer.valueOf(instance.getMinorVersionMainPart()) >= minor);
10+
}
11+
}

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/yaml/YamlHelperLightTest.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.adrienbrault.idea.symfony2plugin.tests.util.yaml;
22

3+
import com.intellij.openapi.application.ApplicationInfo;
34
import com.intellij.psi.PsiElement;
45
import com.intellij.util.Function;
56
import com.intellij.util.containers.ContainerUtil;
@@ -336,16 +337,31 @@ public void testInsertKeyWithArrayValue() {
336337

337338
YamlHelper.insertKeyIntoFile(yamlFile, yamlKeyValue, "services");
338339

339-
assertEquals("" +
340-
"services:\n" +
341-
" foo:\n" +
342-
" car: test\n" +
343-
" my_service:\n" +
344-
" class: foo\n" +
345-
" tag:\n" +
346-
" - foo",
347-
yamlFile.getText()
348-
);
340+
ApplicationInfo instance = ApplicationInfo.getInstance();
341+
String minorVersion = instance.getMinorVersionMainPart();
342+
if (instance.getMajorVersion().equals("2019") || (instance.getMajorVersion().equals("2018") && Integer.valueOf(minorVersion) >= 3)) {
343+
assertEquals("" +
344+
"services:\n" +
345+
" foo:\n" +
346+
" car: test\n" +
347+
" my_service:\n" +
348+
" class: foo\n" +
349+
" tag:\n" +
350+
" - foo",
351+
yamlFile.getText()
352+
);
353+
} else {
354+
assertEquals("" +
355+
"services:\n" +
356+
" foo:\n" +
357+
" car: test\n" +
358+
" my_service:\n" +
359+
" class: foo\n" +
360+
" tag:\n" +
361+
" - foo",
362+
yamlFile.getText()
363+
);
364+
}
349365
}
350366

351367
/**

0 commit comments

Comments
 (0)