Skip to content

Quoting in table cells: documentation, and a consistency question #115

Description

@mlevison

A string means one thing in a sentence and another in a table cell. Both forms below are in one oath:

The value "  ab  " has length 6.

Now a table:

| value    | length | why                                 |
| - | - | - |
| '  ab  ' | 6      | quoted, so the spaces survive       |
|   ab     | 6      | same string, written bare in a cell |
const unquote = (cell: string) => cell.replace(/^'/, '').replace(/'$/, '')

sensor('The value {string} has length {int}.', (_s, value: string) => [value, value.length])

sensor('Now a table:', (_s, table: string[][]) =>
  table.slice(1).map(([value, , why]) => [value, unquote(value).length, why])
)

The sentence passes — {string} strips the quotes and preserves the whitespace. The table fails on the bare row only: length: expected 6 but was 2. The cell is trimmed by the table format before the step sees it.

Quoting the cell fixes it, but varar does not strip cell quotes, so each step writes its own unquote.

A suggestion and a question:

  1. The documentation could mention that tables trim their cells, and that single quotes are needed when whitespace matters.
  2. Would it be better to require single quotes on all strings in a table cell, with varar stripping them? Then there is no ambiguity, no risk of quotes being missed where they are needed, and cells behave like {string} does in a sentence.

This issue was edited by Claude

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions