From 4693d830b19b82d781a6dec636e21edcc3cefd84 Mon Sep 17 00:00:00 2001 From: Dylan Lee Date: Thu, 15 Dec 2022 10:42:27 +0900 Subject: [PATCH] parsing test lines using regexp --- src/utils/tests_parsers.ts | 69 ++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/src/utils/tests_parsers.ts b/src/utils/tests_parsers.ts index e4397dd..46a5a28 100644 --- a/src/utils/tests_parsers.ts +++ b/src/utils/tests_parsers.ts @@ -13,42 +13,61 @@ export interface ParseOutput { tests: Array; } +function splitToTestFileLinesChunk(stdout: string): string[] { + const linesPerTestFileRegex = /(^\w.+ \[(?:.+\.exs)\](?:\s+\*.+\[L#\d+\])+)/gm; + const matches = stdout.match(linesPerTestFileRegex); + return matches || []; +} + +function testFileLinesToFileAndTests(chunk: string): { fileLine: string, testLines: string[] } { + const lines = chunk.trim().split('\n').filter(s => s); + return { + fileLine: lines[0], + testLines: lines.slice(1) + }; +} + +function parseTestFileName(fileLine: string): string { + const fileNamePartPattern = /\[(.+\.exs)\]/; + const matches = fileLine.match(fileNamePartPattern); + return matches![1]; +} + +function parseTestInfo(absolutePath: string, relativePath: string, testLine: string): TestInfo { + // * doctest Phoenix.Naming.camelize/1 (1) (excluded) [L#5] + const testLinePattern = /\*\s+(?\w+)\s+(?