Skip to content

Commit 94ac7dd

Browse files
committed
Altered directory for the directory tree search
1 parent 019c30c commit 94ac7dd

22 files changed

+449
-638
lines changed

.idea/workspace.xml

Lines changed: 44 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gherkinexecutor.Feature_Examples

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Feature: Examples
2+
Scenario: Temperature
3+
Calculation Convert F to C # ListOfObject TemperatureCalculation
4+
| F | C | Notes |
5+
| 32 | 0 | Freezing |
6+
| 212 | 100 | Boiling |
7+
| -40 | -40 | Below zero |
8+
Data TemperatureCalculation
9+
| Name | Default | DataType | Notes |
10+
| F | 0 | Integer | |
11+
| C | 0 | Integer | |
12+
| Notes | | String | |
13+
Scenario: Domain Term ID
14+
Rule ID must have exactly 5 letters and begin with Q # ListOfObject ValueValid
15+
| Value | Valid | Notes |
16+
| Q1234 | true | |
17+
| Q123 | false | Too short |
18+
| Q12345 | false | Too long |
19+
| A1234 | false | Must begin with Q |
20+
Data ValueValid
21+
| Name | Default | DataType |
22+
| Value | 0 | String |
23+
| Valid | false | Boolean |
24+
| Notes | | String |
25+
Scenario: Filter Data
26+
Given list of numbers # ListOfObject LabelValue
27+
| ID | Value |
28+
| Q1234 | 1 |
29+
| Q9999 | 2 |
30+
| Q1234 | 3 |
31+
When filtered by ID with value
32+
| Q1234 |
33+
Then sum is
34+
| 4 |
35+
Scenario: Filter Data Another Way
36+
Given list of numbers # ListOfObject LabelValue
37+
| ID | Value |
38+
| Q1234 | 1 |
39+
| Q9999 | 2 |
40+
| Q1234 | 3 |
41+
When filtered by # ListOfObject FilterValue transpose
42+
| Name | ID |
43+
| Value | Q1234 |
44+
Then result # ListOfObject ResultValue
45+
| Sum |
46+
| 4 |
47+
* Data FilterValue
48+
| Name | Default | DataType | Notes |
49+
| Name | | String | |
50+
| Value | Q0000 | ID | |
51+
* Data ResultValue
52+
| Name | Default | DataType | Notes |
53+
| Sum | | Integer | |
54+
* Data LabelValue
55+
| Name | Default | DataType | Notes |
56+
| ID | | ID | |
57+
| Value | 0 | Integer | |
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Feature: Examples
2+
Scenario: Temperature
3+
Calculation Convert F to C # ListOfObject TemperatureCalculation
4+
| F | C | Notes |
5+
| 32 | 0 | Freezing |
6+
| 212 | 100 | Boiling |
7+
| -40 | -40 | Below zero |
8+
Data TemperatureCalculation
9+
| Name | Default | DataType | Notes |
10+
| F | 0 | Integer | |
11+
| C | 0 | Integer | |
12+
| Notes | | String | |
13+
Scenario: Domain Term ID
14+
Rule ID must have exactly 5 letters and begin with Q # ListOfObject ValueValid
15+
| Value | Valid | Notes |
16+
| Q1234 | true | |
17+
| Q123 | false | Too short |
18+
| Q12345 | false | Too long |
19+
| A1234 | false | Must begin with Q |
20+
Data ValueValid
21+
| Name | Default | DataType |
22+
| Value | 0 | String |
23+
| Valid | false | Boolean |
24+
| Notes | | String |
25+
Scenario: Filter Data
26+
Given list of numbers # ListOfObject LabelValue
27+
| ID | Value |
28+
| Q1234 | 1 |
29+
| Q9999 | 2 |
30+
| Q1234 | 3 |
31+
When filtered by ID with value
32+
| Q1234 |
33+
Then sum is
34+
| 4 |
35+
Scenario: Filter Data Another Way
36+
Given list of numbers # ListOfObject LabelValue
37+
| ID | Value |
38+
| Q1234 | 1 |
39+
| Q9999 | 2 |
40+
| Q1234 | 3 |
41+
When filtered by # ListOfObject FilterValue transpose
42+
| Name | ID |
43+
| Value | Q1234 |
44+
Then result # ListOfObject ResultValue
45+
| Sum |
46+
| 4 |
47+
* Data FilterValue
48+
| Name | Default | DataType | Notes |
49+
| Name | | String | |
50+
| Value | Q0000 | ID | |
51+
* Data ResultValue
52+
| Name | Default | DataType | Notes |
53+
| Sum | | Integer | |
54+
* Data LabelValue
55+
| Name | Default | DataType | Notes |
56+
| ID | | ID | |
57+
| Value | 0 | Integer | |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature: Simple Test
2+
Scenario Simple
3+
Given table is # ListOfObject ATest
4+
| anInt | aString | aDouble |
5+
| 1 | something | 1.2 |
6+
Data ATest
7+
| Name | Default | Datatype | Note |
8+
| anInt | 0 | Integer | |
9+
| aString | ^ | String | |
10+
| aDouble | 1.2 | Double | |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature: Simple Test
2+
Scenario Simple
3+
Given table is # ListOfObject ATest
4+
| anInt | aString | aDouble |
5+
| 1 | something | 1.2 |
6+
Data ATest
7+
| Name | Default | Datatype | Note |
8+
| anInt | 0 | Integer | |
9+
| aString | ^ | String | |
10+
| aDouble | 1.2 | Double | |

src/main/java/gherkinexecutor/Translate.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ public void translateInTests(String name) {
7070

7171
linesToAddForDataAndGlue.addAll(Configuration.linesToAddForDataAndGlue);
7272
dataIn = new InputIterator(name, featureDirectory);
73+
alterFeatureDirectory();
7374
if (dataIn.isEmpty())
7475
return;
76+
7577
for (int pass = 1; pass <= 3; pass++) {
7678
dataIn.reset();
7779
boolean eof = false;
@@ -87,6 +89,16 @@ public void translateInTests(String name) {
8789
endUp();
8890
}
8991

92+
private void alterFeatureDirectory() {
93+
// Remove feature directory from the package and directory
94+
String searchFor = Configuration.treeDirectory;
95+
String alternateSearchFor = searchFor.replace("/","\\");
96+
String directory = featureDirectory.replace(searchFor, "");
97+
directory = directory.replace(alternateSearchFor,"");
98+
featureDirectory = directory;
99+
featurePackagePath = featureDirectory.replace("\\", ".").replace("/", ".");
100+
}
101+
90102
private void findFeatureDirectory(String name) {
91103
String directory = "";
92104
int indexForward = name.lastIndexOf('/');
@@ -137,11 +149,17 @@ private Pair<List<String>, List<String>> splitLine(String line) {
137149
}
138150
continue;
139151
}
152+
word = filterWord(word);
140153
words.add(word);
141154
}
142155
return new Pair<>(words, comment);
143156
}
144-
157+
public static String filterWord(String input) {
158+
if (input == null) {
159+
return "";
160+
}
161+
return input.replaceAll("[^0-9a-zA-Z_]", "");
162+
}
145163
private static String wordWithOutColon(String word) {
146164
return word.replaceAll("^:+|:+$", "");
147165
}
@@ -246,6 +264,7 @@ void writeInputFeature(String filename) {
246264
myLog.write(dataIn.toString());
247265
myLog.close();
248266
} catch (IOException e) {
267+
System.err.println(e.getMessage() + " Cause " + e.getCause());
249268
System.err.println("**** Cannot write to " + fullFilename);
250269
}
251270
}
@@ -292,7 +311,6 @@ private boolean actOnFeatureFirstHalf(String fullName) {
292311
featureName = fullName;
293312
featureActedOn = true;
294313
packagePath = Configuration.packageName + "." + featurePackagePath + featureName;
295-
writeInputFeature(Configuration.testSubDirectory + featureDirectory + featureName + "/" );
296314
String testPathname = Configuration.testSubDirectory + featureDirectory + featureName + "/" +
297315
featureName + ".java";
298316
printFlow(" Writing " + testPathname);
@@ -314,6 +332,7 @@ private boolean actOnFeatureFirstHalf(String fullName) {
314332
}
315333
glueClass = fullName + "_glue";
316334
glueObject = makeName(fullName) + "_glue_object";
335+
writeInputFeature(Configuration.testSubDirectory + featureDirectory + featureName + "/" );
317336
return false;
318337
}
319338

@@ -326,7 +345,8 @@ private String makeBuildName(String s) {
326345

327346
private String makeName(String input) {
328347
if (input.isEmpty()) return "NAME_IS_EMPTY";
329-
String temp = input.replace(' ', '_');
348+
String temp = input.replaceAll(" ", "_");
349+
temp = filterWord(temp);
330350
return Character.toLowerCase(temp.charAt(0)) + temp.substring(1);
331351
}
332352

@@ -674,7 +694,8 @@ static class InputIterator {
674694
public String toString() {
675695
StringBuilder temp = new StringBuilder();
676696
for (String line : linesIn){
677-
temp.append(line + "\n");
697+
temp.append(line);
698+
temp.append("\n");
678699
}
679700
return temp.toString();
680701
}
@@ -1404,7 +1425,7 @@ private void createJSONToTableMethod(String className) {
14041425
public static List<CLASSNAME> listFromJson(String json) {
14051426
List<CLASSNAME> list = new ArrayList<>();
14061427
json = json.replaceAll("\\\\s", "");
1407-
String[] jsonObjects = json.replace("[", "").replace("]", "").split("\\\\},\\\\{");
1428+
String[] jsonObjects = json.replace("[", "").replace("]", "").split("[},{]");
14081429
14091430
for (String jsonObject : jsonObjects) {
14101431
jsonObject = "{" + jsonObject.replace("{", "").replace("}", "") + "}";
@@ -1986,7 +2007,8 @@ static class Configuration {
19862007

19872008
public static final String featureSubDirectory = "src/test/java/";
19882009
// where features are stored
1989-
public static final String startingFeatureDirectory = featureSubDirectory + "features/";
2010+
public static final String treeDirectory = "features/";
2011+
public static final String startingFeatureDirectory = featureSubDirectory + treeDirectory ;
19902012
// where the directory tree of features is to be found.
19912013
public static boolean searchTree = false;
19922014
public static final String packageName = "gherkinexecutor";

0 commit comments

Comments
 (0)