]>
git.proxmox.com Git - rustc.git/blob - vendor/heck-0.3.3/src/kebab.rs
1 use crate::{lowercase, transform}
;
3 /// This trait defines a kebab case conversion.
5 /// In kebab-case, word boundaries are indicated by hyphens.
10 /// use heck::KebabCase;
12 /// let sentence = "We are going to inherit the earth.";
13 /// assert_eq!(sentence.to_kebab_case(), "we-are-going-to-inherit-the-earth");
15 pub trait KebabCase
: ToOwned
{
16 /// Convert this type to kebab case.
17 fn to_kebab_case(&self) -> Self::Owned
;
20 impl KebabCase
for str {
21 fn to_kebab_case(&self) -> Self::Owned
{
22 transform(self, lowercase
, |s
| s
.push('
-'
))
31 ($t
:ident
: $s1
:expr
=> $s2
:expr
) => {
34 assert_eq
!($s1
.to_kebab_case(), $s2
)
39 t
!(test1
: "CamelCase" => "camel-case");
40 t
!(test2
: "This is Human case." => "this-is-human-case");
41 t
!(test3
: "MixedUP CamelCase, with some Spaces" => "mixed-up-camel-case-with-some-spaces");
42 t
!(test4
: "mixed_up_ snake_case with some _spaces" => "mixed-up-snake-case-with-some-spaces");
43 t
!(test5
: "kebab-case" => "kebab-case");
44 t
!(test6
: "SHOUTY_SNAKE_CASE" => "shouty-snake-case");
45 t
!(test7
: "snake_case" => "snake-case");
46 t
!(test8
: "this-contains_ ALLKinds OfWord_Boundaries" => "this-contains-all-kinds-of-word-boundaries");
47 t
!(test9
: "XΣXΣ baffle" => "xσxς-baffle");
48 t
!(test10
: "XMLHttpRequest" => "xml-http-request");