diff --git a/bin/reset_sandbox.sh b/bin/reset_sandbox.sh index 9e8c509..ffb9711 100755 --- a/bin/reset_sandbox.sh +++ b/bin/reset_sandbox.sh @@ -13,7 +13,7 @@ cd "$DIR" # Create a commit, so that the extension can run diff-index, which requires an # initial commit. -echo "# Sandbox\n" >'README.md' +echo '# Sandbox' >'README.md' echo 'console.log("Hello, Foo!");' >foo.js echo 'console.log("Hello, Fizz!");' >fizz.js echo 'console.log("Hello, Buzz!");' >buzz.js @@ -32,3 +32,6 @@ mkdir -p my_subdir mv bazz.js my_subdir # Delete. rm buzz.js + +# Special characters. +echo '# Special characters' >'spëcial châracters.md' diff --git a/src/test/prepareCommitMsg.test.ts b/src/test/prepareCommitMsg.test.ts index f19afbf..9a1f902 100644 --- a/src/test/prepareCommitMsg.test.ts +++ b/src/test/prepareCommitMsg.test.ts @@ -7,7 +7,6 @@ import * as assert from "assert"; import { MsgPieces } from "../generate/parseExisting.d"; import { CONVENTIONAL_TYPE } from "../lib/constants"; import { - generateMsg, _collapse, _combineOldAndNew, _formatMsg, @@ -19,6 +18,7 @@ import { _msgNamed, _newMsg, _prefixFromChange, + generateMsg, } from "../prepareCommitMsg"; import { ConvCommitMsg } from "../prepareCommitMsg.d"; @@ -712,6 +712,10 @@ describe("Prepare commit message", function () { it("handles a single created file", function () { assert.strictEqual(_newMsg(["A\tbaz.txt"]), "feat: create baz.txt"); }); + + it("handles a single created file with special characters", function () { + assert.strictEqual(_newMsg(["A\tspëcial châracters.md"]), "feat: create 'spëcial châracters.md'"); + }); }); describe("multiple changes", function () { @@ -1530,5 +1534,55 @@ describe("Prepare commit message", function () { "update baz.txt and bar.js", ); }); + + it("handles a single file change with a set old message", function () { + const singleFileChange = ["M\tbaz.txt"]; + const oldMsg = "my old message"; + + assert.strictEqual( + generateMsg(singleFileChange, oldMsg), + "update baz.txt my old message", + ); + }); + + it("handles a single file change with an empty old message", function () { + const singleFileChange = ["M\tbaz.txt"]; + const oldMsg = ""; + + assert.strictEqual( + generateMsg(singleFileChange, oldMsg), + "update baz.txt", + ); + }); + + it("handles multiple file changes with a set old message", function () { + const multipleFileChanges = ["M\tbaz.txt", "M\tbar.js", "M\tfoo.txt"]; + const oldMsg = "my old message"; + + assert.strictEqual( + generateMsg(multipleFileChanges, oldMsg), + "update baz.txt, bar.js and foo.txt my old message", + ); + }); + + it("handles multiple file changes with an empty old message", function () { + const multipleFileChanges = ["M\tbaz.txt", "M\tbar.js", "M\tfoo.txt"]; + const oldMsg = ""; + + assert.strictEqual( + generateMsg(multipleFileChanges, oldMsg), + "update baz.txt, bar.js and foo.txt", + ); + }); + + it("handles a single file change with special characters", function () { + const singleFileChange = ["M\tspëcial châracters.md"]; + const oldMsg = ""; + + assert.strictEqual( + generateMsg(singleFileChange, oldMsg), + "update 'spëcial châracters.md'", + ); + }); }); });