1
0
Fork 0
forked from svrjs/svrjs
This repository has been archived on 2024-11-10. You can view files and clone it, but cannot push or open issues or pull requests.
svrjs/tests/utils/urlMojibakeFixer.test.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-09-14 16:23:49 +02:00
const fixNodeMojibakeURL = require("../../src/utils/urlMojibakeFixer.js");
describe("URL mojibake fixer", () => {
test("should return the same string for ASCII characters", () => {
expect(fixNodeMojibakeURL("hello world")).toBe("hello world");
});
test("should encode characters with values greater than 127", () => {
expect(fixNodeMojibakeURL("é")).toBe("%E9");
expect(fixNodeMojibakeURL("ñ")).toBe("%F1");
});
test("should uppercase the URL encodings", () => {
expect(fixNodeMojibakeURL("a%e9b")).toBe("a%E9b");
});
test("should handle mixed ASCII and non-ASCII characters", () => {
expect(fixNodeMojibakeURL("hello é world ñ")).toBe("hello %E9 world %F1");
});
test("should handle empty string", () => {
expect(fixNodeMojibakeURL("")).toBe("");
});
test("should handle strings with special characters", () => {
expect(fixNodeMojibakeURL("!@#$%^&*()")).toBe("!@#$%^&*()");
});
test("should handle strings with spaces", () => {
expect(fixNodeMojibakeURL("hello world")).toBe("hello world");
});
test("should handle strings with numbers", () => {
expect(fixNodeMojibakeURL("12345")).toBe("12345");
});
test("should handle strings with mixed characters", () => {
expect(fixNodeMojibakeURL("hello123 é world ñ!@#$%^&*()")).toBe(
"hello123 %E9 world %F1!@#$%^&*()"
);
});
});