-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:foundpatterns/torchbear
- Loading branch information
Showing
6 changed files
with
135 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "torchbear" | ||
description = "network application framework" | ||
version = "0.8.3" | ||
version = "0.8.4" | ||
authors = ["Mitchell Tannenbaum <[email protected]>"] | ||
repository = "https://github.com/foundpatterns/torchbear" | ||
readme = "Readme.md" | ||
|
@@ -54,6 +54,7 @@ regex = "1" | |
tantivy = "0.7" | ||
mime_guess = "1.8.6" | ||
scl = "0.0.1" | ||
heck = "0.3.0" | ||
|
||
[dev-dependencies] | ||
tempfile = "3" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use rlua::prelude::*; | ||
use heck::*; | ||
|
||
pub fn init(lua: &Lua) -> Result<(), LuaError> { | ||
|
||
let module = lua.create_table()?; | ||
|
||
module.set("to_camel_case", lua.create_function(|_, text: String| { | ||
Ok(text.to_camel_case()) | ||
})?)?; | ||
|
||
module.set("to_kebab_case", lua.create_function(|_, text: String| { | ||
Ok(text.to_kebab_case()) | ||
})?)?; | ||
|
||
module.set("to_mixed_case", lua.create_function(|_, text: String| { | ||
Ok(text.to_mixed_case()) | ||
})?)?; | ||
|
||
module.set("to_shouty_snake_case", lua.create_function(|_, text: String| { | ||
Ok(text.to_shouty_snake_case()) | ||
})?)?; | ||
|
||
module.set("to_snake_case", lua.create_function(|_, text: String| { | ||
Ok(text.to_snake_case()) | ||
})?)?; | ||
|
||
module.set("to_title_case", lua.create_function(|_, text: String| { | ||
Ok(text.to_title_case()) | ||
})?)?; | ||
|
||
lua.globals().set("heck", module)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn lua_heck_cambel () { | ||
let lua = Lua::new(); | ||
init(&lua).unwrap(); | ||
|
||
lua.exec::<_, ()>(r#" | ||
local val = "We are not in the least afraid of ruins" | ||
assert(heck.to_camel_case(val) == "WeAreNotInTheLeastAfraidOfRuins") | ||
"#, None).unwrap(); | ||
} | ||
|
||
#[test] | ||
fn lua_heck_kebab () { | ||
let lua = Lua::new(); | ||
init(&lua).unwrap(); | ||
|
||
lua.exec::<_, ()>(r#" | ||
local val = "We are going to inherit the earth" | ||
assert(heck.to_kebab_case(val) == "we-are-going-to-inherit-the-earth") | ||
"#, None).unwrap(); | ||
} | ||
|
||
#[test] | ||
fn lua_heck_mixed () { | ||
let lua = Lua::new(); | ||
init(&lua).unwrap(); | ||
|
||
lua.exec::<_, ()>(r#" | ||
local val = "It is we who built these palaces and cities" | ||
assert(heck.to_mixed_case(val) == "itIsWeWhoBuiltThesePalacesAndCities") | ||
"#, None).unwrap(); | ||
} | ||
|
||
#[test] | ||
fn lua_heck_shouty() { | ||
let lua = Lua::new(); | ||
init(&lua).unwrap(); | ||
|
||
lua.exec::<_, ()>(r#" | ||
local val = "That world is growing in this minute" | ||
assert(heck.to_shouty_snake_case(val) == "THAT_WORLD_IS_GROWING_IN_THIS_MINUTE") | ||
"#, None).unwrap(); | ||
} | ||
|
||
#[test] | ||
fn lua_heck_snake () { | ||
let lua = Lua::new(); | ||
init(&lua).unwrap(); | ||
|
||
lua.exec::<_, ()>(r#" | ||
local val = "We carry a new world here, in our hearts" | ||
assert(heck.to_snake_case(val) == "we_carry_a_new_world_here_in_our_hearts") | ||
"#, None).unwrap(); | ||
} | ||
|
||
#[test] | ||
fn lua_heck_title () { | ||
let lua = Lua::new(); | ||
init(&lua).unwrap(); | ||
|
||
lua.exec::<_, ()>(r#" | ||
local val = "We have always lived in slums and holes in the wall" | ||
assert(heck.to_title_case(val) == "We Have Always Lived In Slums And Holes In The Wall") | ||
"#, None).unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters