You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2025/08/04 00:24:18 UTC
(groovy) 03/06: GROOVY-8162: Update Groovysh to JLine3 (add test for /methods)
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
commit 6c18138296bab1ee16935e190f58574822ca29d3
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Aug 4 09:32:13 2025 +1000
GROOVY-8162: Update Groovysh to JLine3 (add test for /methods)
---
.../apache/groovy/groovysh/jline/GroovyEngine.java | 9 ++++--
.../groovy/groovysh/commands/MethodsTest.groovy | 35 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
index fc886f1b68..109fe5a698 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
@@ -644,12 +644,15 @@ public class GroovyEngine implements ScriptEngine {
methodNames.remove(prefix);
} else {
methodNames.remove(name);
- methods.keySet().forEach(k -> {
+ Iterator<String> it = methods.keySet().iterator();
+ while (it.hasNext()) {
+ String k = it.next();
if (k.equals(name) || k.startsWith(name + "(")) {
- Integer gone = methods.remove(k);
+ Integer gone = methods.get(k);
if (gone != null) snippets.set(gone, null);
+ it.remove();
}
- });
+ }
}
}
diff --git a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/MethodsTest.groovy b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/MethodsTest.groovy
new file mode 100644
index 0000000000..59cfb70a95
--- /dev/null
+++ b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/MethodsTest.groovy
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.groovy.groovysh.commands
+
+/**
+ * Tests for the {@code /methods} command.
+ */
+class MethodsTest extends SystemTestSupport {
+ void testImport() {
+ system.execute('/methods')
+ assert !printer.output.join().contains('twice')
+ system.execute('def twice(n){ n * 2 }')
+ system.execute('/methods')
+ assert printer.output.join().contains('def twice(n){ n * 2 }')
+ assert engine.methodNames.contains('twice')
+ system.execute('/methods -d twice')
+ assert !engine.methodNames.contains('twice')
+ }
+}