Skip to content

Commit 27b875f

Browse files
committed
Add failing test and fix logic
1 parent 5b926ee commit 27b875f

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function parseGitPatch(patch: string) {
9797
nA++
9898
nB++
9999

100-
if (line.startsWith('-- ')) {
100+
if (line === '-- ') {
101101
return
102102
}
103103
if (line.startsWith('+')) {

test/index.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ test('is a function', () => {
1414
expect(typeof parse).toBe('function')
1515
})
1616

17+
test('is a function that accepts a string', () => {
18+
expect(() => parse('')).not.toThrow()
19+
// @ts-ignore
20+
expect(() => parse(1)).toThrow()
21+
})
22+
1723
test('parses a simple patch', () => {
1824
const patchResult = parse(data['one-file.patch'])
1925
const diffResult = parse(data['one-file-diff.patch'])
@@ -324,6 +330,45 @@ test('parses a add and delete patch', () => {
324330
})
325331
})
326332

333+
test('parses a add and delete patch with hyphen', () => {
334+
const result = parse(data['hyphen.patch'])
335+
336+
console.log('result', JSON.stringify(parse(data['hyphen.patch']), null, 2))
337+
338+
expect(result).toEqual({
339+
hash: '89afcd42fb6f2602fbcd03d6e5573b1859347787',
340+
authorName: '"Restyled.io"',
341+
authorEmail: '[email protected]',
342+
date: 'Fri, 17 Jan 2025 18:09:56 +0000',
343+
message: '[PATCH 2/2] Restyled by prettier-yaml',
344+
files: [
345+
{
346+
added: false,
347+
deleted: false,
348+
beforeName: 'hlint/.hlint.yaml',
349+
afterName: 'hlint/.hlint.yaml',
350+
modifiedLines: [
351+
{
352+
added: false,
353+
lineNumber: 27,
354+
line: '',
355+
},
356+
{
357+
added: false,
358+
lineNumber: 29,
359+
line: '- error: {name: ""}',
360+
},
361+
{
362+
added: true,
363+
lineNumber: 28,
364+
line: '- error: { name: "" }',
365+
},
366+
],
367+
},
368+
],
369+
})
370+
})
371+
327372
test('parses a complex patch 2', () => {
328373
parse(data['complex.patch'])
329374
})

test/tests-data/hyphen.patch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
From 89afcd42fb6f2602fbcd03d6e5573b1859347787 Mon Sep 17 00:00:00 2001
2+
From: "Restyled.io" <[email protected]>
3+
Date: Fri, 17 Jan 2025 18:09:56 +0000
4+
Subject: [PATCH 2/2] Restyled by prettier-yaml
5+
6+
---
7+
hlint/.hlint.yaml | 155 +++++++++++++++++++++++-----------------------
8+
1 file changed, 77 insertions(+), 78 deletions(-)
9+
10+
diff --git a/hlint/.hlint.yaml b/hlint/.hlint.yaml
11+
index 1e09829..19356c5 100644
12+
--- a/hlint/.hlint.yaml
13+
+++ b/hlint/.hlint.yaml
14+
@@ -24,34 +24,33 @@
15+
# for ad hoc ways to suppress hlint.
16+
17+
---
18+
-
19+
# By default, everything is an error
20+
-- error: {name: ""}
21+
+- error: { name: "" }

0 commit comments

Comments
 (0)