renatoathaydes / spock-reports

This project creates a global extension to Spock to create test reports.
Apache License 2.0
273 stars 68 forks source link

The VividAstInspector does not preserve relative indents #235

Closed Gleethos closed 1 year ago

Gleethos commented 1 year ago

Background

I am working on 2 living docs browsers for 2 open source projects: https://gleethos.github.io/neureka/showcase.html https://globaltcad.github.io/swing-tree/ (see the Living Documentation tab) Especially the second browser is supposed to become the go-to documentation for new developers at our company when reading up on how to write UIs...

The Problem

So the problem here is that the code blocks parsed from the AST have inconsistent indents! So for example this code:

matrix.toString() == "(2x8):(    A  )(   B  )(   C  )(   D  )(   E  )(   F  )(   G  )(   H   ):( Framed )\n" +
                     "      [    a  ,    b  ,    c  ,    d  ,    e  ,    f  ,    g  ,    h   ]\n" +
                     "      [    1  ,    2  ,    3  ,    4  ,    5  ,    6  ,    7  ,    8   ]\n" +

Will lose its indents and end up as this:

matrix.toString() == "(2x8):(    A  )(   B  )(   C  )(   D  )(   E  )(   F  )(   G  )(   H   ):( Framed )\n" +
"    [    a  ,    b  ,    c  ,    d  ,    e  ,    f  ,    g  ,    h   ]\n" +
"    [    1  ,    2  ,    3  ,    4  ,    5  ,    6  ,    7  ,    8   ]\n" +

This is not a big deal for code involving simple statements which span no more than 1 line, however when the tested code is more functional like for example something like the stream API or more generally any kind of method chaining based code like the builder pattern... it becomes unreadable.

Gleethos commented 1 year ago

I fixed it and already let it run over 1400+ test, all works for me! However I had to adjust 2 tests which were actually expecting stripped indents, I hope that is fine.

Gleethos commented 1 year ago

I tested the fix on the Groovy 4 branch on all of my 1400+ tests... and indeed the indents are all preserved! I believe I can close this now. Thank you!