Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(java): enable .java filename completion for java command #1197

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions completions/java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ _comp_cmd_java()
else
# classes completion
_comp_cmd_java__classes
# support for launching source-code
# programs (JEP 330, JEP 458)
_comp_compgen -a filedir 'java'
fi
fi

Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/java/JEP330.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* The java launcher is able to run a program
* supplied as a single file of Java source code.
*
* @see <a href="https://openjdk.java.net/jeps/330">JEP 330: Launch Single-File Source-Code Programs</a>
* @see <a href="https://openjdk.java.net/jeps/458">JEP 458: Launch Multi-File Source-Code Programs</a>
*/
class JEP330 {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
32 changes: 20 additions & 12 deletions test/t/test_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,40 @@ def can_list_jar(self, bash):
def test_1(self, completion):
assert completion

@pytest.mark.complete("java ")
@pytest.mark.complete("java ", cwd="java")
def test_2(self, completion, can_list_jar):
if can_list_jar:
assert completion == "b bashcomp.jarred c. toplevel".split()
assert (
completion
== "JEP330.java a/ b bashcomp.jarred c. toplevel".split()
)
else:
assert completion == "b c.".split()
assert completion == "JEP330.java a/ b c.".split()

@pytest.mark.complete("java -classpath java/bashcomp.jar ")
@pytest.mark.complete("java -classpath bashcomp.jar ", cwd="java")
def test_3(self, completion, can_list_jar):
if can_list_jar:
assert completion == "bashcomp.jarred toplevel".split()
assert (
completion == "JEP330.java a/ bashcomp.jarred toplevel".split()
)
else:
assert not completion
assert completion == "JEP330.java a/".split()

@pytest.mark.complete("java -cp java/bashcomp.jar:java/a/c ")
@pytest.mark.complete("java -cp bashcomp.jar:a/c ", cwd="java")
def test_4(self, completion, can_list_jar):
if can_list_jar:
assert completion == "bashcomp.jarred d toplevel".split()
assert (
completion
== "JEP330.java a/ bashcomp.jarred d toplevel".split()
)
else:
assert completion == ["d"]
assert completion == "JEP330.java a/ d".split()

@pytest.mark.complete("java -cp '' ")
@pytest.mark.complete("java -cp '' ", cwd="java")
def test_5(self, completion):
assert not completion
assert completion == "JEP330.java a/".split()

@pytest.mark.complete("java -jar java/")
@pytest.mark.complete("java -jar ", cwd="java")
def test_6(self, completion):
assert completion == "a/ bashcomp.jar bashcomp.war".split()

Expand Down