Skip to content

Commit 545976f

Browse files
alambfindepi
andauthored
Minor: Document how to test for trailing whitespace in slt / sqllogictests (#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]>
1 parent d00a085 commit 545976f

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

datafusion/sqllogictest/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,39 @@ SELECT * from foo;
102102

103103
Assuming it looks good, check it in!
104104

105+
## Cookbook: Testing for whitespace
106+
107+
The `sqllogictest` runner will automatically strip trailing whitespace, meaning
108+
it requires an additional effort to verify that trailing whitespace is correctly produced
109+
110+
For example, the following test can't distinguish between `Andrew` and `Andrew `
111+
(with trailing space):
112+
113+
```text
114+
query T
115+
select substr('Andrew Lamb', 1, 7)
116+
----
117+
Andrew
118+
```
119+
120+
To test trailing whitespace, project additional non-whitespace column on the
121+
right. For example, by selecting `'|'` after the column of interest, the test
122+
can distinguish between `Andrew` and `Andrew `:
123+
124+
```text
125+
# Note two spaces between `Andrew` and `|`
126+
query TT
127+
select substr('Andrew Lamb', 1, 7), '|'
128+
----
129+
Andrew |
130+
131+
# Note only one space between `Andrew` and `|`
132+
query TT
133+
select substr('Andrew Lamb', 1, 6), '|'
134+
----
135+
Andrew |
136+
```
137+
105138
# Reference
106139

107140
## Running tests: Validation Mode

datafusion/sqllogictest/test_files/functions.slt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,3 +735,24 @@ query B
735735
select contains('', '');
736736
----
737737
true
738+
739+
740+
## Demonstrate how to test for trailing whitespace
741+
742+
# Note no trailing whitespace
743+
query T
744+
select substr('Andrew Lamb', 1, 7)
745+
----
746+
Andrew
747+
748+
# Note two spaces between `Andrew` and `|`
749+
query TT
750+
select substr('Andrew Lamb', 1, 7), '|'
751+
----
752+
Andrew |
753+
754+
# Note only one space between `Andrew` and `|`
755+
query TT
756+
select substr('Andrew Lamb', 1, 6), '|'
757+
----
758+
Andrew |

0 commit comments

Comments
 (0)