1 use super::{parse_next_substitution as pns, Substitution as S}
;
3 macro_rules
! assert_eq_pnsat
{
4 ($lhs
:expr
, $rhs
:expr
) => {
6 pns($lhs
).and_then(|(f
, _
)| f
.translate()),
7 $rhs
.map(<String
as From
<&str>>::from
)
14 assert_eq
!(pns("has no escapes"), None
);
15 assert_eq
!(pns("has no escapes, either $"), None
);
16 assert_eq
!(pns("*so* has a $$ escape"), Some((S
::Escape((11, 13)), " escape")));
17 assert_eq
!(pns("$$ leading escape"), Some((S
::Escape((0, 2)), " leading escape")));
18 assert_eq
!(pns("trailing escape $$"), Some((S
::Escape((16, 18)), "")));
23 macro_rules
! assert_pns_eq_sub
{
24 ($in_
:expr
, $kind
:ident($arg
:expr
, $pos
:expr
)) => {
25 assert_eq
!(pns(concat
!($in_
, "!")), Some((S
::$
kind($arg
.into(), $pos
), "!")))
29 assert_pns_eq_sub
!("$0", Ordinal(0, (0, 2)));
30 assert_pns_eq_sub
!("$1", Ordinal(1, (0, 2)));
31 assert_pns_eq_sub
!("$9", Ordinal(9, (0, 2)));
32 assert_pns_eq_sub
!("$N", Name("N", (0, 2)));
33 assert_pns_eq_sub
!("$NAME", Name("NAME", (0, 5)));
39 let s
= "The $0'th word $$ is: `$WORD` $!\n";
40 let subs
: Vec
<_
> = iter_subs(s
, 0).map(|sub
| sub
.translate()).collect();
42 subs
.iter().map(|ms
| ms
.as_ref().map(|s
| &s
[..])).collect
::<Vec
<_
>>(),
43 vec
![Some("{0}"), None
, Some("{WORD}")]
48 fn test_translation() {
49 assert_eq_pnsat
!("$0", Some("{0}"));
50 assert_eq_pnsat
!("$9", Some("{9}"));
51 assert_eq_pnsat
!("$1", Some("{1}"));
52 assert_eq_pnsat
!("$10", Some("{1}"));
53 assert_eq_pnsat
!("$stuff", Some("{stuff}"));
54 assert_eq_pnsat
!("$NAME", Some("{NAME}"));
55 assert_eq_pnsat
!("$PREFIX/bin", Some("{PREFIX}"));