Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Document how to test for trailing whitespace in slt / sqllogictests #13215

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 additional effort to verify that trailing whitespace is correctly produced
alamb marked this conversation as resolved.
Show resolved Hide resolved

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 `'XX'` after the column of interest, the test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's any non-whitespace, but we can take opportunity to suggest what we want to see in tests.
What about '|' that's used in one test i added, or '$' (not non-typical for marking end of line)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use | to be consistent with what you added . I will update the PR

can distinguish between `Andrew` and `Andrew `:

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

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

# Reference

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


## Demonstrate how to test for trailing whitespace
query T
select substr('Andrew Lamb', 1, 7)
----
Andrew

query TT
select substr('Andrew Lamb', 1, 7), 'XX'
----
Andrew XX

query TT
select substr('Andrew Lamb', 1, 6), 'XX'
----
Andrew XX