Merge pull request #9 from zaeleus/to_camel_case
Rename erroneously named to_snake_case
This commit is contained in:
commit
0e65a20c77
6 changed files with 30 additions and 30 deletions
22
src/lib.rs
22
src/lib.rs
|
@ -342,7 +342,7 @@ impl ToJson for ExecutionError {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn to_snake_case(s: &str) -> String {
|
pub fn to_camel_case(s: &str) -> String {
|
||||||
let mut dest = String::new();
|
let mut dest = String::new();
|
||||||
|
|
||||||
for (i, part) in s.split('_').enumerate() {
|
for (i, part) in s.split('_').enumerate() {
|
||||||
|
@ -365,14 +365,14 @@ pub fn to_snake_case(s: &str) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_to_snake_case() {
|
fn test_to_camel_case() {
|
||||||
assert_eq!(&to_snake_case("test")[..], "test");
|
assert_eq!(&to_camel_case("test")[..], "test");
|
||||||
assert_eq!(&to_snake_case("_test")[..], "Test");
|
assert_eq!(&to_camel_case("_test")[..], "Test");
|
||||||
assert_eq!(&to_snake_case("first_second")[..], "firstSecond");
|
assert_eq!(&to_camel_case("first_second")[..], "firstSecond");
|
||||||
assert_eq!(&to_snake_case("first_")[..], "first");
|
assert_eq!(&to_camel_case("first_")[..], "first");
|
||||||
assert_eq!(&to_snake_case("a_b_c")[..], "aBC");
|
assert_eq!(&to_camel_case("a_b_c")[..], "aBC");
|
||||||
assert_eq!(&to_snake_case("a_bc")[..], "aBc");
|
assert_eq!(&to_camel_case("a_bc")[..], "aBc");
|
||||||
assert_eq!(&to_snake_case("a_b")[..], "aB");
|
assert_eq!(&to_camel_case("a_b")[..], "aB");
|
||||||
assert_eq!(&to_snake_case("a")[..], "a");
|
assert_eq!(&to_camel_case("a")[..], "a");
|
||||||
assert_eq!(&to_snake_case("")[..], "");
|
assert_eq!(&to_camel_case("")[..], "");
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ macro_rules! __graphql__args {
|
||||||
$name:ident $(= $default:tt)* : $ty:ty $(as $desc:tt)*, $($rest:tt)*
|
$name:ident $(= $default:tt)* : $ty:ty $(as $desc:tt)*, $($rest:tt)*
|
||||||
) => {
|
) => {
|
||||||
let $name: $ty = $args
|
let $name: $ty = $args
|
||||||
.get(&$crate::to_snake_case(stringify!($name)))
|
.get(&$crate::to_camel_case(stringify!($name)))
|
||||||
.expect("Argument missing - validation must have failed");
|
.expect("Argument missing - validation must have failed");
|
||||||
__graphql__args!(@assign_arg_vars, $args, $executorvar, $($rest)*);
|
__graphql__args!(@assign_arg_vars, $args, $executorvar, $($rest)*);
|
||||||
};
|
};
|
||||||
|
@ -38,7 +38,7 @@ macro_rules! __graphql__args {
|
||||||
$name:ident $(= $default:tt)* : $ty:ty $(as $desc:expr)*
|
$name:ident $(= $default:tt)* : $ty:ty $(as $desc:expr)*
|
||||||
) => {
|
) => {
|
||||||
let $name: $ty = $args
|
let $name: $ty = $args
|
||||||
.get(&$crate::to_snake_case(stringify!($name)))
|
.get(&$crate::to_camel_case(stringify!($name)))
|
||||||
.expect("Argument missing - validation must have failed");
|
.expect("Argument missing - validation must have failed");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ macro_rules! __graphql__args {
|
||||||
$reg:expr, $base:expr, ( $name:ident = $default:tt : $t:ty )
|
$reg:expr, $base:expr, ( $name:ident = $default:tt : $t:ty )
|
||||||
) => {
|
) => {
|
||||||
$base.argument($reg.arg_with_default::<$t>(
|
$base.argument($reg.arg_with_default::<$t>(
|
||||||
&$crate::to_snake_case(stringify!($name)),
|
&$crate::to_camel_case(stringify!($name)),
|
||||||
&__graphql__args!(@as_expr, $default)))
|
&__graphql__args!(@as_expr, $default)))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ macro_rules! __graphql__args {
|
||||||
@apply_args,
|
@apply_args,
|
||||||
$reg,
|
$reg,
|
||||||
$base.argument($reg.arg_with_default::<$t>(
|
$base.argument($reg.arg_with_default::<$t>(
|
||||||
&$crate::to_snake_case(stringify!($name)),
|
&$crate::to_camel_case(stringify!($name)),
|
||||||
&__graphql__args!(@as_expr, $default))),
|
&__graphql__args!(@as_expr, $default))),
|
||||||
( $($rest)* ))
|
( $($rest)* ))
|
||||||
};
|
};
|
||||||
|
@ -99,7 +99,7 @@ macro_rules! __graphql__args {
|
||||||
@apply_args,
|
@apply_args,
|
||||||
$reg,
|
$reg,
|
||||||
$base.argument($reg.arg_with_default::<$t>(
|
$base.argument($reg.arg_with_default::<$t>(
|
||||||
&$crate::to_snake_case(stringify!($name)),
|
&$crate::to_camel_case(stringify!($name)),
|
||||||
&__graphql__args!(@as_expr, $default))
|
&__graphql__args!(@as_expr, $default))
|
||||||
.description($desc)),
|
.description($desc)),
|
||||||
( $($rest)* ))
|
( $($rest)* ))
|
||||||
|
@ -110,7 +110,7 @@ macro_rules! __graphql__args {
|
||||||
$reg:expr, $base:expr, ( $name:ident : $t:ty )
|
$reg:expr, $base:expr, ( $name:ident : $t:ty )
|
||||||
) => {
|
) => {
|
||||||
$base.argument($reg.arg::<$t>(
|
$base.argument($reg.arg::<$t>(
|
||||||
&$crate::to_snake_case(stringify!($name))))
|
&$crate::to_camel_case(stringify!($name))))
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -121,7 +121,7 @@ macro_rules! __graphql__args {
|
||||||
@apply_args,
|
@apply_args,
|
||||||
$reg,
|
$reg,
|
||||||
$base.argument($reg.arg::<$t>(
|
$base.argument($reg.arg::<$t>(
|
||||||
&$crate::to_snake_case(stringify!($name)))),
|
&$crate::to_camel_case(stringify!($name)))),
|
||||||
( $($rest)* ))
|
( $($rest)* ))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ macro_rules! __graphql__args {
|
||||||
$reg,
|
$reg,
|
||||||
$base.argument(
|
$base.argument(
|
||||||
$reg.arg::<$t>(
|
$reg.arg::<$t>(
|
||||||
&$crate::to_snake_case(stringify!($name)))
|
&$crate::to_camel_case(stringify!($name)))
|
||||||
.description($desc)),
|
.description($desc)),
|
||||||
( $($rest)* ))
|
( $($rest)* ))
|
||||||
};
|
};
|
||||||
|
|
|
@ -68,7 +68,7 @@ macro_rules! __graphql__build_field_matches {
|
||||||
( $( ( $name:ident; ( $($args:tt)* ); $t:ty; $body:block ) )* ),
|
( $( ( $name:ident; ( $($args:tt)* ); $t:ty; $body:block ) )* ),
|
||||||
) => {
|
) => {
|
||||||
$(
|
$(
|
||||||
if $fieldvar == &$crate::to_snake_case(stringify!($name)) {
|
if $fieldvar == &$crate::to_camel_case(stringify!($name)) {
|
||||||
let result: $t = (|| {
|
let result: $t = (|| {
|
||||||
__graphql__args!(
|
__graphql__args!(
|
||||||
@assign_arg_vars,
|
@assign_arg_vars,
|
||||||
|
|
|
@ -49,7 +49,7 @@ macro_rules! graphql_input_object {
|
||||||
) => {
|
) => {
|
||||||
Some($name {
|
Some($name {
|
||||||
$( $field_name: {
|
$( $field_name: {
|
||||||
let n: String = $crate::to_snake_case(stringify!($field_name));
|
let n: String = $crate::to_camel_case(stringify!($field_name));
|
||||||
let v: Option<&&$crate::InputValue> = $var.get(&n[..]);
|
let v: Option<&&$crate::InputValue> = $var.get(&n[..]);
|
||||||
|
|
||||||
if let Some(v) = v {
|
if let Some(v) = v {
|
||||||
|
@ -84,7 +84,7 @@ macro_rules! graphql_input_object {
|
||||||
@apply_description,
|
@apply_description,
|
||||||
$($descr)*,
|
$($descr)*,
|
||||||
$reg.arg::<$field_type>(
|
$reg.arg::<$field_type>(
|
||||||
&$crate::to_snake_case(stringify!($field_name))))
|
&$crate::to_camel_case(stringify!($field_name))))
|
||||||
),*
|
),*
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
@ -100,7 +100,7 @@ macro_rules! graphql_interface {
|
||||||
@apply_args,
|
@apply_args,
|
||||||
$reg,
|
$reg,
|
||||||
$reg.field_convert::<$t, _, Self::Context>(
|
$reg.field_convert::<$t, _, Self::Context>(
|
||||||
&$crate::to_snake_case(stringify!($name)))
|
&$crate::to_camel_case(stringify!($name)))
|
||||||
.description($desc)
|
.description($desc)
|
||||||
.deprecated($reason),
|
.deprecated($reason),
|
||||||
$args));
|
$args));
|
||||||
|
@ -118,7 +118,7 @@ macro_rules! graphql_interface {
|
||||||
@apply_args,
|
@apply_args,
|
||||||
$reg,
|
$reg,
|
||||||
$reg.field_convert::<$t, _, Self::Context>(
|
$reg.field_convert::<$t, _, Self::Context>(
|
||||||
&$crate::to_snake_case(stringify!($name)))
|
&$crate::to_camel_case(stringify!($name)))
|
||||||
.deprecated($reason),
|
.deprecated($reason),
|
||||||
$args));
|
$args));
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ macro_rules! graphql_interface {
|
||||||
@apply_args,
|
@apply_args,
|
||||||
$reg,
|
$reg,
|
||||||
$reg.field_convert::<$t, _, Self::Context>(
|
$reg.field_convert::<$t, _, Self::Context>(
|
||||||
&$crate::to_snake_case(stringify!($name)))
|
&$crate::to_camel_case(stringify!($name)))
|
||||||
.description($desc),
|
.description($desc),
|
||||||
$args));
|
$args));
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ macro_rules! graphql_interface {
|
||||||
@apply_args,
|
@apply_args,
|
||||||
$reg,
|
$reg,
|
||||||
$reg.field_convert::<$t, _, Self::Context>(
|
$reg.field_convert::<$t, _, Self::Context>(
|
||||||
&$crate::to_snake_case(stringify!($name))),
|
&$crate::to_camel_case(stringify!($name))),
|
||||||
$args));
|
$args));
|
||||||
|
|
||||||
graphql_interface!(@ gather_meta, ($reg, $acc, $descr), $( $rest )*);
|
graphql_interface!(@ gather_meta, ($reg, $acc, $descr), $( $rest )*);
|
||||||
|
|
|
@ -238,7 +238,7 @@ macro_rules! graphql_object {
|
||||||
@apply_args,
|
@apply_args,
|
||||||
$reg,
|
$reg,
|
||||||
$reg.field_convert::<$t, _, Self::Context>(
|
$reg.field_convert::<$t, _, Self::Context>(
|
||||||
&$crate::to_snake_case(stringify!($name)))
|
&$crate::to_camel_case(stringify!($name)))
|
||||||
.description($desc)
|
.description($desc)
|
||||||
.deprecated($reason),
|
.deprecated($reason),
|
||||||
$args));
|
$args));
|
||||||
|
@ -256,7 +256,7 @@ macro_rules! graphql_object {
|
||||||
@apply_args,
|
@apply_args,
|
||||||
$reg,
|
$reg,
|
||||||
$reg.field_convert::<$t, _, Self::Context>(
|
$reg.field_convert::<$t, _, Self::Context>(
|
||||||
&$crate::to_snake_case(stringify!($name)))
|
&$crate::to_camel_case(stringify!($name)))
|
||||||
.deprecated($reason),
|
.deprecated($reason),
|
||||||
$args));
|
$args));
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ macro_rules! graphql_object {
|
||||||
@apply_args,
|
@apply_args,
|
||||||
$reg,
|
$reg,
|
||||||
$reg.field_convert::<$t, _, Self::Context>(
|
$reg.field_convert::<$t, _, Self::Context>(
|
||||||
&$crate::to_snake_case(stringify!($name)))
|
&$crate::to_camel_case(stringify!($name)))
|
||||||
.description($desc),
|
.description($desc),
|
||||||
$args));
|
$args));
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ macro_rules! graphql_object {
|
||||||
@apply_args,
|
@apply_args,
|
||||||
$reg,
|
$reg,
|
||||||
$reg.field_convert::<$t, _, Self::Context>(
|
$reg.field_convert::<$t, _, Self::Context>(
|
||||||
&$crate::to_snake_case(stringify!($name))),
|
&$crate::to_camel_case(stringify!($name))),
|
||||||
$args));
|
$args));
|
||||||
|
|
||||||
graphql_object!(@gather_object_meta, $reg, $acc, $descr, $ifaces, $( $rest )*);
|
graphql_object!(@gather_object_meta, $reg, $acc, $descr, $ifaces, $( $rest )*);
|
||||||
|
|
Loading…
Reference in a new issue