Skip to content

Commit b9885f4

Browse files
committed
Introduce elvis operator to support default values for undefined bindings
1 parent e46b7b0 commit b9885f4

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

docs/15-string-interpolation.mdx

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
toc_min_heading_level: 2
3-
toc_max_heading_level: 3
3+
toc_max_heading_level: 2
44
---
55

66
import Link from '@docusaurus/Link';
@@ -12,9 +12,9 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
1212

1313
> Since [v1.0.0](https://github.com/gwen-interpreter/gwen-web/releases/tag/v1.0.0)
1414
15-
It is often useful to reference settings, captured values and other text throughout your feature and meta files. To support this, Gwen provides a placholder substitution mechanism.
15+
String interpolation is often useful to reference settings, captured values and other text throughout your feature and meta files. To support this, Gwen provides a placholder substitution mechanism.
1616

17-
### Placeholder Syntax
17+
## Placeholder Syntax
1818

1919
Placeholders are declared using the `${placholder}` syntax and can include:
2020

@@ -25,7 +25,7 @@ Placeholders are declared using the `${placholder}` syntax and can include:
2525
- A named binding in the currently accessible scope
2626
- [JS arrow functions](/docs/js-functions#inlined-functions)
2727

28-
## Examples
28+
### Examples
2929

3030
Substitution involves replacing named placeholders with their values.
3131

@@ -40,3 +40,24 @@ Scenario: By Substitution
4040
Then my proposition should be "By substitution, my value will be ${my.property}"
4141
```
4242

43+
## Elvis Operator
44+
45+
> Since [v4.4.0](https://github.com/gwen-interpreter/gwen-web/releases/tag/v4.4.0)
46+
47+
The elvis `?:` syntax can be used to define default values for references which may not exist
48+
49+
### Examples
50+
51+
```gherkin
52+
Given a is "${some.string :? 'default'}"
53+
And b is "${some.string :? '${some.other.string}'}"
54+
And c is "${some.string :? blank}"
55+
And d is "${some.boolean :? false}"
56+
And e is "${some.string1 :? '${some.string2 ?: blank}'}"
57+
```
58+
59+
- Set `a` to value bound to `some.string` or to `default` string value if undefined
60+
- Set `b` to value bound to `some.string` or to value bound to `some.other.string` if undefined
61+
- Set `c` to value bound to `some.string` or to a blank string value if undefined:
62+
- Set `d` to value bound to `some.string` or to a false Boolean value if undefined:
63+
- Set `e` to value bound to `some.string1` or value bound to `some.string2` if undefined, or to a blank string value if both are undefined:

docusaurus.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ module.exports = {
4141
label: 'FAQ',
4242
},
4343
{
44-
href: '/docs/gwen4',
44+
href: '/docs/string-interpolation#elvis-operator',
4545
position: 'left',
46-
label: "Gwen 4 Released!",
46+
label: "What's New?",
4747
},
4848
{
4949
label: 'GitHub',

0 commit comments

Comments
 (0)