Update rustfmt to 0.9.0.
This commit is contained in:
@@ -47,9 +47,11 @@ impl Directive {
|
||||
"unordered" => Ok(Directive::Unordered(pat)),
|
||||
"not" => {
|
||||
if !pat.defs().is_empty() {
|
||||
let msg = format!("can't define variables '$({}=...' in not: {}",
|
||||
pat.defs()[0],
|
||||
rest);
|
||||
let msg = format!(
|
||||
"can't define variables '$({}=...' in not: {}",
|
||||
pat.defs()[0],
|
||||
rest
|
||||
);
|
||||
Err(Error::DuplicateDef(msg))
|
||||
} else {
|
||||
Ok(Directive::Not(pat))
|
||||
@@ -63,16 +65,23 @@ impl Directive {
|
||||
fn regex(rest: &str) -> Result<Directive> {
|
||||
let varlen = varname_prefix(rest);
|
||||
if varlen == 0 {
|
||||
return Err(Error::Syntax(format!("invalid variable name in regex: {}", rest)));
|
||||
return Err(Error::Syntax(
|
||||
format!("invalid variable name in regex: {}", rest),
|
||||
));
|
||||
}
|
||||
let var = rest[0..varlen].to_string();
|
||||
if !rest[varlen..].starts_with('=') {
|
||||
return Err(Error::Syntax(format!("expected '=' after variable '{}' in regex: {}",
|
||||
var,
|
||||
rest)));
|
||||
return Err(Error::Syntax(format!(
|
||||
"expected '=' after variable '{}' in regex: {}",
|
||||
var,
|
||||
rest
|
||||
)));
|
||||
}
|
||||
// Ignore trailing white space in the regex, including CR.
|
||||
Ok(Directive::Regex(var, rest[varlen + 1..].trim_right().to_string()))
|
||||
Ok(Directive::Regex(
|
||||
var,
|
||||
rest[varlen + 1..].trim_right().to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,13 +192,13 @@ impl Checker {
|
||||
continue;
|
||||
}
|
||||
Directive::Regex(ref var, ref rx) => {
|
||||
state
|
||||
.vars
|
||||
.insert(var.clone(),
|
||||
VarDef {
|
||||
value: Value::Regex(Cow::Borrowed(rx)),
|
||||
offset: 0,
|
||||
});
|
||||
state.vars.insert(
|
||||
var.clone(),
|
||||
VarDef {
|
||||
value: Value::Regex(Cow::Borrowed(rx)),
|
||||
offset: 0,
|
||||
},
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
@@ -210,15 +219,16 @@ impl Checker {
|
||||
state.recorder.directive(not_idx);
|
||||
if let Some(mat) = rx.find(&text[not_begin..match_begin]) {
|
||||
// Matched `not:` pattern.
|
||||
state
|
||||
.recorder
|
||||
.matched_not(rx.as_str(),
|
||||
(not_begin + mat.start(), not_begin + mat.end()));
|
||||
state.recorder.matched_not(rx.as_str(), (
|
||||
not_begin + mat.start(),
|
||||
not_begin + mat.end(),
|
||||
));
|
||||
return Ok(false);
|
||||
} else {
|
||||
state
|
||||
.recorder
|
||||
.missed_not(rx.as_str(), (not_begin, match_begin));
|
||||
state.recorder.missed_not(
|
||||
rx.as_str(),
|
||||
(not_begin, match_begin),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -354,13 +364,13 @@ impl<'a> State<'a> {
|
||||
})
|
||||
};
|
||||
Ok(if let Some(mat) = matched_range {
|
||||
let r = (range.0 + mat.start(), range.0 + mat.end());
|
||||
self.recorder.matched_check(rx.as_str(), r);
|
||||
Some(r)
|
||||
} else {
|
||||
self.recorder.missed_check(rx.as_str(), range);
|
||||
None
|
||||
})
|
||||
let r = (range.0 + mat.start(), range.0 + mat.end());
|
||||
self.recorder.matched_check(rx.as_str(), r);
|
||||
Some(r)
|
||||
} else {
|
||||
self.recorder.missed_check(rx.as_str(), range);
|
||||
None
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,20 +423,32 @@ mod tests {
|
||||
let mut b = CheckerBuilder::new();
|
||||
|
||||
assert_eq!(b.directive("not here: more text").map_err(e2s), Ok(false));
|
||||
assert_eq!(b.directive("not here: regex: X=more text").map_err(e2s),
|
||||
Ok(true));
|
||||
assert_eq!(b.directive("regex: X = tommy").map_err(e2s),
|
||||
Err("expected '=' after variable 'X' in regex: X = tommy".to_string()));
|
||||
assert_eq!(b.directive("[arm]not: patt $x $(y) here").map_err(e2s),
|
||||
Ok(true));
|
||||
assert_eq!(b.directive("[x86]sameln: $x $(y=[^]]*) there").map_err(e2s),
|
||||
Ok(true));
|
||||
assert_eq!(
|
||||
b.directive("not here: regex: X=more text").map_err(e2s),
|
||||
Ok(true)
|
||||
);
|
||||
assert_eq!(
|
||||
b.directive("regex: X = tommy").map_err(e2s),
|
||||
Err(
|
||||
"expected '=' after variable 'X' in regex: X = tommy".to_string(),
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
b.directive("[arm]not: patt $x $(y) here").map_err(e2s),
|
||||
Ok(true)
|
||||
);
|
||||
assert_eq!(
|
||||
b.directive("[x86]sameln: $x $(y=[^]]*) there").map_err(e2s),
|
||||
Ok(true)
|
||||
);
|
||||
// Windows line ending sneaking in.
|
||||
assert_eq!(b.directive("regex: Y=foo\r").map_err(e2s), Ok(true));
|
||||
|
||||
let c = b.finish();
|
||||
assert_eq!(c.to_string(),
|
||||
"#0 regex: X=more text\n#1 not: patt $(x) $(y) here\n#2 sameln: $(x) \
|
||||
$(y=[^]]*) there\n#3 regex: Y=foo\n");
|
||||
assert_eq!(
|
||||
c.to_string(),
|
||||
"#0 regex: X=more text\n#1 not: patt $(x) $(y) here\n#2 sameln: $(x) \
|
||||
$(y=[^]]*) there\n#3 regex: Y=foo\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,16 +111,21 @@ impl<'a> Display for Explainer<'a> {
|
||||
}
|
||||
|
||||
// Emit the match message itself.
|
||||
writeln!(f,
|
||||
"{} #{}{}: {}",
|
||||
if m.is_match { "Matched" } else { "Missed" },
|
||||
m.directive,
|
||||
if m.is_not { " not" } else { "" },
|
||||
m.regex)?;
|
||||
writeln!(
|
||||
f,
|
||||
"{} #{}{}: {}",
|
||||
if m.is_match { "Matched" } else { "Missed" },
|
||||
m.directive,
|
||||
if m.is_not { " not" } else { "" },
|
||||
m.regex
|
||||
)?;
|
||||
|
||||
// Emit any variable definitions.
|
||||
if let Ok(found) = self.vardefs
|
||||
.binary_search_by_key(&m.directive, |v| v.directive) {
|
||||
if let Ok(found) = self.vardefs.binary_search_by_key(
|
||||
&m.directive,
|
||||
|v| v.directive,
|
||||
)
|
||||
{
|
||||
let mut first = found;
|
||||
while first > 0 && self.vardefs[first - 1].directive == m.directive {
|
||||
first -= 1;
|
||||
@@ -148,55 +153,50 @@ impl<'a> Recorder for Explainer<'a> {
|
||||
}
|
||||
|
||||
fn matched_check(&mut self, regex: &str, matched: MatchRange) {
|
||||
self.matches
|
||||
.push(Match {
|
||||
directive: self.directive,
|
||||
is_match: true,
|
||||
is_not: false,
|
||||
regex: regex.to_owned(),
|
||||
range: matched,
|
||||
});
|
||||
self.matches.push(Match {
|
||||
directive: self.directive,
|
||||
is_match: true,
|
||||
is_not: false,
|
||||
regex: regex.to_owned(),
|
||||
range: matched,
|
||||
});
|
||||
}
|
||||
|
||||
fn matched_not(&mut self, regex: &str, matched: MatchRange) {
|
||||
self.matches
|
||||
.push(Match {
|
||||
directive: self.directive,
|
||||
is_match: true,
|
||||
is_not: true,
|
||||
regex: regex.to_owned(),
|
||||
range: matched,
|
||||
});
|
||||
self.matches.push(Match {
|
||||
directive: self.directive,
|
||||
is_match: true,
|
||||
is_not: true,
|
||||
regex: regex.to_owned(),
|
||||
range: matched,
|
||||
});
|
||||
}
|
||||
|
||||
fn missed_check(&mut self, regex: &str, searched: MatchRange) {
|
||||
self.matches
|
||||
.push(Match {
|
||||
directive: self.directive,
|
||||
is_match: false,
|
||||
is_not: false,
|
||||
regex: regex.to_owned(),
|
||||
range: searched,
|
||||
});
|
||||
self.matches.push(Match {
|
||||
directive: self.directive,
|
||||
is_match: false,
|
||||
is_not: false,
|
||||
regex: regex.to_owned(),
|
||||
range: searched,
|
||||
});
|
||||
}
|
||||
|
||||
fn missed_not(&mut self, regex: &str, searched: MatchRange) {
|
||||
self.matches
|
||||
.push(Match {
|
||||
directive: self.directive,
|
||||
is_match: false,
|
||||
is_not: true,
|
||||
regex: regex.to_owned(),
|
||||
range: searched,
|
||||
});
|
||||
self.matches.push(Match {
|
||||
directive: self.directive,
|
||||
is_match: false,
|
||||
is_not: true,
|
||||
regex: regex.to_owned(),
|
||||
range: searched,
|
||||
});
|
||||
}
|
||||
|
||||
fn defined_var(&mut self, varname: &str, value: &str) {
|
||||
self.vardefs
|
||||
.push(VarDef {
|
||||
directive: self.directive,
|
||||
varname: varname.to_owned(),
|
||||
value: value.to_owned(),
|
||||
});
|
||||
self.vardefs.push(VarDef {
|
||||
directive: self.directive,
|
||||
varname: varname.to_owned(),
|
||||
value: value.to_owned(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,9 @@ impl Pattern {
|
||||
/// Return the allocated def number.
|
||||
fn add_def(&mut self, v: &str) -> Result<usize> {
|
||||
if self.defines_var(v) {
|
||||
Err(Error::DuplicateDef(format!("duplicate definition of ${} in same pattern", v)))
|
||||
Err(Error::DuplicateDef(
|
||||
format!("duplicate definition of ${} in same pattern", v),
|
||||
))
|
||||
} else {
|
||||
let idx = self.defs.len();
|
||||
self.defs.push(v.to_string());
|
||||
@@ -111,8 +113,10 @@ impl Pattern {
|
||||
|
||||
// All remaining possibilities start with `$(`.
|
||||
if s.len() < 2 || !s.starts_with("$(") {
|
||||
return Err(Error::Syntax("pattern syntax error, use $$ to match a single $"
|
||||
.to_string()));
|
||||
return Err(Error::Syntax(
|
||||
"pattern syntax error, use $$ to match a single $"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
// Match the variable name, allowing for an empty varname in `$()`, or `$(=...)`.
|
||||
@@ -137,7 +141,9 @@ impl Pattern {
|
||||
// Variable definition. Fall through.
|
||||
}
|
||||
Some(ch) => {
|
||||
return Err(Error::Syntax(format!("syntax error in $({}... '{}'", varname, ch)));
|
||||
return Err(Error::Syntax(
|
||||
format!("syntax error in $({}... '{}'", varname, ch),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,23 +161,31 @@ impl Pattern {
|
||||
let refname_begin = varname_end + 2;
|
||||
let refname_end = refname_begin + varname_prefix(&s[refname_begin..]);
|
||||
if refname_begin == refname_end {
|
||||
return Err(Error::Syntax(format!("expected variable name in $({}=$...", varname)));
|
||||
return Err(Error::Syntax(
|
||||
format!("expected variable name in $({}=$...", varname),
|
||||
));
|
||||
}
|
||||
if !s[refname_end..].starts_with(')') {
|
||||
return Err(Error::Syntax(format!("expected ')' after $({}=${}...",
|
||||
varname,
|
||||
&s[refname_begin..refname_end])));
|
||||
return Err(Error::Syntax(format!(
|
||||
"expected ')' after $({}=${}...",
|
||||
varname,
|
||||
&s[refname_begin..refname_end]
|
||||
)));
|
||||
}
|
||||
let refname = s[refname_begin..refname_end].to_string();
|
||||
return if let Some(defidx) = def {
|
||||
Ok((Part::DefVar {
|
||||
def: defidx,
|
||||
var: refname,
|
||||
},
|
||||
refname_end + 1))
|
||||
} else {
|
||||
Err(Error::Syntax(format!("expected variable name in $(=${})", refname)))
|
||||
};
|
||||
Ok((
|
||||
Part::DefVar {
|
||||
def: defidx,
|
||||
var: refname,
|
||||
},
|
||||
refname_end + 1,
|
||||
))
|
||||
} else {
|
||||
Err(Error::Syntax(
|
||||
format!("expected variable name in $(=${})", refname),
|
||||
))
|
||||
};
|
||||
}
|
||||
|
||||
// Last case: `$(var=...)` where `...` is a regular expression, possibly containing matched
|
||||
@@ -193,9 +207,11 @@ impl Pattern {
|
||||
};
|
||||
Ok((part, rx_end + 1))
|
||||
} else {
|
||||
Err(Error::Syntax(format!("missing ')' after regex in $({}={}",
|
||||
varname,
|
||||
&s[rx_begin..rx_end])))
|
||||
Err(Error::Syntax(format!(
|
||||
"missing ')' after regex in $({}={}",
|
||||
varname,
|
||||
&s[rx_begin..rx_end]
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,9 +289,11 @@ impl FromStr for Pattern {
|
||||
let (part, len) = pat.parse_part(&s[pos..])?;
|
||||
if let Some(v) = part.ref_var() {
|
||||
if pat.defines_var(v) {
|
||||
return Err(Error::Backref(format!("unsupported back-reference to '${}' \
|
||||
return Err(Error::Backref(format!(
|
||||
"unsupported back-reference to '${}' \
|
||||
defined in same pattern",
|
||||
v)));
|
||||
v
|
||||
)));
|
||||
}
|
||||
}
|
||||
pat.parts.push(part);
|
||||
@@ -410,49 +428,87 @@ mod tests {
|
||||
// This is dubious, should we panic instead?
|
||||
assert_eq!(pat.parse_part("").unwrap(), (Part::Text("".to_string()), 0));
|
||||
|
||||
assert_eq!(pat.parse_part("x").unwrap(),
|
||||
(Part::Text("x".to_string()), 1));
|
||||
assert_eq!(pat.parse_part("x2").unwrap(),
|
||||
(Part::Text("x2".to_string()), 2));
|
||||
assert_eq!(pat.parse_part("x$").unwrap(),
|
||||
(Part::Text("x".to_string()), 1));
|
||||
assert_eq!(pat.parse_part("x$$").unwrap(),
|
||||
(Part::Text("x".to_string()), 1));
|
||||
assert_eq!(
|
||||
pat.parse_part("x").unwrap(),
|
||||
(Part::Text("x".to_string()), 1)
|
||||
);
|
||||
assert_eq!(pat.parse_part("x2").unwrap(), (
|
||||
Part::Text("x2".to_string()),
|
||||
2,
|
||||
));
|
||||
assert_eq!(pat.parse_part("x$").unwrap(), (
|
||||
Part::Text("x".to_string()),
|
||||
1,
|
||||
));
|
||||
assert_eq!(pat.parse_part("x$$").unwrap(), (
|
||||
Part::Text("x".to_string()),
|
||||
1,
|
||||
));
|
||||
|
||||
assert_eq!(pat.parse_part("$").unwrap_err().to_string(),
|
||||
"pattern syntax error, use $$ to match a single $");
|
||||
assert_eq!(
|
||||
pat.parse_part("$").unwrap_err().to_string(),
|
||||
"pattern syntax error, use $$ to match a single $"
|
||||
);
|
||||
|
||||
assert_eq!(pat.parse_part("$$").unwrap(),
|
||||
(Part::Text("$".to_string()), 2));
|
||||
assert_eq!(pat.parse_part("$$ ").unwrap(),
|
||||
(Part::Text("$".to_string()), 2));
|
||||
assert_eq!(pat.parse_part("$$").unwrap(), (
|
||||
Part::Text("$".to_string()),
|
||||
2,
|
||||
));
|
||||
assert_eq!(pat.parse_part("$$ ").unwrap(), (
|
||||
Part::Text("$".to_string()),
|
||||
2,
|
||||
));
|
||||
|
||||
assert_eq!(pat.parse_part("$0").unwrap(),
|
||||
(Part::Var("0".to_string()), 2));
|
||||
assert_eq!(pat.parse_part("$xx=").unwrap(),
|
||||
(Part::Var("xx".to_string()), 3));
|
||||
assert_eq!(pat.parse_part("$xx$").unwrap(),
|
||||
(Part::Var("xx".to_string()), 3));
|
||||
assert_eq!(
|
||||
pat.parse_part("$0").unwrap(),
|
||||
(Part::Var("0".to_string()), 2)
|
||||
);
|
||||
assert_eq!(pat.parse_part("$xx=").unwrap(), (
|
||||
Part::Var("xx".to_string()),
|
||||
3,
|
||||
));
|
||||
assert_eq!(pat.parse_part("$xx$").unwrap(), (
|
||||
Part::Var("xx".to_string()),
|
||||
3,
|
||||
));
|
||||
|
||||
assert_eq!(pat.parse_part("$(0)").unwrap(),
|
||||
(Part::Var("0".to_string()), 4));
|
||||
assert_eq!(pat.parse_part("$()").unwrap(),
|
||||
(Part::Text("".to_string()), 3));
|
||||
assert_eq!(pat.parse_part("$(0)").unwrap(), (
|
||||
Part::Var("0".to_string()),
|
||||
4,
|
||||
));
|
||||
assert_eq!(pat.parse_part("$()").unwrap(), (
|
||||
Part::Text("".to_string()),
|
||||
3,
|
||||
));
|
||||
|
||||
assert_eq!(pat.parse_part("$(0").unwrap_err().to_string(),
|
||||
("unterminated $(0..."));
|
||||
assert_eq!(pat.parse_part("$(foo:").unwrap_err().to_string(),
|
||||
("syntax error in $(foo... ':'"));
|
||||
assert_eq!(pat.parse_part("$(foo =").unwrap_err().to_string(),
|
||||
("syntax error in $(foo... ' '"));
|
||||
assert_eq!(pat.parse_part("$(eo0=$bar").unwrap_err().to_string(),
|
||||
("expected ')' after $(eo0=$bar..."));
|
||||
assert_eq!(pat.parse_part("$(eo1=$bar}").unwrap_err().to_string(),
|
||||
("expected ')' after $(eo1=$bar..."));
|
||||
assert_eq!(pat.parse_part("$(eo2=$)").unwrap_err().to_string(),
|
||||
("expected variable name in $(eo2=$..."));
|
||||
assert_eq!(pat.parse_part("$(eo3=$-)").unwrap_err().to_string(),
|
||||
("expected variable name in $(eo3=$..."));
|
||||
assert_eq!(
|
||||
pat.parse_part("$(0").unwrap_err().to_string(),
|
||||
("unterminated $(0...")
|
||||
);
|
||||
assert_eq!(
|
||||
pat.parse_part("$(foo:").unwrap_err().to_string(),
|
||||
("syntax error in $(foo... ':'")
|
||||
);
|
||||
assert_eq!(
|
||||
pat.parse_part("$(foo =").unwrap_err().to_string(),
|
||||
("syntax error in $(foo... ' '")
|
||||
);
|
||||
assert_eq!(
|
||||
pat.parse_part("$(eo0=$bar").unwrap_err().to_string(),
|
||||
("expected ')' after $(eo0=$bar...")
|
||||
);
|
||||
assert_eq!(
|
||||
pat.parse_part("$(eo1=$bar}").unwrap_err().to_string(),
|
||||
("expected ')' after $(eo1=$bar...")
|
||||
);
|
||||
assert_eq!(
|
||||
pat.parse_part("$(eo2=$)").unwrap_err().to_string(),
|
||||
("expected variable name in $(eo2=$...")
|
||||
);
|
||||
assert_eq!(
|
||||
pat.parse_part("$(eo3=$-)").unwrap_err().to_string(),
|
||||
("expected variable name in $(eo3=$...")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -460,48 +516,65 @@ mod tests {
|
||||
use super::{Pattern, Part};
|
||||
let mut pat = Pattern::new();
|
||||
|
||||
assert_eq!(pat.parse_part("$(foo=$bar)").unwrap(),
|
||||
(Part::DefVar {
|
||||
def: 0,
|
||||
var: "bar".to_string(),
|
||||
},
|
||||
11));
|
||||
assert_eq!(pat.parse_part("$(foo=$bar)").unwrap_err().to_string(),
|
||||
"duplicate definition of $foo in same pattern");
|
||||
assert_eq!(pat.parse_part("$(foo=$bar)").unwrap(), (
|
||||
Part::DefVar {
|
||||
def: 0,
|
||||
var: "bar".to_string(),
|
||||
},
|
||||
11,
|
||||
));
|
||||
assert_eq!(
|
||||
pat.parse_part("$(foo=$bar)").unwrap_err().to_string(),
|
||||
"duplicate definition of $foo in same pattern"
|
||||
);
|
||||
|
||||
assert_eq!(pat.parse_part("$(fxo=$bar)x").unwrap(),
|
||||
(Part::DefVar {
|
||||
def: 1,
|
||||
var: "bar".to_string(),
|
||||
},
|
||||
11));
|
||||
assert_eq!(pat.parse_part("$(fxo=$bar)x").unwrap(), (
|
||||
Part::DefVar {
|
||||
def: 1,
|
||||
var: "bar".to_string(),
|
||||
},
|
||||
11,
|
||||
));
|
||||
|
||||
assert_eq!(pat.parse_part("$(fo2=[a-z])").unwrap(),
|
||||
(Part::DefLit {
|
||||
def: 2,
|
||||
regex: "(?P<fo2>[a-z])".to_string(),
|
||||
},
|
||||
12));
|
||||
assert_eq!(pat.parse_part("$(fo3=[a-)])").unwrap(),
|
||||
(Part::DefLit {
|
||||
def: 3,
|
||||
regex: "(?P<fo3>[a-)])".to_string(),
|
||||
},
|
||||
12));
|
||||
assert_eq!(pat.parse_part("$(fo4=)").unwrap(),
|
||||
(Part::DefLit {
|
||||
def: 4,
|
||||
regex: "(?P<fo4>)".to_string(),
|
||||
},
|
||||
7));
|
||||
assert_eq!(pat.parse_part("$(fo2=[a-z])").unwrap(), (
|
||||
Part::DefLit {
|
||||
def: 2,
|
||||
regex: "(?P<fo2>[a-z])".to_string(),
|
||||
},
|
||||
12,
|
||||
));
|
||||
assert_eq!(pat.parse_part("$(fo3=[a-)])").unwrap(), (
|
||||
Part::DefLit {
|
||||
def: 3,
|
||||
regex: "(?P<fo3>[a-)])".to_string(),
|
||||
},
|
||||
12,
|
||||
));
|
||||
assert_eq!(pat.parse_part("$(fo4=)").unwrap(), (
|
||||
Part::DefLit {
|
||||
def: 4,
|
||||
regex: "(?P<fo4>)".to_string(),
|
||||
},
|
||||
7,
|
||||
));
|
||||
|
||||
assert_eq!(pat.parse_part("$(=.*)").unwrap(),
|
||||
(Part::Regex("(?:.*)".to_string()), 6));
|
||||
assert_eq!(pat.parse_part("$(=.*)").unwrap(), (
|
||||
Part::Regex(
|
||||
"(?:.*)".to_string(),
|
||||
),
|
||||
6,
|
||||
));
|
||||
|
||||
assert_eq!(pat.parse_part("$(=)").unwrap(),
|
||||
(Part::Regex("(?:)".to_string()), 4));
|
||||
assert_eq!(pat.parse_part("$()").unwrap(),
|
||||
(Part::Text("".to_string()), 3));
|
||||
assert_eq!(pat.parse_part("$(=)").unwrap(), (
|
||||
Part::Regex(
|
||||
"(?:)".to_string(),
|
||||
),
|
||||
4,
|
||||
));
|
||||
assert_eq!(pat.parse_part("$()").unwrap(), (
|
||||
Part::Text("".to_string()),
|
||||
3,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -512,7 +585,9 @@ mod tests {
|
||||
assert_eq!(format!("{:?}", p.parts), "[Text(\"Hello world!\")]");
|
||||
|
||||
let p: Pattern = " $foo=$(bar) ".parse().unwrap();
|
||||
assert_eq!(format!("{:?}", p.parts),
|
||||
"[Var(\"foo\"), Text(\"=\"), Var(\"bar\")]");
|
||||
assert_eq!(
|
||||
format!("{:?}", p.parts),
|
||||
"[Var(\"foo\"), Text(\"=\"), Var(\"bar\")]"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user