std/text/unstable_slugify_test.ts

59 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert/equals";
import { slugify } from "./unstable_slugify.ts";
Deno.test("slugify() returns kebabcase", () => {
assertEquals(slugify("hello world"), "hello-world");
});
Deno.test("slugify() returns lowercase", () => {
assertEquals(slugify("Hello World"), "hello-world");
});
Deno.test("slugify() handles whitespaces", () => {
assertEquals(slugify(" Hello World "), "hello-world");
assertEquals(slugify("Hello\tWorld"), "hello-world");
assertEquals(slugify("Hello\nWorld"), "hello-world");
assertEquals(slugify("Hello\r\nWorld"), "hello-world");
});
Deno.test("slugify() replaces diacritic characters", () => {
assertEquals(slugify("déjà vu"), "deja-vu");
assertEquals(slugify("Cliché"), "cliche");
assertEquals(slugify("façade"), "facade");
assertEquals(slugify("résumé"), "resume");
});
Deno.test("slugify() handles dashes", () => {
assertEquals(slugify("-Hello-World-"), "hello-world");
assertEquals(slugify("--Hello--World--"), "hello-world");
});
Deno.test("slugify() handles empty string", () => {
assertEquals(slugify(""), "");
});
Deno.test("slugify() removes unknown special characters", () => {
assertEquals(slugify("hello ~ world"), "hello-world");
assertEquals(
slugify("Elon Musk considers move to Mars"),
"elon-musk-considers-move-to-mars",
);
assertEquals(
slugify("Fintech startups raised $34B in 2019"),
"fintech-startups-raised-34b-in-2019",
);
assertEquals(
slugify("Shopify joins Facebooks cryptocurrency Libra Association"),
"shopify-joins-facebooks-cryptocurrency-libra-association",
);
assertEquals(
slugify("What is a slug and how to optimize it?"),
"what-is-a-slug-and-how-to-optimize-it",
);
assertEquals(
slugify("Bitcoin soars past $33,000, its highest ever"),
"bitcoin-soars-past-33000-its-highest-ever",
);
});