test(memory): avoid control-regex lint · openclaw/openclaw@6aa7e37
vincentkoc
·
2026-05-09
·
via Recent Commits to openclaw:main
File tree
extensions/memory-core/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -142,13 +142,35 @@ describe("memory cli", () => {
|
142 | 142 | ); |
143 | 143 | } |
144 | 144 | |
145 | | -const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g; |
| 145 | +function stripAnsi(value: string) { |
| 146 | +let output = ""; |
| 147 | +for (let index = 0; index < value.length; index += 1) { |
| 148 | +if (value.charCodeAt(index) !== 0x1b) { |
| 149 | +output += value[index] ?? ""; |
| 150 | +continue; |
| 151 | +} |
| 152 | +if (value[index + 1] !== "[") { |
| 153 | +continue; |
| 154 | +} |
| 155 | +index += 2; |
| 156 | +while (index < value.length) { |
| 157 | +const code = value.charCodeAt(index); |
| 158 | +if (code >= 0x40 && code <= 0x7e) { |
| 159 | +break; |
| 160 | +} |
| 161 | +index += 1; |
| 162 | +} |
| 163 | +} |
| 164 | +return output; |
| 165 | +} |
146 | 166 | |
147 | 167 | function loggedOutput(spy: ReturnType<typeof vi.spyOn>) { |
148 | 168 | return spy.mock.calls |
149 | 169 | .map((call: unknown[]) => (typeof call[0] === "string" ? call[0] : "")) |
150 | 170 | .join("\n") |
151 | | -.replace(ansiPattern, ""); |
| 171 | +.split("\n") |
| 172 | +.map(stripAnsi) |
| 173 | +.join("\n"); |
152 | 174 | } |
153 | 175 | |
154 | 176 | function expectLogged(spy: ReturnType<typeof vi.spyOn>, expected: string) { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。