Compare commits
2 commits
af4585ee2f
...
d03aa48ff3
Author | SHA1 | Date | |
---|---|---|---|
d03aa48ff3 | |||
54e86e4722 |
2 changed files with 159 additions and 4 deletions
|
@ -294,9 +294,12 @@ Il est souhaité d'écrire des tests quand cela est possible.
|
|||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const { fnReturnsTrue } = require("../src/utils/misc");
|
||||
|
||||
describe("test description", () => {
|
||||
test("test name", () => {
|
||||
expect(fnReturnsTrue() /* function to test */).toBe(true /* expected result */);
|
||||
});
|
||||
describe("test name", () => {
|
||||
{
|
||||
const name = "to be tested";
|
||||
test(name, () => {
|
||||
expect(fnReturnsTrue() /* function to test */).toBe(true /* expected result */);
|
||||
});
|
||||
}
|
||||
});
|
||||
```
|
||||
|
|
152
tests/misc.test.ts
Normal file
152
tests/misc.test.ts
Normal file
|
@ -0,0 +1,152 @@
|
|||
const {
|
||||
cleanCodeBlock,
|
||||
emojiPng,
|
||||
isImage,
|
||||
removeExtension,
|
||||
splitFilenameExtensions,
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
} = require("../src/utils/misc");
|
||||
|
||||
describe("Filename splitter", () => {
|
||||
{
|
||||
const name = "test.js";
|
||||
test(name, () => {
|
||||
expect(splitFilenameExtensions(name)).toStrictEqual({ file: "test", ext: "js" });
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = ".env";
|
||||
test(name, () => {
|
||||
expect(splitFilenameExtensions(name)).toStrictEqual({ file: ".env", ext: undefined });
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = ".env.test";
|
||||
test(name, () => {
|
||||
expect(splitFilenameExtensions(name)).toStrictEqual({
|
||||
file: ".env",
|
||||
ext: "test",
|
||||
});
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = "file.test.js";
|
||||
test(name, () => {
|
||||
expect(splitFilenameExtensions(name)).toStrictEqual({ file: "file.test", ext: "js" });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Extension remover", () => {
|
||||
{
|
||||
const name = "test.js";
|
||||
test(name, () => {
|
||||
expect(removeExtension(name)).toBe("test");
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = ".env";
|
||||
test(name, () => {
|
||||
expect(removeExtension(name)).toBe(".env");
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = ".env.test";
|
||||
test(name, () => {
|
||||
expect(removeExtension(name)).toBe(".env");
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = "file.test.js";
|
||||
test(name, () => {
|
||||
expect(removeExtension(name)).toBe("file.test");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Image checker", () => {
|
||||
{
|
||||
const name = "image.Png";
|
||||
test(name, () => {
|
||||
expect(isImage(name)).toBe(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = "image.jpeg";
|
||||
test(name, () => {
|
||||
expect(isImage(name)).toBe(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = "image.wav";
|
||||
test(name, () => {
|
||||
expect(isImage(name)).toBe(false);
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = "image.jpg";
|
||||
test(name, () => {
|
||||
expect(isImage(name)).toBe(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = "image.webP";
|
||||
test(name, () => {
|
||||
expect(isImage(name)).toBe(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = "image.GIF";
|
||||
test(name, () => {
|
||||
expect(isImage(name)).toBe(true);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Code block cleaner", () => {
|
||||
{
|
||||
const name = "salut";
|
||||
test(name, () => {
|
||||
expect(cleanCodeBlock(name)).toBe("`salut`");
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = "<@158260864623968257> ça va ?";
|
||||
test(name, () => {
|
||||
expect(cleanCodeBlock(name)).toBe("<@158260864623968257>` ça va ?`");
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = "t'as vu la vidéo ? https://youtu.be/dQw4w9WgXcQ";
|
||||
test(name, () => {
|
||||
expect(cleanCodeBlock(name)).toBe("`t'as vu la vidéo ? `https://youtu.be/dQw4w9WgXcQ");
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = "t'as vu la vidéo ? https://youtu.be/dQw4w9WgXcQ elle est cool en vrai tqt";
|
||||
test(name, () => {
|
||||
expect(cleanCodeBlock(name)).toBe(
|
||||
"`t'as vu la vidéo ? `https://youtu.be/dQw4w9WgXcQ` elle est cool en vrai tqt`",
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("test name", () => {
|
||||
{
|
||||
const name = "☺️";
|
||||
test(name, () => {
|
||||
expect(emojiPng(name)).toBe(
|
||||
"https://cdn.jsdelivr.net/gh/twitter/twemoji/assets/72x72/263a.png",
|
||||
);
|
||||
});
|
||||
}
|
||||
{
|
||||
const name = "🍕";
|
||||
test(name, () => {
|
||||
expect(emojiPng(name)).toBe(
|
||||
"https://cdn.jsdelivr.net/gh/twitter/twemoji/assets/72x72/1f355.png",
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
Loading…
Reference in a new issue