2020-12-15 01:44:28 +00:00
|
|
|
import {strict as assert} from "assert";
|
2021-04-09 15:17:25 +00:00
|
|
|
import {pluralise, pluraliseSigned, replaceAll, toTitleCase, split, parseVars} from "./lib";
|
2020-08-26 02:49:08 +00:00
|
|
|
|
|
|
|
// 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"', () => {
|
2021-03-30 10:25:07 +00:00
|
|
|
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"', () => {
|
2021-03-30 10:25:07 +00:00
|
|
|
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"', () => {
|
2021-03-30 10:25:07 +00:00
|
|
|
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", () => {
|
2021-03-30 10:25:07 +00:00
|
|
|
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", () => {
|
2021-03-30 10:25:07 +00:00
|
|
|
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", () => {
|
2021-03-30 10:25:07 +00:00
|
|
|
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"', () => {
|
2021-03-30 10:25:07 +00:00
|
|
|
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"', () => {
|
2021-03-30 10:25:07 +00:00
|
|
|
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"', () => {
|
2021-03-30 10:25:07 +00:00
|
|
|
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"', () => {
|
2021-03-30 10:25:07 +00:00
|
|
|
assert.strictEqual(replaceAll("test", "t", "z"), "zesz");
|
2020-12-15 01:44:28 +00:00
|
|
|
});
|
|
|
|
});
|
2020-10-15 09:23:24 +00:00
|
|
|
|
2021-04-09 15:17:25 +00:00
|
|
|
describe("#parseVars()", () => {
|
|
|
|
it('should replace %test% with "yeet"', () => {
|
|
|
|
assert.strictEqual(parseVars("ya %test%", {test: "yeet"}), "ya yeet");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-15 01:44:28 +00:00
|
|
|
describe("#toTitleCase()", () => {
|
|
|
|
it("should capitalize the first letter of each word", () => {
|
|
|
|
assert.strictEqual(
|
2021-03-30 10:25:07 +00:00
|
|
|
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]]", () => {
|
2021-03-30 10:25:07 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|