(regex)
| 99 | * Search for one of the regex statements in the code file. If it's found, return the line as a string and the line number. |
| 100 | */ |
| 101 | const lookForMatch = (regex) => { |
| 102 | let match; |
| 103 | let matchFound = false; |
| 104 | let matchedLineNum = null; |
| 105 | let actualMatch = null; |
| 106 | let lines = fileContent.split("\n"); |
| 107 | while ((match = regex.exec(fileContent))) { |
| 108 | if (match !== null) { |
| 109 | const identifiers = match[1].split(":"); |
| 110 | let tempMatch = identifiers.includes(identifier) ? match : null; |
| 111 | |
| 112 | if (tempMatch === null) { |
| 113 | // If it's not a match, we'll make a note that we should remove the matched text, because it's from some other identifier and should not appear in the snippet for this identifier. |
| 114 | for (let i = 0; i < lines.length; i++) { |
| 115 | let line = lines[i]; |
| 116 | if (line.trim() == match[0].trim()) { |
| 117 | linesToRemove.push(i + 1); // lines are indexed from 1 |
| 118 | } |
| 119 | } |
| 120 | } else { |
| 121 | if (matchFound === true) { |
| 122 | throw new Error( |
| 123 | `Duplicate for regex ${regex} and identifier ${identifier}` |
| 124 | ); |
| 125 | } |
| 126 | matchFound = true; |
| 127 | matchedLineNum = getLineNumberFromIndex(fileContent, tempMatch.index); |
| 128 | actualMatch = tempMatch; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | return [actualMatch, matchedLineNum]; |
| 134 | }; |
| 135 | |
| 136 | let [startMatch, startLineNum] = lookForMatch(startRegex); |
| 137 | let [endMatch, endLineNum] = lookForMatch(endRegex); |
no test coverage detected