Skip to content

Commit

Permalink
Minor: Document how to test for trailing whitespace in slt / sqllog…
Browse files Browse the repository at this point in the history
…ictests (#13215)

* Minor: Document how to test for trailing whitespace

* Apply suggestions from code review

Co-authored-by: Piotr Findeisen <[email protected]>

* Use `|` for consistency

---------

Co-authored-by: Piotr Findeisen <[email protected]>
  • Loading branch information
alamb and findepi authored Nov 8, 2024
1 parent d00a085 commit 545976f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
33 changes: 33 additions & 0 deletions datafusion/sqllogictest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,39 @@ SELECT * from foo;

Assuming it looks good, check it in!

## Cookbook: Testing for whitespace

The `sqllogictest` runner will automatically strip trailing whitespace, meaning
it requires an additional effort to verify that trailing whitespace is correctly produced

For example, the following test can't distinguish between `Andrew` and `Andrew `
(with trailing space):

```text
query T
select substr('Andrew Lamb', 1, 7)
----
Andrew
```

To test trailing whitespace, project additional non-whitespace column on the
right. For example, by selecting `'|'` after the column of interest, the test
can distinguish between `Andrew` and `Andrew `:

```text
# Note two spaces between `Andrew` and `|`
query TT
select substr('Andrew Lamb', 1, 7), '|'
----
Andrew |
# Note only one space between `Andrew` and `|`
query TT
select substr('Andrew Lamb', 1, 6), '|'
----
Andrew |
```

# Reference

## Running tests: Validation Mode
Expand Down
21 changes: 21 additions & 0 deletions datafusion/sqllogictest/test_files/functions.slt
Original file line number Diff line number Diff line change
Expand Up @@ -735,3 +735,24 @@ query B
select contains('', '');
----
true


## Demonstrate how to test for trailing whitespace

# Note no trailing whitespace
query T
select substr('Andrew Lamb', 1, 7)
----
Andrew

# Note two spaces between `Andrew` and `|`
query TT
select substr('Andrew Lamb', 1, 7), '|'
----
Andrew |

# Note only one space between `Andrew` and `|`
query TT
select substr('Andrew Lamb', 1, 6), '|'
----
Andrew |

0 comments on commit 545976f

Please sign in to comment.