Allow to resuse value from previosu cell in data table
I would like to suggest a new feature for data tables. data tables already allow to refer to variables to the left in the same row. I thought it would be great if it was also possible to reference value from same cell but from previous row. I managed to roll out my own solution for this by means of data pipes:
@Unroll("max(#a,#b)==#c")
def 'Trick'( def a, def b, def c) {
expect:
Math.max(a, b) == c
where:
[a, b, c] << Spock.dataTable(
[
[5, 1, 5],
[_, 2, _],
[_, 3, _],
[_, 4, _],
[_, 5, _],
[5, 6, 6]
]
)
}
and the dataTable function goes like this:
static List dataTable( List data ) {
for( int i=0;i<data.size();++i ) {
List row = data[i];
for( int j=0;j<row.size();++j ) {
if( row[j] instanceof Wildcard) {
row[j]=data[i-1][j]
}
}
}
data;
}
It should be clear from the dataTable what is meant as the result.
I think that Spock AST transformation could easily perform the work for me Table of the form:
where:
a | b | c
5 | 1 | 5
_ | 2 | _
_ | 3 | _
_ | 4 | _
_ | 5 | _
_ | 6 | 6
could easily be transformed to
where:
a | b | c
5 | 1 | 5
5 | 2 | 5
5 | 3 | 5
5 | 4 | 5
5 | 5 | 5
5 | 6 | 6
and the processed like any other dataTable
The reason for this feature would be that i'm working with long nested lists as values in table cells and i would like not to repeat my self