fix(core): authorize patch move destinations (#38133)
This commit is contained in:
parent
99b2e78d75
commit
dbfbb13ccc
4 changed files with 58 additions and 4 deletions
|
|
@ -40,6 +40,18 @@ describe("Patch", () => {
|
|||
expect(() => parse("*** Begin Patch\n*** Add File: add.txt\n+added")).toThrow(
|
||||
"The last line of the patch must be '*** End Patch'",
|
||||
)
|
||||
expect(() => parse("extra\n*** Begin Patch\n*** End Patch")).toThrow(
|
||||
"The first line of the patch must be '*** Begin Patch'",
|
||||
)
|
||||
expect(() => parse("*** Begin Patch\n*** Add File: add.txt\n+added\n*** End Patch\nextra")).toThrow(
|
||||
"The last line of the patch must be '*** End Patch'",
|
||||
)
|
||||
})
|
||||
|
||||
test("allows whitespace after the end marker", () => {
|
||||
expect(parse("*** Begin Patch\n*** Add File: add.txt\n+added\n*** End Patch\n \t\n")).toEqual([
|
||||
{ type: "add", path: "add.txt", contents: "added" },
|
||||
])
|
||||
})
|
||||
|
||||
test("strips a heredoc wrapper", () => {
|
||||
|
|
@ -169,6 +181,25 @@ describe("Patch", () => {
|
|||
).toBe('He said "hi"\n')
|
||||
})
|
||||
|
||||
test("matches Unicode minus signs and spaces", () => {
|
||||
expect(
|
||||
Patch.derive("minus.txt", [{ oldLines: ["value - 1"], newLines: ["value - 2"] }], "value − 1\n")
|
||||
.content,
|
||||
).toBe("value - 2\n")
|
||||
const spaces = ["\u00A0", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200A", "\u202F", "\u205F", "\u3000"]
|
||||
spaces.forEach(
|
||||
(space) => {
|
||||
expect(
|
||||
Patch.derive(
|
||||
"spaces.txt",
|
||||
[{ oldLines: ["hello world"], newLines: ["hello there"] }],
|
||||
`hello${space}world\n`,
|
||||
).content,
|
||||
).toBe("hello there\n")
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
test("matches EOF-anchored chunks from the end", () => {
|
||||
expect(
|
||||
Patch.derive(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue