Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for target annotations selection, workaround for ceylon bu… #16

Merged
merged 1 commit into from
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions source/herd/depin/engine/DefaultResolver.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ import ceylon.language.meta {
shared class DefaultResolver(Registry registry) satisfies Resolver{
shared actual Dependency resolve(Declaration declaration) {
if(is TypedDeclaration&AnnotatedDeclaration declaration){

value annotations = declaration.annotations<Annotation>()
variable {Annotation*} annotations;
try{
annotations = declaration.annotations<Annotation>()
.select((Annotation element) => registry.controls.contains(type(element)));
}catch(Exception x){
//Ceylon BUG!!! We can't identifiy parameter by annotations but for now we can use name of the parameter.
//This will be enough for most of cases.
annotations={NamedAnnotation(declaration.name)};
}
return Dependency{
type = declaration.openType;
identification = if (annotations.empty && registry.controls.contains(`NamedAnnotation`))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import ceylon.test {
test,
ignore
}
shared class ConstructorTestClass{
String param;
shared new (String param){
this.param = param;}
}

shared class AnnotationsFromConstructorParameter() {

ignore
shared test void shouldGetAnnotationsFromConstructorParameter(){
assert (exists constructor = `class ConstructorTestClass`.defaultConstructor);
assert(exists param=constructor.parameterDeclarations.first);
assert(param.annotations<Annotation>().empty);
}


}
1 change: 1 addition & 0 deletions test/test/herd/depin/engine/ceylon/package.ceylon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shared package test.herd.depin.engine.ceylon;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ceylon.test {
test
test,
ignore
}

import herd.depin.engine {
Expand All @@ -12,7 +13,8 @@ import test.herd.depin.engine.integration.model {
DataSource,
DefaultParametersConstructor,
DefaultedParametersByFunction,
DefaultedParameterFunction
DefaultedParameterFunction,
TargetWithTwoCallableConstructors
}
shared class ClassInjectionTest() {

Expand All @@ -36,4 +38,8 @@ shared class ClassInjectionTest() {
shared test void shouldInjectDefaultedParameterClassFunction(){
assert(depin.inject(`DefaultedParameterFunction`).fun()==fixture.defaultedParameterFunction.param);
}
ignore("until https://github.com/eclipse/ceylon/issues/7448 fixed")
shared test void shouldInjectTargetedConstructor(){
assert(depin.inject(`TargetWithTwoCallableConstructors`).something==fixture.targetWithTwoCallableConstructors.param.reversed);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import test.herd.depin.engine.integration.model {
fixture
}
import herd.depin.engine {
dependency
}
shared dependency String something =fixture.targetWithTwoCallableConstructors.param;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import herd.depin.engine {
target,
named
}
shared class TargetWithTwoCallableConstructors {

shared String something;
shared new (String something){
this.something = something;

}

shared target new targetedConstructor(named("Abc") String something){
this.something=something.reversed;
}

}
4 changes: 4 additions & 0 deletions test/test/herd/depin/engine/integration/model/fixture.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ shared object fixture {
shared object defaultedParameterFunction {
shared String param = "abc";
}
shared object targetWithTwoCallableConstructors{
shared String param ="abc";
shared TargetWithTwoCallableConstructors instance= TargetWithTwoCallableConstructors(param);
}
}