Skip to content

Commit

Permalink
test: add test cases and update sandbox around special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelCurrin committed Aug 19, 2024
1 parent 3302df7 commit 02c9d7f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
5 changes: 4 additions & 1 deletion bin/reset_sandbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
56 changes: 55 additions & 1 deletion src/test/prepareCommitMsg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,6 +18,7 @@ import {
_msgNamed,
_newMsg,
_prefixFromChange,
generateMsg,
} from "../prepareCommitMsg";
import { ConvCommitMsg } from "../prepareCommitMsg.d";

Expand Down Expand Up @@ -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'");

Check failure on line 717 in src/test/prepareCommitMsg.test.ts

View workflow job for this annotation

GitHub Actions / build

This line has a length of 108. Maximum allowed is 100
});
});

describe("multiple changes", function () {
Expand Down Expand Up @@ -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'",
);
});
});
});

0 comments on commit 02c9d7f

Please sign in to comment.