From 293350d1ad8e701577bfd5a85fb16ec162f9f5aa Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Sat, 10 Jun 2017 13:08:20 -0500 Subject: [PATCH] Fix for issue #303: DSL tests require certain content assist preferences --- .../dsl/tests/DSLContentAssistTests.groovy | 40 +++++++----- .../dsl/tests/DSLInferencingTests.groovy | 25 +++++--- .../DSLNamedArgContentAssistTests.groovy | 63 ++++++++++--------- 3 files changed, 75 insertions(+), 53 deletions(-) diff --git a/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLContentAssistTests.groovy b/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLContentAssistTests.groovy index 93a98a6d6c..aad46cdba4 100644 --- a/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLContentAssistTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLContentAssistTests.groovy @@ -17,6 +17,7 @@ package org.codehaus.groovy.eclipse.dsl.tests import static org.junit.Assume.assumeTrue +import org.codehaus.groovy.eclipse.codeassist.GroovyContentAssist import org.codehaus.groovy.eclipse.codeassist.tests.CompletionTestSuite import org.codehaus.groovy.eclipse.dsl.GroovyDSLCoreActivator import org.eclipse.core.resources.IFile @@ -24,6 +25,8 @@ import org.eclipse.core.resources.IProject import org.eclipse.jface.text.Document import org.eclipse.jface.text.contentassist.ICompletionProposal import org.junit.Before +import org.junit.BeforeClass +import org.junit.Ignore import org.junit.Test final class DSLContentAssistTests extends CompletionTestSuite { @@ -54,12 +57,14 @@ final class DSLContentAssistTests extends CompletionTestSuite { } '''.stripIndent() + @BeforeClass + static void setUpTests() { + GroovyContentAssist.default.preferenceStore.setValue(GroovyContentAssist.PARAMETER_GUESSING, true) + } + @Before void setUp() { assumeTrue(!GroovyDSLCoreActivator.default.isDSLDDisabled()) - - addClasspathContainer(GroovyDSLCoreActivator.CLASSPATH_CONTAINER_ID) - DSLInferencingTestSuite.refreshExternalFoldersProject() withProject { IProject project -> GroovyDSLCoreActivator.default.contextStoreManager.initialize(project, true) //GroovyDSLCoreActivator.default.contextStoreManager.ignoreProject(project) @@ -79,23 +84,25 @@ final class DSLContentAssistTests extends CompletionTestSuite { // - @Test + @Test @Ignore('Proposal "instance" appears twice in the result') void testDSLProposalFirstStaticField() { String contents = '''\ @Singleton class Foo { static aaa } - Foo. + Foo.i '''.stripIndent() - ICompletionProposal[] proposals = orderByRelevance(createProposalsAtOffset(contents, getIndexOf(contents, '.'))) + ICompletionProposal[] proposals = orderByRelevance(createProposalsAtOffset(contents, getIndexOf(contents, '.i'))) + // contributed by built-in DLSD for @Singleton AST transform assertProposalOrdering(proposals, 'instance', 'aaa') } - @Test + @Test @Ignore('Proposal "getInstance" appears twice in the result') void testDSLProposalFirstStaticMethod() { String contents = '''\ @Singleton class Foo { static aaa() { } } - Foo. + Foo.g '''.stripIndent() - ICompletionProposal[] proposals = orderByRelevance(createProposalsAtOffset(contents, getIndexOf(contents, '.'))) + ICompletionProposal[] proposals = orderByRelevance(createProposalsAtOffset(contents, getIndexOf(contents, '.g'))) + // contributed by built-in DLSD for @Singleton AST transform assertProposalOrdering(proposals, 'getInstance', 'aaa') } @@ -104,22 +111,25 @@ final class DSLContentAssistTests extends CompletionTestSuite { String contents = '''\ import groovy.swing.SwingBuilder new SwingBuilder().edt { - delegate.x + delegate.f } '''.stripIndent() - ICompletionProposal[] proposals = orderByRelevance(createProposalsAtOffset(contents, getIndexOf(contents, 'delegate.'))) - assertProposalOrdering(proposals, 'frame', 'registerBinding') + ICompletionProposal[] proposals = orderByRelevance(createProposalsAtOffset(contents, getIndexOf(contents, 'delegate.f'))) + // contributed by built-in DSLD for SwingBuilder + assertProposalOrdering(proposals, 'frame', 'find') } @Test void testDSLProposalFirstMethod2() { String contents = '''\ import groovy.swing.SwingBuilder - new SwingBuilder().edt { + new SwingBuilder().edt { + fr } '''.stripIndent() - ICompletionProposal[] proposals = orderByRelevance(createProposalsAtOffset(contents, getIndexOf(contents, '{\n'))) - assertProposalOrdering(proposals, 'frame', 'registerBinding') + ICompletionProposal[] proposals = orderByRelevance(createProposalsAtOffset(contents, getIndexOf(contents, 'fr'))) + // contributed by built-in DSLD for SwingBuilder + assertProposalOrdering(proposals, 'frame', 'FrameFactory') } @Test // proposals should not exist since not applied to 'this' diff --git a/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLInferencingTests.groovy b/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLInferencingTests.groovy index 8f598cd49c..a6a77688be 100644 --- a/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLInferencingTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLInferencingTests.groovy @@ -15,6 +15,8 @@ */ package org.codehaus.groovy.eclipse.dsl.tests +import groovy.transform.NotYetImplemented + import org.codehaus.jdt.groovy.model.GroovyCompilationUnit import org.eclipse.jdt.core.groovy.tests.search.InferencingTestSuite import org.junit.Before @@ -849,14 +851,17 @@ final class DSLInferencingTests extends DSLInferencingTestSuite { @Test // GRECLIPSE-1459 void testNullType() { - createDsls('contribute(enclosingCall(hasArgument(type()))) {\n' + - ' property name:"foo", type:Integer\n' + - '}') - String contents = 'String flart(val, closure) { }\n' + - '\n' + - 'flart "", {\n' + - ' foo\n' + - '}' + createDsls '''\ + contribute(enclosingCall(hasArgument(type()))) { + property name:"foo", type:Integer + } + '''.stripIndent() + String contents = '''\ + String flart(val, closure) { } + flart "", { + foo + } + '''.stripIndent() int start = contents.lastIndexOf('fo') int end = start + 'foo'.length() assertType(contents, start, end, 'java.lang.Integer') @@ -893,14 +898,14 @@ final class DSLInferencingTests extends DSLInferencingTestSuite { assertType(contents, 0, contents.length(), 'java.util.List') } - @Test @Ignore // TODO expected to fail + @Test @NotYetImplemented void testArrayType4() { createDsls(ARRAY_TYPE_DSLD) String contents = 'foot4' assertType(contents, 0, contents.length(), 'java.util.List[]') } - @Test @Ignore // TODO expected to fail + @Test @NotYetImplemented void testArrayType5() { createDsls(ARRAY_TYPE_DSLD) String contents = 'foot5' diff --git a/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLNamedArgContentAssistTests.groovy b/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLNamedArgContentAssistTests.groovy index f2fa29c2a6..724f4d081c 100644 --- a/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLNamedArgContentAssistTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.dsl.tests/src/org/codehaus/groovy/eclipse/dsl/tests/DSLNamedArgContentAssistTests.groovy @@ -17,21 +17,28 @@ package org.codehaus.groovy.eclipse.dsl.tests import static org.junit.Assume.assumeTrue +import org.codehaus.groovy.eclipse.codeassist.GroovyContentAssist import org.codehaus.groovy.eclipse.codeassist.tests.CompletionTestSuite import org.codehaus.groovy.eclipse.dsl.GroovyDSLCoreActivator import org.eclipse.core.resources.IProject import org.eclipse.jface.text.contentassist.ICompletionProposal import org.junit.Before +import org.junit.BeforeClass import org.junit.Test final class DSLNamedArgContentAssistTests extends CompletionTestSuite { + @BeforeClass + static void setUpTests() { + GroovyContentAssist.default.preferenceStore.setValue(GroovyContentAssist.CLOSURE_BRACKETS, true) + GroovyContentAssist.default.preferenceStore.setValue(GroovyContentAssist.CLOSURE_NOPARENS, true) + GroovyContentAssist.default.preferenceStore.setValue(GroovyContentAssist.NAMED_ARGUMENTS, true) + GroovyContentAssist.default.preferenceStore.setValue(GroovyContentAssist.PARAMETER_GUESSING, true) + } + @Before void setUp() { assumeTrue(!GroovyDSLCoreActivator.default.isDSLDDisabled()) - - addClasspathContainer(GroovyDSLCoreActivator.CLASSPATH_CONTAINER_ID) - DSLInferencingTestSuite.refreshExternalFoldersProject() withProject { IProject project -> GroovyDSLCoreActivator.default.contextStoreManager.initialize(project, true) //GroovyDSLCoreActivator.default.contextStoreManager.ignoreProject(project) @@ -47,7 +54,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testNamedArgs1() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", params:[aaa:Integer, bbb:Boolean, ccc:String], useNamedArgs:true } '''.stripIndent() @@ -62,7 +69,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testNoNamedArgs1() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", params:[aaa:Integer, bbb:Boolean, ccc:String], useNamedArgs:false } '''.stripIndent() @@ -77,7 +84,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testNamedArgs2() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", params:[aaa:Integer, bbb:Boolean, ccc:String], useNamedArgs:true } '''.stripIndent() @@ -92,7 +99,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testNamedArgs3() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", params:[aaa:Integer, bbb:Boolean, ccc:String], useNamedArgs:true } '''.stripIndent() @@ -107,7 +114,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testNamedArgs4() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", params:[aaa:Integer, bbb:Boolean, ccc:String], useNamedArgs:true } '''.stripIndent() @@ -122,7 +129,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testNamedArgs5() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", params:[aaa:Integer, bbb:Boolean, ccc:String], useNamedArgs:true } '''.stripIndent() @@ -137,7 +144,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testNoNamedArgs6() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", params:[aaa:Integer, bbb:Boolean, ccc:String], useNamedArgs:false } '''.stripIndent() @@ -152,7 +159,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testOptionalArgs1() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", optionalParams:[aaa:Integer, bbb:Boolean, ccc:String] } '''.stripIndent() @@ -167,7 +174,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testOptionalArgs2() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", namedParams:[aaa:Integer, bbb:Boolean, ccc:String] } '''.stripIndent() @@ -182,7 +189,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testOptionalArgs3() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", namedParams:[aaa:Integer], optionalParams: [bbb:Boolean, ccc:String] } '''.stripIndent() @@ -197,7 +204,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testNamedArgs7() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", params:[aaa:Integer, bbb:Boolean, ccc:String], useNamedArgs:true } '''.stripIndent() @@ -215,7 +222,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testNamedArgs8() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", params:[aaa:Integer, bbb:Boolean, ccc:String], useNamedArgs:true } '''.stripIndent() @@ -233,7 +240,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testParamGuessing1() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", params:[aaa:Integer, bbb:Boolean, ccc:String], useNamedArgs:true } '''.stripIndent() @@ -249,7 +256,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testParamGuessing3() { createDSL '''\ - currentType().accept { + contribute(currentType()) { method name:"flar", params:[aaa:Integer, bbb:Boolean, ccc:String], useNamedArgs:true } '''.stripIndent() @@ -265,7 +272,7 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { } // tests application of closures with and without named parameters - private static final String closuredsld = '''\ + private static final String CLOSURE_DSLD = '''\ contribute(currentType('Clos')) { method name: 'test1', params: [op:Closure] method name: 'test2', params: [first: String, op:Closure] @@ -285,61 +292,61 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite { @Test void testClostureOp1() { - createDSL(closuredsld) + createDSL(CLOSURE_DSLD) checkProposalApplicationNonType(closureContents, closureContents + '1 {', closureContents.length(), 'test1') } @Test void testClostureOp2() { - createDSL(closuredsld) + createDSL(CLOSURE_DSLD) checkProposalApplicationNonType(closureContents, closureContents + '2("") {', closureContents.length(), 'test2') } @Test void testClostureOp3() { - createDSL(closuredsld) + createDSL(CLOSURE_DSLD) checkProposalApplicationNonType(closureContents, closureContents + '3(op:{ })', closureContents.length(), 'test3') } @Test void testClostureOp4() { - createDSL(closuredsld) + createDSL(CLOSURE_DSLD) checkProposalApplicationNonType(closureContents, closureContents + '4(first:"", op:{ })', closureContents.length(), 'test4') } @Test void testClostureOp5() { - createDSL(closuredsld) + createDSL(CLOSURE_DSLD) checkProposalApplicationNonType(closureContents, closureContents + '5("", op:{ })', closureContents.length(), 'test5') } @Test void testClostureOp6() { - createDSL(closuredsld) + createDSL(CLOSURE_DSLD) checkProposalApplicationNonType(closureContents, closureContents + '6(first:"") {', closureContents.length(), 'test6') } @Test void testClostureOp7() { - createDSL(closuredsld) + createDSL(CLOSURE_DSLD) checkProposalApplicationNonType(closureContents, closureContents + '7(first:"", other:"") {', closureContents.length(), 'test7') } @Test void testClostureOp8() { - createDSL(closuredsld) + createDSL(CLOSURE_DSLD) checkProposalApplicationNonType(closureContents, closureContents + '8("", first:"") {', closureContents.length(), 'test8') } @Test void testClostureOp9() { - createDSL(closuredsld) + createDSL(CLOSURE_DSLD) checkProposalApplicationNonType(closureContents, closureContents + '9("", { }, "", first:"")', closureContents.length(), 'test9') } @Test void testClostureOp0() { - createDSL(closuredsld) + createDSL(CLOSURE_DSLD) checkProposalApplicationNonType(closureContents, closureContents + '0("", { }, "", first:"") {', closureContents.length(), 'test0') } }