Fix diff rendering in windows. (#7254)
This commit is contained in:
parent
cd2e237c73
commit
af4fe611ed
2 changed files with 11 additions and 13 deletions
|
|
@ -9,7 +9,6 @@ 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 'node:os';
|
||||
|
||||
describe('<OverflowProvider><DiffRenderer /></OverflowProvider>', () => {
|
||||
const mockColorizeCode = vi.spyOn(CodeColorizer, 'colorizeCode');
|
||||
|
|
@ -30,7 +29,7 @@ index 0000000..e69de29
|
|||
+++ b/test.py
|
||||
@@ -0,0 +1 @@
|
||||
+print("hello world")
|
||||
`.replace(/\n/g, EOL);
|
||||
`;
|
||||
render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
|
|
@ -58,7 +57,7 @@ index 0000000..e69de29
|
|||
+++ b/test.unknown
|
||||
@@ -0,0 +1 @@
|
||||
+some content
|
||||
`.replace(/\n/g, EOL);
|
||||
`;
|
||||
render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
|
|
@ -86,7 +85,7 @@ index 0000000..e69de29
|
|||
+++ b/test.txt
|
||||
@@ -0,0 +1 @@
|
||||
+some text content
|
||||
`.replace(/\n/g, EOL);
|
||||
`;
|
||||
render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer diffContent={newFileDiffContent} terminalWidth={80} />
|
||||
|
|
@ -110,7 +109,7 @@ index 0000001..0000002 100644
|
|||
@@ -1 +1 @@
|
||||
-old line
|
||||
+new line
|
||||
`.replace(/\n/g, EOL);
|
||||
`;
|
||||
const { lastFrame } = render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
|
|
@ -140,7 +139,7 @@ index 0000001..0000002 100644
|
|||
index 1234567..1234567 100644
|
||||
--- a/file.txt
|
||||
+++ b/file.txt
|
||||
`.replace(/\n/g, EOL);
|
||||
`;
|
||||
const { lastFrame } = render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
|
|
@ -177,7 +176,7 @@ index 123..456 100644
|
|||
@@ -10,2 +10,2 @@
|
||||
context line 10
|
||||
context line 11
|
||||
`.replace(/\n/g, EOL);
|
||||
`;
|
||||
const { lastFrame } = render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
|
|
@ -214,7 +213,7 @@ index abc..def 100644
|
|||
context line 13
|
||||
context line 14
|
||||
context line 15
|
||||
`.replace(/\n/g, EOL);
|
||||
`;
|
||||
const { lastFrame } = render(
|
||||
<OverflowProvider>
|
||||
<DiffRenderer
|
||||
|
|
@ -248,7 +247,7 @@ index 123..789 100644
|
|||
-const anotherOld = 'test';
|
||||
+const anotherNew = 'test';
|
||||
console.log('end of second hunk');
|
||||
`.replace(/\n/g, EOL);
|
||||
`;
|
||||
|
||||
it.each([
|
||||
{
|
||||
|
|
@ -318,7 +317,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
|
||||
|
|
@ -348,7 +347,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,7 +6,6 @@
|
|||
|
||||
import type React from 'react';
|
||||
import { Box, Text } from 'ink';
|
||||
import { EOL } from 'node:os';
|
||||
import { Colors } from '../../colors.js';
|
||||
import crypto from 'node:crypto';
|
||||
import { colorizeCode, colorizeLine } from '../../utils/CodeColorizer.js';
|
||||
|
|
@ -21,7 +20,7 @@ interface DiffLine {
|
|||
}
|
||||
|
||||
function parseDiffWithLineNumbers(diffContent: string): DiffLine[] {
|
||||
const lines = diffContent.split(EOL);
|
||||
const lines = diffContent.split('\n');
|
||||
const result: DiffLine[] = [];
|
||||
let currentOldLine = 0;
|
||||
let currentNewLine = 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue