Skip to content

Commit dc6f721

Browse files
committed
Add new DSLs for checking that input file data is unique
1 parent 85a8b64 commit dc6f721

File tree

2 files changed

+143
-1
lines changed

2 files changed

+143
-1
lines changed

docs/04-dsl.mdx

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7827,6 +7827,148 @@ Since [v4.8.0](https://github.com/gwen-interpreter/gwen-web/releases/tag/v4.8.0)
78277827
</div>
78287828
</details>
78297829

7830+
#### Data asserts
7831+
7832+
<details id="name-should-be-unique-in-the-filepath-file">
7833+
<summary class="dsl">
7834+
7835+
```gherkin
7836+
`<name> should be unique in the "<filepath>" file`
7837+
```
7838+
<p>Checks that the current value of a field is unique in a CSV or JSON input file</p>
7839+
</summary>
7840+
<p>Where</p>
7841+
<ul>
7842+
<li><code>&lt;name&gt;</code>the name of the field to check</li>
7843+
<li><code>&lt;filepath&gt;</code> the path to the CSV or JSON file</li>
7844+
</ul>
7845+
7846+
<p>Examples</p>
7847+
7848+
##### CSV Check
7849+
7850+
Given the CSV file: resources/StateCodes.csv
7851+
7852+
```csv
7853+
Code,Name
7854+
ACT,Australian Capital Territory
7855+
NSW,New South Wales
7856+
NT,Northern Territory
7857+
QLD,Queensland
7858+
SA,South Australia
7859+
TAS,Tasmania
7860+
VIC,Victoria
7861+
WA,Western Australia
7862+
```
7863+
7864+
The following will check that all values in the <code>Name</code> column are unique:
7865+
7866+
```gherkin {1}
7867+
Then Name should be unique in the "resources/StateCodes.csv" file
7868+
```
7869+
7870+
##### JSON Check
7871+
7872+
Given the JSON file: resources/StateCodes.json
7873+
7874+
```json
7875+
[
7876+
{ "Code": "ACT", "Name": "Australian Capital Territory" },
7877+
{ "Code": "NSW", "Name": "New South Wales" },
7878+
{ "Code": "NT", "Name": "Northern Territory" },
7879+
{ "Code": "QLD", "Name": "Queensland" },
7880+
{ "Code": "SA", "Name": "South Australia" },
7881+
{ "Code": "TAS", "Name": "Tasmania" },
7882+
{ "Code": "VIC", "Name": "Victoria" },
7883+
{ "Code": "WA", "Name": "Western Australia" }
7884+
]
7885+
```
7886+
7887+
The following will check that all <code>Name</code> properties are unique:
7888+
7889+
```gherkin {1}
7890+
Then Name should be unique in the "resources/StateCodes.json" file
7891+
```
7892+
7893+
<div class="grid-3">
7894+
<div><Link to="#name-should-be-unique-in-the-filepath-file">Link</Link></div>
7895+
<div align="center"></div>
7896+
<div align="right">Since <Link to="https://github.com/gwen-interpreter/gwen-web/releases/tag/v4.12.0">v4.12.0</Link></div>
7897+
</div>
7898+
</details>
7899+
7900+
<details id="name-should-be-unique-in-the-filepath-ref">
7901+
<summary class="dsl">
7902+
7903+
```gherkin
7904+
<name> should be unique in <filepathRef file>
7905+
```
7906+
<p>Checks that the current value of a field is unique in a CSV or JSON input file</p>
7907+
</summary>
7908+
<p>Where</p>
7909+
<ul>
7910+
<li><code>&lt;name&gt;</code>the name of the field to check</li>
7911+
<li><code>&lt;filepathRef file&gt;</code> is the name of the binding containing the path of the CSV or JSON file</li>
7912+
</ul>
7913+
7914+
The data value contained in the first record that satisifes the given predicate will be bound to the global scope. Otherwise if no records match, then no value will be bound.
7915+
7916+
<p>Examples</p>
7917+
7918+
##### CSV Check
7919+
7920+
Given the CSV file: resources/StateCodes.csv
7921+
7922+
```csv
7923+
Code,Name
7924+
ACT,Australian Capital Territory
7925+
NSW,New South Wales
7926+
NT,Northern Territory
7927+
QLD,Queensland
7928+
SA,South Australia
7929+
TAS,Tasmania
7930+
VIC,Victoria
7931+
WA,Western Australia
7932+
```
7933+
7934+
The following will check that all values in the <code>Name</code> column are unique:
7935+
7936+
```gherkin {2}
7937+
Given the mapping file is "resources/StateCodes.csv"
7938+
Then Name should be unique in the mapping file
7939+
```
7940+
7941+
##### JSON Check
7942+
7943+
Given the JSON file: resources/StateCodes.json
7944+
7945+
```json
7946+
[
7947+
{ "Code": "ACT", "Name": "Australian Capital Territory" },
7948+
{ "Code": "NSW", "Name": "New South Wales" },
7949+
{ "Code": "NT", "Name": "Northern Territory" },
7950+
{ "Code": "QLD", "Name": "Queensland" },
7951+
{ "Code": "SA", "Name": "South Australia" },
7952+
{ "Code": "TAS", "Name": "Tasmania" },
7953+
{ "Code": "VIC", "Name": "Victoria" },
7954+
{ "Code": "WA", "Name": "Western Australia" }
7955+
]
7956+
```
7957+
7958+
The following will check that all <code>Name</code> properties are unique:
7959+
7960+
```gherkin {1}
7961+
Given the mapping file is "resources/StateCodes.json"
7962+
Then Name should be unique in the mapping file
7963+
```
7964+
7965+
<div class="grid-3">
7966+
<div><Link to="#name-should-be-unique-in-the-filepath-ref">Link</Link></div>
7967+
<div align="center"></div>
7968+
<div align="right">Since <Link to="https://github.com/gwen-interpreter/gwen-web/releases/tag/v4.12.0">v4.12.0</Link></div>
7969+
</div>
7970+
</details>
7971+
78307972
### Control structures
78317973

78327974
#### ForEach

docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
label: 'FAQ',
4242
},
4343
{
44-
href: '/docs/dsl#element-locators',
44+
href: '/docs/dsl#data-asserts',
4545
position: 'left',
4646
label: "What's New?",
4747
},

0 commit comments

Comments
 (0)