Skip to content

Commit

Permalink
GROOVY-5714: More @DelegatesTo unit tests (tests rewrite of "with")
Browse files Browse the repository at this point in the history
  • Loading branch information
melix committed Oct 2, 2012
1 parent 6c4c0bb commit 68c7a5c
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions src/test/groovy/transform/stc/DelegatesToSTCTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,96 @@ class DelegatesToSTCTest extends StaticTypeCheckingTestCase {
'''
}

void testEmbeddedWithAndShadowing() {
assertScript '''
class A {
int foo() { 1 }
}
class B {
int foo() { 2 }
}
def a = new A()
def b = new B()
int result
a.with {
b.with {
result = foo()
}
}
assert result == 2
'''
}

void testEmbeddedWithAndShadowing2() {
assertScript '''
class A {
int foo() { 1 }
}
class B {
int foo() { 2 }
}
def a = new A()
def b = new B()
int result
b.with {
a.with {
result = foo()
}
}
assert result == 1
'''
}

void testEmbeddedWithAndShadowing3() {
assertScript '''
class A {
int foo() { 1 }
}
class B {
int foo() { 2 }
}
class C {
int foo() { 3 }
void test() {
def a = new A()
def b = new B()
int result
b.with {
a.with {
result = foo()
}
}
assert result == 1
}
}
new C().test()
'''
}

void testEmbeddedWithAndShadowing4() {
assertScript '''
class A {
int foo() { 1 }
}
class B {
int foo() { 2 }
}
class C {
int foo() { 3 }
void test() {
def a = new A()
def b = new B()
int result
b.with {
a.with {
result = this.foo()
}
}
assert result == 3
}
}
new C().test()
'''
}

}

0 comments on commit 68c7a5c

Please sign in to comment.