Skip to content
This repository was archived by the owner on Aug 24, 2023. It is now read-only.

Commit 3118457

Browse files
authored
feat(robot): add generators (withfig#1086)
1 parent e29a3b5 commit 3118457

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

src/robot.ts

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { filepaths } from "@fig/autocomplete-generators";
22

33
const tagsGenerator: Fig.Generator = {
4-
custom: async (tokens, executeShellCommand) => {
5-
const out = await executeShellCommand(
6-
'for i in $(find -E . -regex ".*.robot" -type f); do cat -s $i ; done'
7-
);
4+
script:
5+
'for i in $(find -E . -regex ".*.robot" -type f); do cat -s $i ; done',
6+
postProcess: (out) => {
7+
// find all lines with tags
8+
// regex: line that starts with 2+ spaces, than '[Tags] ' and words
89
const iter = out.matchAll(/(?:^\s\s+\[Tags\])\s\s+(\w+ *)*(?!.\#.*)/gm);
910

1011
const seen: Set<string> = new Set();
@@ -46,6 +47,44 @@ const variablesGenerator: Fig.Generator = {
4647
},
4748
};
4849

50+
const testCasesGenerator: Fig.Generator = {
51+
script:
52+
'for i in $(find -E . -regex ".*.robot" -type f); do cat -s $i ; done',
53+
postProcess: (out) => {
54+
// find all the parts of the code with test cases
55+
// regex: everytring after '***Test Cases***' until '***???***')
56+
const iter = out.matchAll(
57+
/(?:\*{3}Test Cases\*{3})([\S\s]*)(?:\*{3}(\w+\s?)+\*{3})/gim
58+
);
59+
60+
const seen: Set<string> = new Set();
61+
const suggestions: Fig.Suggestion[] = [];
62+
63+
// go through ***Test Cases** blocks
64+
for (const [_, block] of iter) {
65+
// get every test case name
66+
// regex: word/s at the start of a line divided
67+
const lines = block.matchAll(/^(\w+ *)+(?!.\#.*)(?!.\#.*)/gm);
68+
// go through all the test cases names found
69+
for (let [testCase] of lines) {
70+
testCase = testCase.trim();
71+
// validate if the test case name isn't divided by more than one space
72+
if (testCase.search(/\s\s+/) != -1) continue;
73+
74+
if (seen.has(testCase)) continue;
75+
seen.add(testCase);
76+
77+
suggestions.push({
78+
name: testCase,
79+
description: "Test case",
80+
});
81+
}
82+
}
83+
84+
return suggestions;
85+
},
86+
};
87+
4988
const completionSpec: Fig.Spec = {
5089
name: "robot",
5190
description: "CLI for running Robot Framework automation tests",
@@ -111,13 +150,15 @@ const completionSpec: Fig.Spec = {
111150
"Select tests by name or by long name containing also parent suite name like `Parent.Test`",
112151
args: {
113152
name: "name",
153+
generators: testCasesGenerator,
114154
},
115155
},
116156
{
117157
name: "--task",
118158
description: "Alias to --test. Especially applicable with --rpa",
119159
args: {
120160
name: "name",
161+
generators: testCasesGenerator,
121162
},
122163
},
123164
{
@@ -203,7 +244,6 @@ const completionSpec: Fig.Spec = {
203244
}),
204245
},
205246
},
206-
207247
{
208248
name: ["-d", "--outputdir"],
209249
description:

0 commit comments

Comments
 (0)