Skip to content

Commit 02c9d7f

Browse files
committed
test: add test cases and update sandbox around special characters
1 parent 3302df7 commit 02c9d7f

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

bin/reset_sandbox.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cd "$DIR"
1313

1414
# Create a commit, so that the extension can run diff-index, which requires an
1515
# initial commit.
16-
echo "# Sandbox\n" >'README.md'
16+
echo '# Sandbox' >'README.md'
1717
echo 'console.log("Hello, Foo!");' >foo.js
1818
echo 'console.log("Hello, Fizz!");' >fizz.js
1919
echo 'console.log("Hello, Buzz!");' >buzz.js
@@ -32,3 +32,6 @@ mkdir -p my_subdir
3232
mv bazz.js my_subdir
3333
# Delete.
3434
rm buzz.js
35+
36+
# Special characters.
37+
echo '# Special characters' >'spëcial châracters.md'

src/test/prepareCommitMsg.test.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as assert from "assert";
77
import { MsgPieces } from "../generate/parseExisting.d";
88
import { CONVENTIONAL_TYPE } from "../lib/constants";
99
import {
10-
generateMsg,
1110
_collapse,
1211
_combineOldAndNew,
1312
_formatMsg,
@@ -19,6 +18,7 @@ import {
1918
_msgNamed,
2019
_newMsg,
2120
_prefixFromChange,
21+
generateMsg,
2222
} from "../prepareCommitMsg";
2323
import { ConvCommitMsg } from "../prepareCommitMsg.d";
2424

@@ -712,6 +712,10 @@ describe("Prepare commit message", function () {
712712
it("handles a single created file", function () {
713713
assert.strictEqual(_newMsg(["A\tbaz.txt"]), "feat: create baz.txt");
714714
});
715+
716+
it("handles a single created file with special characters", function () {
717+
assert.strictEqual(_newMsg(["A\tspëcial châracters.md"]), "feat: create 'spëcial châracters.md'");
718+
});
715719
});
716720

717721
describe("multiple changes", function () {
@@ -1530,5 +1534,55 @@ describe("Prepare commit message", function () {
15301534
"update baz.txt and bar.js",
15311535
);
15321536
});
1537+
1538+
it("handles a single file change with a set old message", function () {
1539+
const singleFileChange = ["M\tbaz.txt"];
1540+
const oldMsg = "my old message";
1541+
1542+
assert.strictEqual(
1543+
generateMsg(singleFileChange, oldMsg),
1544+
"update baz.txt my old message",
1545+
);
1546+
});
1547+
1548+
it("handles a single file change with an empty old message", function () {
1549+
const singleFileChange = ["M\tbaz.txt"];
1550+
const oldMsg = "";
1551+
1552+
assert.strictEqual(
1553+
generateMsg(singleFileChange, oldMsg),
1554+
"update baz.txt",
1555+
);
1556+
});
1557+
1558+
it("handles multiple file changes with a set old message", function () {
1559+
const multipleFileChanges = ["M\tbaz.txt", "M\tbar.js", "M\tfoo.txt"];
1560+
const oldMsg = "my old message";
1561+
1562+
assert.strictEqual(
1563+
generateMsg(multipleFileChanges, oldMsg),
1564+
"update baz.txt, bar.js and foo.txt my old message",
1565+
);
1566+
});
1567+
1568+
it("handles multiple file changes with an empty old message", function () {
1569+
const multipleFileChanges = ["M\tbaz.txt", "M\tbar.js", "M\tfoo.txt"];
1570+
const oldMsg = "";
1571+
1572+
assert.strictEqual(
1573+
generateMsg(multipleFileChanges, oldMsg),
1574+
"update baz.txt, bar.js and foo.txt",
1575+
);
1576+
});
1577+
1578+
it("handles a single file change with special characters", function () {
1579+
const singleFileChange = ["M\tspëcial châracters.md"];
1580+
const oldMsg = "";
1581+
1582+
assert.strictEqual(
1583+
generateMsg(singleFileChange, oldMsg),
1584+
"update 'spëcial châracters.md'",
1585+
);
1586+
});
15331587
});
15341588
});

0 commit comments

Comments
 (0)