-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make GeneratorDecorator only decorate Generators
- Loading branch information
Showing
18 changed files
with
209 additions
and
121 deletions.
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
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
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
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
59 changes: 59 additions & 0 deletions
59
src/main/groovy/spock/genesis/generators/IterableGenerator.groovy
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,59 @@ | ||
package spock.genesis.generators | ||
|
||
import groovy.transform.CompileDynamic | ||
import groovy.transform.CompileStatic | ||
|
||
/** | ||
* A generator that wraps an iterator to provide {@link Generator} methods. | ||
* @param < E > the generated type | ||
*/ | ||
@CompileStatic | ||
class IterableGenerator<E> extends Generator<E> implements Closeable { | ||
|
||
private final Iterable<E> iterable | ||
private final boolean finite | ||
|
||
IterableGenerator(Iterable<E> iterable) { | ||
this.iterable = iterable | ||
this.finite = Generator.isInstance(iterable) ? false : true | ||
} | ||
|
||
IterableGenerator(Iterable<E> iterable, boolean finite) { | ||
this.iterable = iterable | ||
this.finite = finite | ||
} | ||
|
||
IterableGenerator(E... array) { | ||
this.iterable = Arrays.asList(array) | ||
this.finite = true | ||
} | ||
|
||
@Override | ||
UnmodifiableIterator<E> iterator() { | ||
new UnmodifiableIterator<E>() { | ||
private final Iterator<E> iterator = iterable.iterator() | ||
@Override | ||
boolean hasNext() { | ||
iterator.hasNext() | ||
} | ||
|
||
@Override | ||
E next() { | ||
iterator.next() | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
boolean isFinite() { | ||
finite || GeneratorUtils.isFinite(iterable) | ||
} | ||
|
||
@CompileDynamic | ||
@Override | ||
void close() { | ||
if (iterable.respondsTo('close')) { | ||
iterable.close() | ||
} | ||
} | ||
} |
13 changes: 2 additions & 11 deletions
13
src/main/groovy/spock/genesis/generators/LimitedGenerator.groovy
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
Oops, something went wrong.