Functional Weave
Code in Rust

text.slugify@1.0.0

vectors.json

2,312 bytes · view raw

[
  { "name": "an ordinary title", "args": ["Hello World"], "expect": "hello-world" },
  { "name": "something already a slug is left alone", "args": ["already-a-slug"], "expect": "already-a-slug" },
  { "name": "punctuation, repeated spaces and stray hyphens all collapse to one hyphen", "args": ["  --Héllo,   Wörld!--  "], "expect": "hello-world" },
  { "name": "accents are dropped, not expanded", "args": ["Crème Brûlée"], "expect": "creme-brulee" },
  { "name": "sharp s is two letters, so it becomes ss", "args": ["Straße"], "expect": "strasse" },
  { "name": "ligatures are letters in their own right", "args": ["Æther & Œuvre"], "expect": "aether-oeuvre" },
  { "name": "thorn and slashed o transliterate", "args": ["Ølsen Þórsdóttir"], "expect": "olsen-thorsdottir" },
  { "name": "the Windows-1252 carons are covered too", "args": ["Žižek Šuma"], "expect": "zizek-suma" },
  { "name": "y with diaeresis, upper and lower", "args": ["Ünicode ÿ Ÿ"], "expect": "unicode-y-y" },
  { "name": "digits survive and brackets do not", "args": ["Model 3 (2024)"], "expect": "model-3-2024" },
  { "name": "underscores are separators like any other non-alphanumeric", "args": ["snake_case_name"], "expect": "snake-case-name" },
  { "name": "a run of hyphens collapses to one", "args": ["a---b"], "expect": "a-b" },
  { "name": "separators at either end are trimmed", "args": ["-leading and trailing-"], "expect": "leading-and-trailing" },
  { "name": "mixed case folds down", "args": ["MIXED Case ÜBER"], "expect": "mixed-case-uber" },
  { "name": "an empty string slugifies to an empty string", "args": [""], "expect": "" },
  { "name": "punctuation alone leaves nothing", "args": ["!!!???"], "expect": "" },
  { "name": "characters outside the table are dropped, keeping the Latin ones", "args": ["東京 Tokyo"], "expect": "tokyo" },
  { "name": "a title in a script the table does not cover slugifies to empty rather than raising", "args": ["Ελλάδα"], "expect": "" },
  { "name": "emoji are dropped without leaving stray hyphens", "args": ["🚀 Launch Day 🚀"], "expect": "launch-day" },
  { "name": "a single character is a single character slug", "args": ["é"], "expect": "e" },
  { "name": "a non-string is a caller bug", "args": [42], "expectError": "slugify needs a string" }
]