项目文件夹

文件
wehub-resource-sync 98e40dac97
CLI Smoke Test / smoke-test-linux (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-linux (24) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (24) (push) Has been cancelled
Expo App TypeScript typecheck / typecheck (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:40:49 +08:00

74 行
2.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { materializeUnifiedDiffPatch, parseUnifiedDiff } from './codexUnifiedDiff';
describe('parseUnifiedDiff', () => {
it('parses unified diff hunk fragments without file headers', () => {
const parsed = parseUnifiedDiff(
[
'@@ -10,2 +10,4 @@',
' ',
'+<p align="center"><em>Still won\'t make your tests pass by the power of positive thinking.</em></p>',
'+',
' <div align="center">',
].join('\n'),
);
expect(parsed.fileName).toBeUndefined();
expect(parsed.oldText).toBe('\n<div align="center">');
expect(parsed.newText).toBe([
'',
'<p align="center"><em>Still won\'t make your tests pass by the power of positive thinking.</em></p>',
'',
'<div align="center">',
].join('\n'));
});
it('extracts filenames from full unified diffs', () => {
const parsed = parseUnifiedDiff(
[
'diff --git a/README.md b/README.md',
'index 1111111..2222222 100644',
'--- a/README.md',
'+++ b/README.md',
'@@ -1 +1 @@',
'-old line',
'+new line',
].join('\n'),
);
expect(parsed.fileName).toBe('README.md');
expect(parsed.oldText).toBe('old line');
expect(parsed.newText).toBe('new line');
});
it('adds file headers to Codex hunk-only patch fragments', () => {
expect(materializeUnifiedDiffPatch(
[
'@@ -1 +1 @@',
'-old line',
'+new line',
].join('\n'),
'README.md',
'update',
)).toBe([
'--- a/README.md',
'+++ b/README.md',
'@@ -1 +1 @@',
'-old line',
'+new line',
].join('\n'));
});
it('keeps full unified diffs unchanged', () => {
const patch = [
'--- a/README.md',
'+++ b/README.md',
'@@ -1 +1 @@',
'-old line',
'+new line',
].join('\n');
expect(materializeUnifiedDiffPatch(patch, 'README.md', 'update')).toBe(patch);
});
});