This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 39ced53e04 add trait tests
39ced53e04 is described below
commit 39ced53e046cf2f5cad4ac8babc3ee4995642b07
Author: Eric Milles <[email protected]>
AuthorDate: Fri Sep 19 11:43:06 2025 -0500
add trait tests
---
.../traitx/TraitASTTransformationTest.groovy | 84 ++++++++++++++++++----
1 file changed, 71 insertions(+), 13 deletions(-)
diff --git
a/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
b/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
index acdb2dc6ce..b697369a4f 100644
---
a/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
+++
b/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
@@ -393,33 +393,91 @@ final class TraitASTTransformationTest {
@Test
void testOverridePropertyDefinedInTrait() {
assertScript shell, '''
- trait Id {
- Long id = 123L
+ trait Foo {
+ long id = 123L
}
-
- class Foo implements Id {
- Long id = 456L
+ class Bar implements Foo {
+ long id = 456L
}
- def f = new Foo()
- assert f.id == 456L
+
+ def pogo = new Bar()
+ assert pogo.id == 456L
+ assert pogo.getId() == 456L
'''
}
@Test
void testOverridePropertyGetterDefinedInTrait() {
assertScript shell, '''
- trait Id {
- Long id = 123L
+ trait Foo {
+ long id = 123L
}
+ class Bar implements Foo {
+ long getId() { 456L }
+ }
+
+ def pogo = new Bar()
+ assert pogo.id == 456L
+ assert pogo.getId() == 456L
+ '''
+ }
- class Foo implements Id {
- Long getId() { 456L }
+ @Test
+ void testShadowingPropertyGetterDefinedInTrait() {
+ assertScript shell, '''
+ trait Foo {
+ private long getId() { 123L }
}
- def f = new Foo()
- assert f.id == 456L
+ trait Bar extends Foo {
+ long id = 456L
+ }
+ class Baz implements Bar {
+ }
+
+ def pogo = new Baz()
+ assert pogo.id == 456L
+ assert pogo.getId() == 456L
'''
}
+ @ParameterizedTest
+ @ValueSource(strings=['public',/*TODO:'protected',*/'private'])
+ void testFinalPropertyGetterDefinedInSuperClass(String modifier) {
+ assertScript shell, """
+ trait Foo {
+ final long id = 123L
+ }
+ class Bar {
+ $modifier final long getId() { 456L }
+ }
+ class Baz extends Bar implements Foo {
+ }
+
+ def pogo = new Baz()
+ assert pogo.id == ${modifier == 'private' ? '123L' : '456L'}
+ assert pogo.getId() == ${modifier == 'private' ? '123L' : '456L'}
+ """
+ }
+
+ @ParameterizedTest
+
@ValueSource(strings=['private','@PackageScope','protected','public','static'])
+ void testNonFinalPropertyGetterDefinedInSuperClass(String modifier) {
+ assertScript shell, """
+ trait Foo {
+ long id = 123L
+ }
+ class Bar {
+ $modifier long getId() { 456L }
+ }
+ class Baz extends Bar implements Foo {
+ }
+
+ def pogo = new Baz()
+ assert pogo.id == 123L
+ assert pogo.getId() == 123L
+ """
+ }
+
@Test
void testSimpleTraitInheritance() {
assertScript shell, '''