use test_tools::*;
tests_impls!
{
fn braces_unwrap()
{
static mut GOT : String = String::new();
macro_rules! test_with
{
(
$( $Arg : tt )*
) =>
{{
GOT += stringify!( $( $Arg )* );
GOT += ";";
}};
}
{
let ( a, b, c ) = ( 1, 2, 3 );
math_adapter::braces_unwrap!( dbg, { a, b, c } );
math_adapter::braces_unwrap!( dbg, a, b, c );
}
{
let ( prefix, a, b, c, postfix ) = ( "prefix", 1, 2, 3, "postfix" );
math_adapter::braces_unwrap!
(
dbg where
@Prefix{ prefix, }
@Postfix{ postfix }
@SRC{ { a, b, c, } }
);
math_adapter::braces_unwrap!
(
dbg where
@Prefix{ prefix, }
@Postfix{ postfix }
@SRC{ a, b, c, }
);
}
unsafe
{
GOT = "".to_string();
math_adapter::braces_unwrap!( test_with, a, b, c );
let exp = "a, b, c;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!( test_with, { a, b, c } );
let exp = "a, b, c;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!( test_with, { { a, b, c } } );
let exp = "{ a, b, c };";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!( test_with, ( a, b, c ) );
let exp = "(a, b, c);";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!( test_with, ( ( a, b, c ) ) );
let exp = "((a, b, c));";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!( test_with, [ a, b, c ] );
let exp = "[a, b, c];";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!( test_with, [ [ a, b, c ] ] );
let exp = "[[a, b, c]];";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@SRC{ a, b, c }
);
let exp = "a, b, c;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@SRC{ { a, b, c } }
);
let exp = "a, b, c;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@SRC{ { { a, b, c } } }
);
let exp = "{ a, b, c };";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@SRC{ ( a, b, c ) }
);
let exp = "(a, b, c);";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@SRC{ ( ( a, b, c ) ) }
);
let exp = "((a, b, c));";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@SRC{ [ a, b, c ] }
);
let exp = "[a, b, c];";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@SRC{ [ [ a, b, c ] ] }
);
let exp = "[[a, b, c]];";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@Postfix{ postfix }
@SRC{ a, b, c }
);
let exp = "prefix a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@Postfix{ postfix }
@SRC{ { a, b, c } }
);
let exp = "prefix a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@Postfix{ postfix }
@SRC{ { { a, b, c } } }
);
let exp = "prefix { a, b, c } postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@Postfix{ postfix }
@SRC{ ( a, b, c ) }
);
let exp = "prefix(a, b, c) postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@Postfix{ postfix }
@SRC{ ( ( a, b, c ) ) }
);
let exp = "prefix((a, b, c)) postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@Postfix{ postfix }
@SRC{ [ a, b, c ] }
);
let exp = "prefix [a, b, c] postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@Postfix{ postfix }
@SRC{ [ [ a, b, c ] ] }
);
let exp = "prefix [[a, b, c]] postfix;";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ { prefix } }
@Postfix{ { postfix } }
@SRC{ { a, b, c } }
);
let exp = "prefix a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ { prefix } }
@Postfix{ { postfix } }
@SRC{ { a, b, c } }
);
let exp = "prefix a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ { prefix } }
@Postfix{ { postfix } }
@SRC{ { a, b, c } }
);
let exp = "prefix a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ { prefix } }
@Postfix{ { postfix } }
@SRC{ { a, b, c } }
);
let exp = "prefix a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@Postfix{ { postfix } }
@SRC{ { a, b, c } }
);
let exp = "prefix a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@Postfix{ { postfix } }
@SRC{ a, b, c }
);
let exp = "prefix a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@Postfix{ postfix }
@SRC{ { a, b, c } }
);
let exp = "prefix a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@Postfix{ postfix }
@SRC{ a, b, c }
);
let exp = "prefix a, b, c postfix;";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@SRC{ a, b, c }
);
let exp = "prefix a, b, c;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@SRC{ { a, b, c } }
);
let exp = "prefix a, b, c;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@SRC{ { { a, b, c } } }
);
let exp = "prefix { a, b, c };";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@SRC{ ( a, b, c ) }
);
let exp = "prefix(a, b, c);";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@SRC{ ( ( a, b, c ) ) }
);
let exp = "prefix((a, b, c));";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@SRC{ [ a, b, c ] }
);
let exp = "prefix [a, b, c];";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@SRC{ [ [ a, b, c ] ] }
);
let exp = "prefix [[a, b, c]];";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ { prefix } }
@SRC{ { a, b, c } }
);
let exp = "prefix a, b, c;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ { prefix } }
@SRC{ a, b, c }
);
let exp = "prefix a, b, c;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@SRC{ { a, b, c } }
);
let exp = "prefix a, b, c;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Prefix{ prefix }
@SRC{ a, b, c }
);
let exp = "prefix a, b, c;";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Postfix{ postfix }
@SRC{ a, b, c }
);
let exp = "a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Postfix{ postfix }
@SRC{ { a, b, c } }
);
let exp = "a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Postfix{ postfix }
@SRC{ { { a, b, c } } }
);
let exp = "{ a, b, c } postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Postfix{ postfix }
@SRC{ ( a, b, c ) }
);
let exp = "(a, b, c) postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Postfix{ postfix }
@SRC{ ( ( a, b, c ) ) }
);
let exp = "((a, b, c)) postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Postfix{ postfix }
@SRC{ [ a, b, c ] }
);
let exp = "[a, b, c] postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Postfix{ postfix }
@SRC{ [ [ a, b, c ] ] }
);
let exp = "[[a, b, c]] postfix;";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Postfix{ { postfix } }
@SRC{ { a, b, c } }
);
let exp = "a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Postfix{ { postfix } }
@SRC{ a, b, c }
);
let exp = "a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Postfix{ postfix }
@SRC{ { a, b, c } }
);
let exp = "a, b, c postfix;";
a_id!( GOT, exp );
GOT = "".to_string();
math_adapter::braces_unwrap!
(
test_with where
@Postfix{ postfix }
@SRC{ a, b, c }
);
let exp = "a, b, c postfix;";
a_id!( GOT, exp );
}
}
fn for_each()
{
macro_rules! test_with
{
(
$( $Arg : tt )*
) =>
{{
GOT += stringify!( $( $Arg )* );
GOT += "+";
}};
}
static mut GOT : String = String::new();
{
math_adapter::for_each!( dbg, "a", "b", "c" );
dbg!( "a" );
dbg!( "b" );
dbg!( "c" );
}
{
math_adapter::for_each!
{
dbg where
@Prefix { "prefix".to_string() + }
@Postfix { + "postfix" }
@Each "a" "b" "c"
};
dbg!( "prefix".to_string() + "a" + "postfix" );
dbg!( "prefix".to_string() + "b" + "postfix" );
dbg!( "prefix".to_string() + "c" + "postfix" );
}
{
math_adapter::for_each!
{
dbg where
@Prefix { "prefix".to_string() + }
@Postfix { + "postfix" }
@Each { "a" + "1" } { "b" + "2" } { "c" + "3" }
};
dbg!( "prefix".to_string() + "a" + "1" + "postfix" );
dbg!( "prefix".to_string() + "b" + "2" + "postfix" );
dbg!( "prefix".to_string() + "c" + "3" + "postfix" );
}
{
math_adapter::for_each!
{
@Prefix { dbg! }
@Each ( "a" ) ( "b" ) ( "c" )
};
dbg!( "a" );
dbg!( "b" );
dbg!( "c" );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!( test_with, a, b, c );
let exp = "a+b+c+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!( test_with, { std::collections::HashMap }, { std::collections::BTreeMap } );
let exp = "std :: collections :: HashMap+std :: collections :: BTreeMap+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!( test_with, { a _ a }, { b _ b } );
let exp = "a _ a+b _ b+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!( test_with, { a _ a }, { b _ b }, );
let exp = "a _ a+b _ b+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!( test_with, ( std::collections::HashMap ), ( std::collections::BTreeMap ) );
let exp = "(std :: collections :: HashMap)+(std :: collections :: BTreeMap)+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!
{
@Prefix { test_with! }
@Postfix { ; test_with!( postfix ); }
@Each ( a ) ( b ) ( c )
};
let exp = "a+postfix+b+postfix+c+postfix+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!
{
@Prefix { test_with! }
@Each ( a ) ( b ) ( c )
};
let exp = "a+b+c+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!
{
@Postfix { ; test_with!( postfix ); }
@Each { test_with!( a ) } { test_with!( b ) } { test_with!( c ) }
};
let exp = "a+postfix+b+postfix+c+postfix+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!( test_with where @Each a b c );
let exp = "a+b+c+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!( test_with where @Prefix prefix @Postfix postfix @Each a b c );
let exp = "prefix a postfix+prefix b postfix+prefix c postfix+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!( test_with where @Prefix prefix @Each a b c );
let exp = "prefix a+prefix b+prefix c+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!( test_with where @Postfix postfix @Each a b c );
let exp = "a postfix+b postfix+c postfix+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!
{
test_with where
@Each { a _ a } { b _ b } { c _ c }
};
let exp = "a _ a+b _ b+c _ c+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!
{
test_with where
@Prefix { pre fix }
@Postfix { post fix }
@Each { a _ a } { b _ b } { c _ c }
};
let exp = "pre fix a _ a post fix+pre fix b _ b post fix+pre fix c _ c post fix+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!
{
test_with where
@Prefix { pre fix }
@Each { a _ a } { b _ b } { c _ c }
};
let exp = "pre fix a _ a+pre fix b _ b+pre fix c _ c+";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!
{
test_with where
@Postfix { post fix }
@Each { a _ a } { b _ b } { c _ c }
};
let exp = "a _ a post fix+b _ b post fix+c _ c post fix+";
a_id!( GOT, exp );
}
}
fn for_each_higher_order()
{
static mut GOT : String = String::new();
macro_rules! test_with
{
(
$( $Arg : tt )*
) =>
{{
GOT += stringify!( $( $Arg )* );
GOT += ";";
}};
}
macro_rules! for_each_float
{
(
$Callback : path
$( where $( $Args : tt )* )?
) =>
{
math_adapter::for_each!
(
$Callback where
$( $( $Args )* )?
@Each f32 f64
);
};
}
unsafe
{
GOT = "".to_string();
for_each_float!( test_with where @Prefix { pre fix 1 } @Postfix { post fix } );
for_each_float!( test_with where @Prefix { pre fix 2 } @Postfix { post fix } );
let exp = "pre fix 1 f32 post fix;pre fix 1 f64 post fix;pre fix 2 f32 post fix;pre fix 2 f64 post fix;";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!
{
for_each_float where
@Each
{ test_with where @Prefix { pre fix 1 } @Postfix { post fix } }
{ test_with where @Prefix { pre fix 2 } @Postfix { post fix } }
}
let exp = "pre fix 1 f32 post fix;pre fix 1 f64 post fix;pre fix 2 f32 post fix;pre fix 2 f64 post fix;";
a_id!( GOT, exp );
}
unsafe
{
GOT = "".to_string();
math_adapter::for_each!
{
for_each_float where
@Prefix { test_with where @Prefix }
@Postfix { @Postfix { post fix } }
@Each
{ { pre fix 1 } }
{ { pre fix 2 } }
}
let exp = "pre fix 1 f32 post fix;pre fix 1 f64 post fix;pre fix 2 f32 post fix;pre fix 2 f64 post fix;";
a_id!( GOT, exp );
}
}
}
tests_index!
{
braces_unwrap,
for_each,
for_each_higher_order,
}