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