forked from remkop/picocli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75e2aa3
commit 61eeba8
Showing
2 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package picocli; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class Issue1351 { | ||
static int flag = 0; | ||
|
||
static class MyIterator implements Iterator<String> { | ||
private int cursor; | ||
private final String[] a; | ||
|
||
MyIterator(String[] a) { | ||
this.a = a; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
// Do something in the iterator, maybe talking to a server as was mentioned in issue 1351. | ||
flag = flag + 1; | ||
return this.cursor < this.a.length; | ||
} | ||
|
||
@Override | ||
public String next() { | ||
int i = this.cursor; | ||
if (i >= this.a.length) { | ||
throw new NoSuchElementException(); | ||
} else { | ||
this.cursor = i + 1; | ||
return this.a[i]; | ||
} | ||
} | ||
} | ||
|
||
static class MyIterable implements Iterable<String> { | ||
@Override | ||
public Iterator<String> iterator() { | ||
return new MyIterator(new String[]{"A", "B", "C"}); | ||
} | ||
} | ||
|
||
@CommandLine.Command | ||
class TestCommand { | ||
@CommandLine.Option(names = "-o", completionCandidates = MyIterable.class, | ||
description = "Candidates: A, B, C") | ||
String option; | ||
} | ||
|
||
@Test | ||
public void testIssue1351() { | ||
CommandLine.usage(new TestCommand(), System.out); | ||
assertEquals(0, flag); | ||
} | ||
} |