Skip to content

Commit

Permalink
Fix for issue #303: DSL tests require certain content assist preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jun 10, 2017
1 parent bf6d6d3 commit 293350d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ 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
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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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')
}

Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -893,14 +898,14 @@ final class DSLInferencingTests extends DSLInferencingTestSuite {
assertType(contents, 0, contents.length(), 'java.util.List<java.lang.String[][]>')
}

@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<java.lang.String>[]')
}

@Test @Ignore // TODO expected to fail
@Test @NotYetImplemented
void testArrayType5() {
createDsls(ARRAY_TYPE_DSLD)
String contents = 'foot5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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]
Expand All @@ -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')
}
}

0 comments on commit 293350d

Please sign in to comment.