Skip to content

Commit

Permalink
Unit tests for target annotations selection, workaround for ceylon bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Voiteh committed Jun 22, 2019
1 parent b2c0dff commit 5bbb874
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
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);
}
}

0 comments on commit 5bbb874

Please sign in to comment.