Skip to content

Commit 90e9290

Browse files
committed
Add doc about DataTables
1 parent a1cfbca commit 90e9290

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The minor version might differ because Cucumber Scala may add Scala-related feat
2929
- Documentation
3030
- [Basic usage](docs/usage.md)
3131
- [Step Definitions](docs/step_definitions.md)
32+
- [DataTables](docs/datatables.md)
3233
- [Hooks](docs/hooks.md)
3334
- [Transformers](docs/transformers.md)
3435
- [Default Jackson DataTable Transformer](docs/default_jackson_datatable_transformer.md)

docs/datatables.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# DataTables
2+
3+
Cucumber Scala support DataTables with Java types.
4+
5+
See below the exhaustive list of possible mappings.
6+
7+
## As Map of Map
8+
9+
```gherkin
10+
Given the following table as Map of Map
11+
| | key1 | key2 | key3 |
12+
| row1 | val11 | val12 | val13 |
13+
| row2 | val21 | val22 | val23 |
14+
| row3 | val31 | val32 | val33 |
15+
```
16+
17+
```scala
18+
Given("the following table as Map of Map") { (table: JavaMap[String, JavaMap[String, String]]) =>
19+
// Map(
20+
// "row1" -> Map("key1" -> "val11", "key2" -> "val12", "key3" -> "val13"),
21+
// "row2" -> Map("key1" -> "val21", "key2" -> "val22", "key3" -> "val23"),
22+
// "row3" -> Map("key1" -> "val31", "key2" -> "val32", "key3" -> "val33")
23+
// )
24+
}
25+
```
26+
27+
## As List of Map
28+
29+
```gherkin
30+
Given the following table as List of Map
31+
| key1 | key2 | key3 |
32+
| val11 | val12 | val13 |
33+
| val21 | val22 | val23 |
34+
| val31 | val32 | val33 |
35+
```
36+
37+
```scala
38+
Given("the following table as List of Map") { (table: JavaList[JavaMap[String, String]]) =>
39+
// Seq(
40+
// Map("key1" -> "val11", "key2" -> "val12", "key3" -> "val13"),
41+
// Map("key1" -> "val21", "key2" -> "val22", "key3" -> "val23"),
42+
// Map("key1" -> "val31", "key2" -> "val32", "key3" -> "val33")
43+
// )
44+
}
45+
```
46+
47+
## As Map of List
48+
49+
```gherkin
50+
Given the following table as Map of List
51+
| row1 | val11 | val12 | val13 |
52+
| row2 | val21 | val22 | val23 |
53+
| row3 | val31 | val32 | val33 |
54+
```
55+
56+
```scala
57+
Given("the following table as Map of List") { (table: JavaMap[String, JavaList[String]]) =>
58+
// Map(
59+
// "row1" -> Seq("val11", "val12", "val13"),
60+
// "row2" -> Seq("val21", "val22", "val23"),
61+
// "row3" -> Seq("val31", "val32", "val33")
62+
// )
63+
}
64+
```
65+
66+
67+
## As List of List
68+
69+
```gherkin
70+
Given the following table as List of List
71+
| val11 | val12 | val13 |
72+
| val21 | val22 | val23 |
73+
| val31 | val32 | val33 |
74+
```
75+
76+
```scala
77+
Given("the following table as List of List") { (table: JavaList[JavaList[String]]) =>
78+
// Seq(
79+
// Seq("val11", "val12", "val13"),
80+
// Seq("val21", "val22", "val23"),
81+
// Seq("val31", "val32", "val33")
82+
// )
83+
}
84+
```
85+
86+
## As Map
87+
88+
```gherkin
89+
Given the following table as Map
90+
| row1 | val11 |
91+
| row2 | val21 |
92+
| row3 | val31 |
93+
```
94+
95+
```scala
96+
Given("the following table as Map") { (table: JavaMap[String, String]) =>
97+
// Map(
98+
// "row1" -> "val11",
99+
// "row2" -> "val21",
100+
// "row3" -> "val31"
101+
// )
102+
}
103+
```
104+
105+
## As List
106+
107+
```gherkin
108+
Given the following table as List
109+
| val11 |
110+
| val21 |
111+
| val31 |
112+
```
113+
114+
```scala
115+
Given("the following table as List") { (table: JavaList[String]) =>
116+
// Seq(
117+
// "val11",
118+
// "val21",
119+
// "val31"
120+
// )
121+
}
122+
```
123+
124+
## As DataTable
125+
126+
```gherkin
127+
Given the following table as DataTable
128+
# Any previous table definition is possible
129+
| key1 | key2 | key3 |
130+
| val11 | val12 | val13 |
131+
| val21 | val22 | val23 |
132+
| val31 | val32 | val33 |
133+
```
134+
135+
```scala
136+
Given("the following table as DataTable") { (table: DataTable) =>
137+
// Use the table any way you want, including any of the options defined previously
138+
}
139+
```

0 commit comments

Comments
 (0)