TravBot-v3/src/lib.test.ts

93 lines
3.3 KiB
TypeScript
Raw Normal View History

2020-12-15 01:44:28 +00:00
import {strict as assert} from "assert";
2021-05-06 13:30:51 +00:00
import {pluralise, pluraliseSigned, replaceAll, toTitleCase, split, parseVars, parseVarsCallback} from "./lib";
// I can't figure out a way to run the test suite while running the bot.
2020-12-15 01:44:28 +00:00
describe("Wrappers", () => {
describe("NumberWrapper", () => {
describe("#pluralise()", () => {
it('should return "5 credits"', () => {
assert.strictEqual(pluralise(5, "credit", "s"), "5 credits");
2020-12-15 01:44:28 +00:00
});
2020-10-15 09:23:24 +00:00
2020-12-15 01:44:28 +00:00
it('should return "1 credit"', () => {
assert.strictEqual(pluralise(1, "credit", "s"), "1 credit");
2020-12-15 01:44:28 +00:00
});
2020-10-15 09:23:24 +00:00
2020-12-15 01:44:28 +00:00
it('should return "-1 credits"', () => {
assert.strictEqual(pluralise(-1, "credit", "s"), "-1 credits");
2020-12-15 01:44:28 +00:00
});
2020-10-15 09:23:24 +00:00
2020-12-15 01:44:28 +00:00
it("should be able to work with a plural suffix", () => {
assert.strictEqual(pluralise(2, "part", "ies", "y"), "2 parties");
2020-12-15 01:44:28 +00:00
});
2020-10-15 09:23:24 +00:00
2020-12-15 01:44:28 +00:00
it("should be able to work with a singular suffix", () => {
assert.strictEqual(pluralise(1, "part", "ies", "y"), "1 party");
2020-12-15 01:44:28 +00:00
});
2020-10-15 09:23:24 +00:00
2020-12-15 01:44:28 +00:00
it("should be able to exclude the number", () => {
assert.strictEqual(pluralise(1, "credit", "s", "", true), "credit");
2020-12-15 01:44:28 +00:00
});
});
2020-10-15 09:23:24 +00:00
2020-12-15 01:44:28 +00:00
describe("#pluraliseSigned()", () => {
it('should return "-1 credits"', () => {
assert.strictEqual(pluraliseSigned(-1, "credit", "s"), "-1 credits");
2020-12-15 01:44:28 +00:00
});
2020-10-15 09:23:24 +00:00
2020-12-15 01:44:28 +00:00
it('should return "+0 credits"', () => {
assert.strictEqual(pluraliseSigned(0, "credit", "s"), "+0 credits");
2020-12-15 01:44:28 +00:00
});
2020-10-15 09:23:24 +00:00
2020-12-15 01:44:28 +00:00
it('should return "+1 credit"', () => {
assert.strictEqual(pluraliseSigned(1, "credit", "s"), "+1 credit");
2020-12-15 01:44:28 +00:00
});
});
2020-10-15 09:23:24 +00:00
});
2020-12-15 01:44:28 +00:00
describe("StringWrapper", () => {
describe("#replaceAll()", () => {
it('should convert "test" to "zesz"', () => {
assert.strictEqual(replaceAll("test", "t", "z"), "zesz");
2020-12-15 01:44:28 +00:00
});
});
2020-10-15 09:23:24 +00:00
describe("#parseVars()", () => {
it('should replace %test% with "yeet"', () => {
assert.strictEqual(parseVars("ya %test%", {test: "yeet"}), "ya yeet");
});
});
2021-05-06 13:30:51 +00:00
describe("#parseVarsCallback()", () => {
it('should replace %test% with "yeet"', () => {
assert.strictEqual(
parseVarsCallback("ya %test% the %pear%", (variable) => (variable === "test" ? "yeet" : "null")),
"ya yeet the null"
);
});
});
2020-12-15 01:44:28 +00:00
describe("#toTitleCase()", () => {
it("should capitalize the first letter of each word", () => {
assert.strictEqual(
toTitleCase("yeetus deletus find salvation from jesus"),
2020-12-15 01:44:28 +00:00
"Yeetus Deletus Find Salvation From Jesus"
);
});
});
2020-10-15 09:23:24 +00:00
});
2020-12-15 01:44:28 +00:00
describe("ArrayWrapper", () => {
describe("#split()", () => {
it("should split [1,2,3,4,5,6,7,8,9,10] into [[1,2,3],[4,5,6],[7,8,9],[10]]", () => {
assert.deepStrictEqual(split([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3), [
2020-12-15 07:56:09 +00:00
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10]
]);
2020-12-15 01:44:28 +00:00
});
});
2020-10-15 09:23:24 +00:00
});
});