Closed orlade-anz closed 4 years ago
@> //fmt.pretty([1,2,3]) '[\n 1,\n 2,\n 3\n]' @>
Current output is not right.
It's not perfect, but I'd argue it's more correct that it was. Simple lists should be flat, but in practice, most lists are not simple. Expanding simple lists is a better interim than flattening non-simple lists as we do today.
@> //fmt.pretty([1,2,3]) '[\n 1,\n 2,\n 3\n]' @>
Current output is not right.
It's not perfect, but I'd argue it's more correct that it was. Simple lists should be flat, but in practice, most lists are not simple. Expanding simple lists is a better interim than flattening non-simple lists as we do today.
I think the issue is code return rel.NewString([]rune(prettifiedString)), nil
in std_fmt.go.
All \n
is transformed to char \n
and will not start a new line really.
This is correct behaviour. The purpose of //fmt.pretty
is to return a string with the correctly formatted content, not to print that string. When evaluated in ai
, this shows that string in arr.ai syntax. Compare with Python:
In [1]: import pprint
In [2]: pprint.pp([1, 2, 3])
[1, 2, 3]
In [3]: pprint.pformat([1, 2, 3])
Out[3]: '[1, 2, 3]'
pprint.pp
prints the string, while pprint.pformat
returns the string and ipython3 shows what that string is in Python syntax. The intent behind //fmt.pretty
is the same as pprint.pformat
.
The intended behaviour will manifest with:
arrai eval '//fmt.pretty([1,2,3])'
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
syntax/prettify.go | 63 | 75 | 84.0% | ||
<!-- | Total: | 64 | 76 | 84.21% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
rel/value_set_str.go | 2 | 60.82% | ||
<!-- | Total: | 2 | --> |
Totals | |
---|---|
Change from base Build b7a28242d7549a562daf65d9d9dd7d16ef814484: | 0.2% |
Covered Lines: | 4503 |
Relevant Lines: | 9399 |
Some test cases are failed.
Fixed I believe.
Fixes #516, part of https://github.com/arr-ai/arrai/issues/171.
Changes proposed in this pull request:
Checklist: