Skip to content

Commit

Permalink
Fix regex of stdoutparser (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmittag authored Apr 25, 2024
1 parent fcaa7ce commit f277c77
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/modules/stdout-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { ProjectCache } from './project-cache';

const CACHE_OUTPUT_REGEX: RegExp =
/(\w+)\s*=\s*(\[((\'(\/*\w+)*\'\s*,\s*|(\"(\/*\w+)*\"\s*,\s*)|(\/*\w+)*\s*,\s*|\'(\/*\w+)*\'(?=\])|\"(\/*\w+)*\"(?=\])|(\/*\w+)*(?=\]))*\])|(\'.*?\'|\".*?\"|\w+))\s+\>\>\s+VELOCITAS_CACHE/;
/(\w+)\s*=\s*(\[((?:'[^']*'\s*,\s*|"[^"]*"\s*,\s*|[^\[\],]*\s*,\s*|'[^']*'(?=\])|"[^"]*"(?=\])|[^\[\],]*(?=\]))*)\]|'[^']*'|"[^"]*"|\w+)\s+\>\>\s+VELOCITAS_CACHE/;

export function stdOutParser(projectCache: ProjectCache, line: string) {
let lineTrimmed = (line as string).trim();
Expand Down
2 changes: 1 addition & 1 deletion test/system-test/exec.stest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('CLI command', () => {
expect(result.stdout).to.contain('arr2');
expect(result.stdout).to.contain("['/path/test1', '/path/test2']");
expect(result.stdout).to.contain('arr3');
expect(result.stdout).to.contain("['/path/test1', '/path/test2']");
expect(result.stdout).to.contain("['./path-one/test1', '/path/test2']");
expect(result.stdout).to.contain('arr4');
expect(result.stdout).to.contain("['/path/test1', '/path/test2']");
});
Expand Down
16 changes: 11 additions & 5 deletions test/unit/stdout-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ describe('stdOutParser - module', () => {
['test_6 = ["/this/is/path/one", "/this/is/path/two"] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']],
['test_7 =["/this/is/path/one", "/this/is/path/two"] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']],
['test_8=["/this/is/path/one", "/this/is/path/two"] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']],
["test_9 = ['/this/is/path/one', /this/is/path/two] >> VELOCITAS_CACHE", ['/this/is/path/one', '/this/is/path/two']],
[
"test_9 = ['./this-this/is/path/one', /this/is/path/two] >> VELOCITAS_CACHE",
['./this-this/is/path/one', '/this/is/path/two'],
],
['test_10 = [/this/is/path/one, "/this/is/path/two"] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']],
['test_11 = [/this/is/path/one, /this/is/path/two] >> VELOCITAS_CACHE', ['/this/is/path/one', '/this/is/path/two']],
['test_11 = [/this-this/is/path/one, /this/is/path/two] >> VELOCITAS_CACHE', ['/this-this/is/path/one', '/this/is/path/two']],
['test_12 = [/this-this/is/path/one , /this/is/path/two] >> VELOCITAS_CACHE', ['/this-this/is/path/one', '/this/is/path/two']],
]);

it('should match and set project cache correct', () => {
Expand All @@ -60,9 +64,11 @@ describe('stdOutParser - module', () => {
['test_3 = /this/is/path/one"this/test >> VELOCITAS_CACHE', {}],
['test_4 = ["/this/is/path/one", /this/is/path/two"]', {}],
['test_5 = ["/this/is/path/one""/this/is/path/two"] >> VELOCITAS_CACHE', {}],
['"test_6" = ["/this/is/path/one", "/this/is/path/two"] >> VELOCITAS_CACHE', {}],
['test_7 = [/this/is/path/one""/this/is/path/two"] >> VELOCITAS_CACHE', {}],
["test_8 = ['/this/is/path/one''/this/is/path/two'] >> VELOCITAS_CACHE", {}],
['test_6 = ["/this/is/path/one", "/this/is/path/two"] >> VELOCITAS_CACHE', {}],
['"test_7" = ["/this/is"/path/one", "/this/is/path/two"] >> VELOCITAS_CACHE', {}],
['test_8 = [/this/is/path/one""/this/is/path/two"] >> VELOCITAS_CACHE', {}],
["test_9 = ['/this/is/path/one''/this/is/path/two'] >> VELOCITAS_CACHE", {}],
["test_10 = ['/this/is/'path/one','/this/is/path/two'] >> VELOCITAS_CACHE", {}],
]);

it('should not match for wrong inputs', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
print("arr2=['/path/test1', '/path/test2'] >> VELOCITAS_CACHE")
print("arr3=['/path/test1', /path/test2] >> VELOCITAS_CACHE")
print('arr4=["/path/test1","/path/test2"] >> VELOCITAS_CACHE')
print('arr5=["/path/test1" ,"/path/test2"] >> VELOCITAS_CACHE')
print('arr5=["./path-one/test1" ,"/path/test2"] >> VELOCITAS_CACHE')
print("var=\"asdc' >> VELOCITAS_CACHE")

0 comments on commit f277c77

Please sign in to comment.