From a2ee65e64ca87e0b4f2abfe1d1d356f9bbcf4500 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Wed, 29 May 2013 15:33:53 +0400 Subject: [PATCH] Add type tests for JetPsiMatcher --- .../jet/generators/tests/GenerateTests.java | 3 +- .../jetPsiMatcher/types/_functional1.kt | 2 + .../jetPsiMatcher/types/_functional1.kt.2 | 1 + .../jetPsiMatcher/types/_functional2.kt | 2 + .../jetPsiMatcher/types/_functional2.kt.2 | 1 + .../jetPsiMatcher/types/_nullable1.kt | 2 + .../jetPsiMatcher/types/_nullable1.kt.2 | 1 + idea/testData/jetPsiMatcher/types/_user1.kt | 2 + idea/testData/jetPsiMatcher/types/_user1.kt.2 | 1 + idea/testData/jetPsiMatcher/types/_user2.kt | 2 + idea/testData/jetPsiMatcher/types/_user2.kt.2 | 1 + .../jetPsiMatcher/types/functional1.kt | 1 + .../jetPsiMatcher/types/functional1.kt.2 | 1 + .../jetPsiMatcher/types/functional2.kt | 1 + .../jetPsiMatcher/types/functional2.kt.2 | 1 + .../jetPsiMatcher/types/functional3.kt | 1 + .../jetPsiMatcher/types/functional3.kt.2 | 1 + .../testData/jetPsiMatcher/types/nullable1.kt | 1 + .../jetPsiMatcher/types/nullable1.kt.2 | 1 + idea/testData/jetPsiMatcher/types/user1.kt | 1 + idea/testData/jetPsiMatcher/types/user1.kt.2 | 1 + idea/testData/jetPsiMatcher/types/user2.kt | 1 + idea/testData/jetPsiMatcher/types/user2.kt.2 | 1 + .../jet/psi/AbstractJetPsiMatcherTest.java | 19 +++++ .../jetbrains/jet/psi/JetPsiMatcherTest.java | 72 +++++++++++++++++-- 25 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 idea/testData/jetPsiMatcher/types/_functional1.kt create mode 100644 idea/testData/jetPsiMatcher/types/_functional1.kt.2 create mode 100644 idea/testData/jetPsiMatcher/types/_functional2.kt create mode 100644 idea/testData/jetPsiMatcher/types/_functional2.kt.2 create mode 100644 idea/testData/jetPsiMatcher/types/_nullable1.kt create mode 100644 idea/testData/jetPsiMatcher/types/_nullable1.kt.2 create mode 100644 idea/testData/jetPsiMatcher/types/_user1.kt create mode 100644 idea/testData/jetPsiMatcher/types/_user1.kt.2 create mode 100644 idea/testData/jetPsiMatcher/types/_user2.kt create mode 100644 idea/testData/jetPsiMatcher/types/_user2.kt.2 create mode 100644 idea/testData/jetPsiMatcher/types/functional1.kt create mode 100644 idea/testData/jetPsiMatcher/types/functional1.kt.2 create mode 100644 idea/testData/jetPsiMatcher/types/functional2.kt create mode 100644 idea/testData/jetPsiMatcher/types/functional2.kt.2 create mode 100644 idea/testData/jetPsiMatcher/types/functional3.kt create mode 100644 idea/testData/jetPsiMatcher/types/functional3.kt.2 create mode 100644 idea/testData/jetPsiMatcher/types/nullable1.kt create mode 100644 idea/testData/jetPsiMatcher/types/nullable1.kt.2 create mode 100644 idea/testData/jetPsiMatcher/types/user1.kt create mode 100644 idea/testData/jetPsiMatcher/types/user1.kt.2 create mode 100644 idea/testData/jetPsiMatcher/types/user2.kt create mode 100644 idea/testData/jetPsiMatcher/types/user2.kt.2 diff --git a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java index 0b4e2b3d1f0..4971a06f9cf 100644 --- a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java +++ b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java @@ -216,7 +216,8 @@ public class GenerateTests { "idea/tests/", "JetPsiMatcherTest", AbstractJetPsiMatcherTest.class, - testModel("idea/testData/jetPsiMatcher", "doTestExpressions") + testModel("idea/testData/jetPsiMatcher/expressions", "doTestExpressions"), + testModel("idea/testData/jetPsiMatcher/types", "doTestTypes") ); generateTest( diff --git a/idea/testData/jetPsiMatcher/types/_functional1.kt b/idea/testData/jetPsiMatcher/types/_functional1.kt new file mode 100644 index 00000000000..f33284d37f3 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/_functional1.kt @@ -0,0 +1,2 @@ +// NOT_EQUAL +val x: (s: String, b: Boolean) -> Int \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/_functional1.kt.2 b/idea/testData/jetPsiMatcher/types/_functional1.kt.2 new file mode 100644 index 00000000000..38402488d77 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/_functional1.kt.2 @@ -0,0 +1 @@ +val x: (s: Boolean, b: String) -> Int \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/_functional2.kt b/idea/testData/jetPsiMatcher/types/_functional2.kt new file mode 100644 index 00000000000..10576c8c432 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/_functional2.kt @@ -0,0 +1,2 @@ +// NOT_EQUAL +val x: String.(b: Boolean) -> Int \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/_functional2.kt.2 b/idea/testData/jetPsiMatcher/types/_functional2.kt.2 new file mode 100644 index 00000000000..310f441f850 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/_functional2.kt.2 @@ -0,0 +1 @@ +val x: (s: String, b: Boolean) -> Int \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/_nullable1.kt b/idea/testData/jetPsiMatcher/types/_nullable1.kt new file mode 100644 index 00000000000..acb4730cc08 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/_nullable1.kt @@ -0,0 +1,2 @@ +// NOT_EQUAL +val x: String \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/_nullable1.kt.2 b/idea/testData/jetPsiMatcher/types/_nullable1.kt.2 new file mode 100644 index 00000000000..b43528c36f1 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/_nullable1.kt.2 @@ -0,0 +1 @@ +val x: String? \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/_user1.kt b/idea/testData/jetPsiMatcher/types/_user1.kt new file mode 100644 index 00000000000..d85c1b188ac --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/_user1.kt @@ -0,0 +1,2 @@ +// NOT_EQUAL +val x: Map> \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/_user1.kt.2 b/idea/testData/jetPsiMatcher/types/_user1.kt.2 new file mode 100644 index 00000000000..eea5c86cdd2 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/_user1.kt.2 @@ -0,0 +1 @@ +val y: Map> \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/_user2.kt b/idea/testData/jetPsiMatcher/types/_user2.kt new file mode 100644 index 00000000000..797debd3543 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/_user2.kt @@ -0,0 +1,2 @@ +// NOT_EQUAL +val x: Collection \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/_user2.kt.2 b/idea/testData/jetPsiMatcher/types/_user2.kt.2 new file mode 100644 index 00000000000..6c8662b0250 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/_user2.kt.2 @@ -0,0 +1 @@ +val x: MutableCollection \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/functional1.kt b/idea/testData/jetPsiMatcher/types/functional1.kt new file mode 100644 index 00000000000..40071fe2b1c --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/functional1.kt @@ -0,0 +1 @@ +val x: String -> Int \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/functional1.kt.2 b/idea/testData/jetPsiMatcher/types/functional1.kt.2 new file mode 100644 index 00000000000..799a25379cf --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/functional1.kt.2 @@ -0,0 +1 @@ +val y: String -> Int \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/functional2.kt b/idea/testData/jetPsiMatcher/types/functional2.kt new file mode 100644 index 00000000000..310f441f850 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/functional2.kt @@ -0,0 +1 @@ +val x: (s: String, b: Boolean) -> Int \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/functional2.kt.2 b/idea/testData/jetPsiMatcher/types/functional2.kt.2 new file mode 100644 index 00000000000..004a1d24a98 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/functional2.kt.2 @@ -0,0 +1 @@ +val x: (x: String, y: Boolean) -> Int \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/functional3.kt b/idea/testData/jetPsiMatcher/types/functional3.kt new file mode 100644 index 00000000000..aac457e03f0 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/functional3.kt @@ -0,0 +1 @@ +val x: String.(b: Boolean) -> Int \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/functional3.kt.2 b/idea/testData/jetPsiMatcher/types/functional3.kt.2 new file mode 100644 index 00000000000..202b79b1e59 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/functional3.kt.2 @@ -0,0 +1 @@ +val x: String.(n: Boolean) -> Int \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/nullable1.kt b/idea/testData/jetPsiMatcher/types/nullable1.kt new file mode 100644 index 00000000000..b43528c36f1 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/nullable1.kt @@ -0,0 +1 @@ +val x: String? \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/nullable1.kt.2 b/idea/testData/jetPsiMatcher/types/nullable1.kt.2 new file mode 100644 index 00000000000..bb095c9d12d --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/nullable1.kt.2 @@ -0,0 +1 @@ +val y: String? \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/user1.kt b/idea/testData/jetPsiMatcher/types/user1.kt new file mode 100644 index 00000000000..b15fdf0cf95 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/user1.kt @@ -0,0 +1 @@ +val x: Collection \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/user1.kt.2 b/idea/testData/jetPsiMatcher/types/user1.kt.2 new file mode 100644 index 00000000000..809fba40a0e --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/user1.kt.2 @@ -0,0 +1 @@ +val y: Collection \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/user2.kt b/idea/testData/jetPsiMatcher/types/user2.kt new file mode 100644 index 00000000000..3715d26a30f --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/user2.kt @@ -0,0 +1 @@ +val x: Map> \ No newline at end of file diff --git a/idea/testData/jetPsiMatcher/types/user2.kt.2 b/idea/testData/jetPsiMatcher/types/user2.kt.2 new file mode 100644 index 00000000000..95a905d3a30 --- /dev/null +++ b/idea/testData/jetPsiMatcher/types/user2.kt.2 @@ -0,0 +1 @@ +val y: Map> \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/psi/AbstractJetPsiMatcherTest.java b/idea/tests/org/jetbrains/jet/psi/AbstractJetPsiMatcherTest.java index 912904ce789..cf35da9fa89 100644 --- a/idea/tests/org/jetbrains/jet/psi/AbstractJetPsiMatcherTest.java +++ b/idea/tests/org/jetbrains/jet/psi/AbstractJetPsiMatcherTest.java @@ -24,6 +24,7 @@ import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; import org.jetbrains.jet.config.CompilerConfiguration; import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetPsiFactory; +import org.jetbrains.jet.lang.psi.JetTypeReference; import org.jetbrains.jet.plugin.util.JetPsiMatcher; import java.io.File; @@ -44,6 +45,24 @@ public abstract class AbstractJetPsiMatcherTest extends JetLiteFixture { ); } + public void doTestTypes(@NotNull String path) throws Exception { + String fileText = FileUtil.loadFile(new File(path)); + String fileText2 = FileUtil.loadFile(new File(path + ".2")); + + boolean equalityExpected = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// NOT_EQUAL") == null; + + JetTypeReference typeRef = JetPsiFactory.createProperty(getProject(), fileText).getTypeRef(); + JetTypeReference typeRef2 = JetPsiFactory.createProperty(getProject(), fileText2).getTypeRef(); + + assertNotNull(typeRef); + assertNotNull(typeRef2); + + assertTrue( + "JetPsiMatcher.checkElementMatch() should return " + equalityExpected, + equalityExpected == JetPsiMatcher.checkElementMatch(typeRef, typeRef2) + ); + } + @Override protected JetCoreEnvironment createEnvironment() { return new JetCoreEnvironment(getTestRootDisposable(), new CompilerConfiguration()); diff --git a/idea/tests/org/jetbrains/jet/psi/JetPsiMatcherTest.java b/idea/tests/org/jetbrains/jet/psi/JetPsiMatcherTest.java index 08c57f91d9b..c365371af18 100644 --- a/idea/tests/org/jetbrains/jet/psi/JetPsiMatcherTest.java +++ b/idea/tests/org/jetbrains/jet/psi/JetPsiMatcherTest.java @@ -30,13 +30,8 @@ import org.jetbrains.jet.psi.AbstractJetPsiMatcherTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@TestMetadata("idea/testData/jetPsiMatcher") -@InnerTestClasses({JetPsiMatcherTest.Expressions.class}) +@InnerTestClasses({JetPsiMatcherTest.Expressions.class, JetPsiMatcherTest.Types.class}) public class JetPsiMatcherTest extends AbstractJetPsiMatcherTest { - public void testAllFilesPresentInJetPsiMatcher() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/jetPsiMatcher"), Pattern.compile("^(.+)\\.kt$"), true); - } - @TestMetadata("idea/testData/jetPsiMatcher/expressions") @InnerTestClasses({Expressions.ArrayAccess.class, Expressions.BinaryExpr.class, Expressions.Call.class, Expressions.Const.class, Expressions.Misc.class, Expressions.SimpleName.class, Expressions.Super.class, Expressions.Throw.class, Expressions.UnaryExpr.class}) public static class Expressions extends AbstractJetPsiMatcherTest { @@ -377,10 +372,73 @@ public class JetPsiMatcherTest extends AbstractJetPsiMatcherTest { } } + @TestMetadata("idea/testData/jetPsiMatcher/types") + public static class Types extends AbstractJetPsiMatcherTest { + public void testAllFilesPresentInTypes() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/jetPsiMatcher/types"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("functional1.kt") + public void testFunctional1() throws Exception { + doTestTypes("idea/testData/jetPsiMatcher/types/functional1.kt"); + } + + @TestMetadata("functional2.kt") + public void testFunctional2() throws Exception { + doTestTypes("idea/testData/jetPsiMatcher/types/functional2.kt"); + } + + @TestMetadata("functional3.kt") + public void testFunctional3() throws Exception { + doTestTypes("idea/testData/jetPsiMatcher/types/functional3.kt"); + } + + @TestMetadata("nullable1.kt") + public void testNullable1() throws Exception { + doTestTypes("idea/testData/jetPsiMatcher/types/nullable1.kt"); + } + + @TestMetadata("user1.kt") + public void testUser1() throws Exception { + doTestTypes("idea/testData/jetPsiMatcher/types/user1.kt"); + } + + @TestMetadata("user2.kt") + public void testUser2() throws Exception { + doTestTypes("idea/testData/jetPsiMatcher/types/user2.kt"); + } + + @TestMetadata("_functional1.kt") + public void test_functional1() throws Exception { + doTestTypes("idea/testData/jetPsiMatcher/types/_functional1.kt"); + } + + @TestMetadata("_functional2.kt") + public void test_functional2() throws Exception { + doTestTypes("idea/testData/jetPsiMatcher/types/_functional2.kt"); + } + + @TestMetadata("_nullable1.kt") + public void test_nullable1() throws Exception { + doTestTypes("idea/testData/jetPsiMatcher/types/_nullable1.kt"); + } + + @TestMetadata("_user1.kt") + public void test_user1() throws Exception { + doTestTypes("idea/testData/jetPsiMatcher/types/_user1.kt"); + } + + @TestMetadata("_user2.kt") + public void test_user2() throws Exception { + doTestTypes("idea/testData/jetPsiMatcher/types/_user2.kt"); + } + + } + public static Test suite() { TestSuite suite = new TestSuite("JetPsiMatcherTest"); - suite.addTestSuite(JetPsiMatcherTest.class); suite.addTest(Expressions.innerSuite()); + suite.addTestSuite(Types.class); return suite; } }