Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added StreamDelegate so we can access stream properties from closures
- Loading branch information
Tim Yates
committed
Apr 3, 2013
1 parent
d715f7c
commit 0b3ee32
Showing
6 changed files
with
94 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package groovy.stream | ||
|
||
public class DelegateTests extends spock.lang.Specification { | ||
def "unfilteredIndex map test"() { | ||
setup: | ||
def stream = Stream.from 1..4 map { it * unfilteredIndex } | ||
when: | ||
def result = stream.collect() | ||
then: | ||
"unfilteredIndex is incremented BEFORE map" | ||
result == [ 1, 4, 9, 16 ] | ||
} | ||
|
||
def "unfilteredIndex filter test"() { | ||
setup: | ||
def stream = Stream.from 1..4 filter { 2 != unfilteredIndex } | ||
when: | ||
def result = stream.collect() | ||
then: | ||
"unfilteredIndex is incremented AFTER filter" | ||
result == [ 1, 2, 4 ] | ||
} | ||
|
||
def "unfilteredIndex until test"() { | ||
setup: | ||
def stream = Stream.from 1..4 until { unfilteredIndex == 2 } | ||
when: | ||
def result = stream.collect() | ||
then: | ||
"unfilteredIndex is incremented BEFORE until" | ||
result == [ 1, 2 ] | ||
} | ||
} |
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