This is an automated email from the ASF dual-hosted git repository.
paulk 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 b586919e3f GROOVY-11151: Example in the Documentation of the Coercion
Operator is Wrong
b586919e3f is described below
commit b586919e3f1f67cfaebea23e515ccaea6d0b3ad3
Author: Paul King <[email protected]>
AuthorDate: Tue Aug 8 14:07:46 2023 +1000
GROOVY-11151: Example in the Documentation of the Coercion Operator is Wrong
---
src/spec/test/OperatorsTest.groovy | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/spec/test/OperatorsTest.groovy
b/src/spec/test/OperatorsTest.groovy
index a37b369fd9..c12185674d 100644
--- a/src/spec/test/OperatorsTest.groovy
+++ b/src/spec/test/OperatorsTest.groovy
@@ -629,15 +629,17 @@ assert function(*args,5,6) == 26
void testCoercionOperator() {
try {
// tag::coerce_op_cast[]
- Integer x = 123
- String s = (String) x // <1>
+ String input = '42'
+ Integer num = (Integer) input // <1>
// end::coerce_op_cast[]
+ assert false, 'Should not reach here but instead should have
thrown a ClassCastException'
} catch (ClassCastException e) {
+ assert e.message == "Cannot cast object '42' with class
'java.lang.String' to class 'java.lang.Integer'"
// tag::coerce_op[]
- Integer x = 123
- String s = x as String // <1>
+ String input = '42'
+ Integer num = input as Integer // <1>
// end::coerce_op[]
- assert s == '123'
+ assert num == 42
}
assertScript '''
// tag::coerce_op_custom[]