From bdb8e7ce0f7733bfa9fe650ec96e56d06c306291 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Fri, 29 Jun 2018 17:54:40 +0300 Subject: [PATCH] [groovy] add tests for 'for' variables --- .../lang/resolve/ResolveLocalTest.groovy | 34 +++++++++++++++++++ .../lang/resolve/ResolvePropertyTest.groovy | 9 ----- .../property/forVariable1/ForVariable.groovy | 7 ---- .../property/forVariable2/ForVariable.groovy | 7 ---- 4 files changed, 34 insertions(+), 23 deletions(-) delete mode 100644 plugins/groovy/testdata/resolve/property/forVariable1/ForVariable.groovy delete mode 100644 plugins/groovy/testdata/resolve/property/forVariable2/ForVariable.groovy diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveLocalTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveLocalTest.groovy index 4a02dc505384..16e896a063dd 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveLocalTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveLocalTest.groovy @@ -52,4 +52,38 @@ class ResolveLocalTest implements ResolveTest { void 'parameter from resource initializer'() { resolveTest 'def foo(param) { try (def a = param) {} }', GrParameter } + + @Test + void 'for variable from for block'() { + resolveTest 'for (def e;;){ e }', GrVariable + } + + @Test + void 'for variable from for condition'() { + resolveTest 'for (def e;e;){}', GrVariable + } + + @Test + void 'for variable from for update'() { + resolveTest 'for (def e;;e){}', GrVariable + } + + @Test + void 'for variable from for-each expression'() { + resolveTest 'for (e : e) {}', null + resolveTest 'for (e in e) {}', null + } + + @Test + void 'for variable from for-each block'() { + resolveTest 'for (e : b) { e }', GrVariable + resolveTest 'for (e in b) { e }', GrVariable + } + + @Test + void 'for variable after for'() { + resolveTest 'for (def e;;) {}; e', null + resolveTest 'for (e : b) {}; e', null + resolveTest 'for (e in b) {}; e', null + } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolvePropertyTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolvePropertyTest.groovy index d0cdf9440bb5..9662f65a1897 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolvePropertyTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolvePropertyTest.groovy @@ -58,11 +58,6 @@ class ResolvePropertyTest extends GroovyResolveTestCase { doTest("field2/A.groovy") } - void testForVariable1() throws Exception { - disableTransformations testRootDisposable - resolve "ForVariable.groovy", GrParameter - } - void testArrayLength() throws Exception { doTest("arrayLength/A.groovy") } @@ -87,10 +82,6 @@ class ResolvePropertyTest extends GroovyResolveTestCase { assertTrue(ref.resolve() instanceof GrAccessorMethod) } - void _testForVariable2() throws Exception { - doTest("forVariable2/ForVariable.groovy") - } - void testCatchParameter() throws Exception { disableTransformations testRootDisposable resolve "CatchParameter.groovy", GrParameter diff --git a/plugins/groovy/testdata/resolve/property/forVariable1/ForVariable.groovy b/plugins/groovy/testdata/resolve/property/forVariable1/ForVariable.groovy deleted file mode 100644 index af3e8ae9ed00..000000000000 --- a/plugins/groovy/testdata/resolve/property/forVariable1/ForVariable.groovy +++ /dev/null @@ -1,7 +0,0 @@ -class ForVariable { - def foo = { - for (i in is) { - def e = i - } - } -} \ No newline at end of file diff --git a/plugins/groovy/testdata/resolve/property/forVariable2/ForVariable.groovy b/plugins/groovy/testdata/resolve/property/forVariable2/ForVariable.groovy deleted file mode 100644 index b7589f934c29..000000000000 --- a/plugins/groovy/testdata/resolve/property/forVariable2/ForVariable.groovy +++ /dev/null @@ -1,7 +0,0 @@ -class ForVariable { - def foo = { - for (def i = 0, j = 0;;) { - def e = j - } - } -} \ No newline at end of file