You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/10/16 07:02:47 UTC
[groovy] branch master updated: Add one more test case for record
This is an automated email from the ASF dual-hosted git repository.
sunlan 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 9f0f27d Add one more test case for record
9f0f27d is described below
commit 9f0f27d36caa6aace2501b9198c863855499687e
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Oct 16 15:01:13 2021 +0800
Add one more test case for record
---
.../org/codehaus/groovy/classgen/RecordTest.groovy | 48 ++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy b/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy
index edcb0cb..1d2dd93 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy
+++ b/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy
@@ -267,4 +267,52 @@ class RecordTest {
assert 22 == m.getParameterCount()
'''
}
+
+ @Test
+ void testCoerce() {
+ assertScript '''
+ record PersonDynamic(String name, int age) {}
+ @groovy.transform.CompileStatic
+ record PersonStatic(String name, int age) {}
+
+ def testDynamic() {
+ PersonDynamic p = ['Daniel', 37]
+ assert 'Daniel' == p.name()
+ assert 37 == p.age()
+
+ PersonDynamic p2 = [age: 37, name: 'Daniel']
+ assert 'Daniel' == p2.name()
+ assert 37 == p2.age()
+
+ PersonStatic p3 = ['Daniel', 37]
+ assert 'Daniel' == p3.name()
+ assert 37 == p3.age()
+
+ PersonStatic p4 = [age: 37, name: 'Daniel']
+ assert 'Daniel' == p4.name()
+ assert 37 == p4.age()
+ }
+ testDynamic()
+
+ @groovy.transform.CompileStatic
+ def testStatic() {
+ PersonStatic p = ['Daniel', 37]
+ assert 'Daniel' == p.name()
+ assert 37 == p.age()
+
+ PersonStatic p2 = [age: 37, name: 'Daniel']
+ assert 'Daniel' == p2.name()
+ assert 37 == p2.age()
+
+ PersonDynamic p3 = ['Daniel', 37]
+ assert 'Daniel' == p3.name()
+ assert 37 == p3.age()
+
+ PersonDynamic p4 = [age: 37, name: 'Daniel']
+ assert 'Daniel' == p4.name()
+ assert 37 == p4.age()
+ }
+ testStatic()
+ '''
+ }
}