Wrong line joins in Transpose

The Transpose test contains the lines

  let g:lines = join(g:lines, '\n')
  let g:expected = join(g:expected, '\n')

The idea is presumably to splice the lines of text together with newlines. However, ‘\n’ is a two-character sequence consisting of a backslash and an n (try :echo len('\n') if you are in doubt). So the solution also needs to join the lines in this unusual fashion. The fix is to use “\n” instead.

So long as the expected lines and received lines are joined using the same string sequence, the tests ought to work just fine, I think? It might not do what is expected but I think the tests should still behave correctly.

I mean, sure, you can always write a solution that conforms to the requirements of the tests, but this convention of backslash-n separators is hardly what a reasonable person would expect and is almost certainly not what the author intended. I think that it would be confusing to less experienced programmers who are new to the language. The fix is easy and so far, I am the only one who has submitted a solution, so changing the behavior won’t have much impact. I can create a PR.

+cc @kotp @BNAndras

Yeah, single quotes would be a string literal so ‘\n’ won’t be escaped properly.

PR welcome.

1 Like

The comment in the stub code is also slightly garbled. I will fix that while I’m in there.

2 Likes

PR merged.