visRangeOffsets is a helper that produces a visual representation of the start and end byte offsets of the given range, which can then be stacked with the same for other ranges to more easily see how the ranges relate to one another.
(rng Range)
| 447 | // with the same for other ranges to more easily see how the ranges relate |
| 448 | // to one another. |
| 449 | func visRangeOffsets(rng Range) string { |
| 450 | var buf bytes.Buffer |
| 451 | if rng.End.Byte < rng.Start.Byte { |
| 452 | // Should never happen, but we'll visualize it anyway so we can |
| 453 | // more easily debug failing tests. |
| 454 | for i := 0; i < rng.End.Byte; i++ { |
| 455 | buf.WriteByte(' ') |
| 456 | } |
| 457 | for i := rng.End.Byte; i < rng.Start.Byte; i++ { |
| 458 | buf.WriteByte('!') |
| 459 | } |
| 460 | return buf.String() |
| 461 | } |
| 462 | |
| 463 | for i := 0; i < rng.Start.Byte; i++ { |
| 464 | buf.WriteByte(' ') |
| 465 | } |
| 466 | for i := rng.Start.Byte; i < rng.End.Byte; i++ { |
| 467 | buf.WriteByte('#') |
| 468 | } |
| 469 | return buf.String() |
| 470 | } |
no test coverage detected