mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
Fix(grep): memory overflow in grep search and enhance test coverage (#5911)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import { render } from 'ink-testing-library';
|
||||
import { DiffRenderer } from './DiffRenderer.js';
|
||||
import * as CodeColorizer from '../../utils/CodeColorizer.js';
|
||||
import { vi } from 'vitest';
|
||||
import { EOL } from 'os';
|
||||
|
||||
describe('<OverflowProvider><DiffRenderer /></OverflowProvider>', () => {
|
||||
const mockColorizeCode = vi.spyOn(CodeColorizer, 'colorizeCode');
|
||||
@@ -29,7 +30,7 @@ index 0000000..e69de29
|
||||
+++ b/test.py
|
||||
@@ -0,0 +1 @@
|
||||
+print("hello world")
|
||||
`;
|
||||
`.replace(/\n/g, EOL);
|
||||
render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
@@ -57,7 +58,7 @@ index 0000000..e69de29
|
||||
+++ b/test.unknown
|
||||
@@ -0,0 +1 @@
|
||||
+some content
|
||||
`;
|
||||
`.replace(/\n/g, EOL);
|
||||
render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
@@ -85,7 +86,7 @@ index 0000000..e69de29
|
||||
+++ b/test.txt
|
||||
@@ -0,0 +1 @@
|
||||
+some text content
|
||||
`;
|
||||
`.replace(/\n/g, EOL);
|
||||
render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer diffContent={newFileDiffContent} terminalWidth={80} />
|
||||
@@ -109,7 +110,7 @@ index 0000001..0000002 100644
|
||||
@@ -1 +1 @@
|
||||
-old line
|
||||
+new line
|
||||
`;
|
||||
`.replace(/\n/g, EOL);
|
||||
const { lastFrame } = render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
@@ -139,7 +140,7 @@ index 0000001..0000002 100644
|
||||
index 1234567..1234567 100644
|
||||
--- a/file.txt
|
||||
+++ b/file.txt
|
||||
`;
|
||||
`.replace(/\n/g, EOL);
|
||||
const { lastFrame } = render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
@@ -176,7 +177,7 @@ index 123..456 100644
|
||||
@@ -10,2 +10,2 @@
|
||||
context line 10
|
||||
context line 11
|
||||
`;
|
||||
`.replace(/\n/g, EOL);
|
||||
const { lastFrame } = render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
@@ -213,7 +214,7 @@ index abc..def 100644
|
||||
context line 13
|
||||
context line 14
|
||||
context line 15
|
||||
`;
|
||||
`.replace(/\n/g, EOL);
|
||||
const { lastFrame } = render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
@@ -247,7 +248,7 @@ index 123..789 100644
|
||||
-const anotherOld = 'test';
|
||||
+const anotherNew = 'test';
|
||||
console.log('end of second hunk');
|
||||
`;
|
||||
`.replace(/\n/g, EOL);
|
||||
|
||||
it.each([
|
||||
{
|
||||
@@ -317,7 +318,7 @@ fileDiff Index: file.txt
|
||||
-const anotherOld = 'test';
|
||||
+const anotherNew = 'test';
|
||||
\\ No newline at end of file
|
||||
`;
|
||||
`.replace(/\n/g, EOL);
|
||||
const { lastFrame } = render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
@@ -347,7 +348,7 @@ fileDiff Index: Dockerfile
|
||||
+RUN npm install
|
||||
+RUN npm run build
|
||||
\\ No newline at end of file
|
||||
`;
|
||||
`.replace(/\n/g, EOL);
|
||||
const { lastFrame } = render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import React from 'react';
|
||||
import { Box, Text } from 'ink';
|
||||
import { EOL } from 'os';
|
||||
import { Colors } from '../../colors.js';
|
||||
import crypto from 'crypto';
|
||||
import { colorizeCode, colorizeLine } from '../../utils/CodeColorizer.js';
|
||||
@@ -20,7 +21,7 @@ interface DiffLine {
|
||||
}
|
||||
|
||||
function parseDiffWithLineNumbers(diffContent: string): DiffLine[] {
|
||||
const lines = diffContent.split('\n');
|
||||
const lines = diffContent.split(EOL);
|
||||
const result: DiffLine[] = [];
|
||||
let currentOldLine = 0;
|
||||
let currentNewLine = 0;
|
||||
|
||||
Reference in New Issue
Block a user