attr: rm unused ret bool from valid

This commit is contained in:
Noah Hellman 2023-05-12 19:52:04 +02:00
parent c804e666ec
commit 599b712f36
2 changed files with 13 additions and 15 deletions

View file

@ -8,26 +8,24 @@ pub(crate) fn parse(src: &str) -> Attributes {
a a
} }
pub fn valid<I: Iterator<Item = char>>(chars: I) -> (usize, bool) { pub fn valid<I: Iterator<Item = char>>(chars: I) -> usize {
use State::*; use State::*;
let mut has_attr = false;
let mut n = 0; let mut n = 0;
let mut state = Start; let mut state = Start;
for c in chars { for c in chars {
n += 1; n += 1;
state = state.step(c); state = state.step(c);
match state { match state {
Class | Identifier | Value | ValueQuoted => has_attr = true,
Done | Invalid => break, Done | Invalid => break,
_ => {} _ => {}
} }
} }
if matches!(state, Done) { if matches!(state, Done) {
(n, has_attr) n
} else { } else {
(0, false) 0
} }
} }
@ -519,25 +517,25 @@ mod test {
#[test] #[test]
fn valid_full() { fn valid_full() {
let src = "{.class %comment%}"; let src = "{.class %comment%}";
assert_eq!(super::valid(src.chars()), (src.len(), true)); assert_eq!(super::valid(src.chars()), src.len());
} }
#[test] #[test]
fn valid_empty() { fn valid_empty() {
let src = "{}"; let src = "{}";
assert_eq!(super::valid(src.chars()), (src.len(), false)); assert_eq!(super::valid(src.chars()), src.len());
} }
#[test] #[test]
fn valid_whitespace() { fn valid_whitespace() {
let src = "{ \n }"; let src = "{ \n }";
assert_eq!(super::valid(src.chars()), (src.len(), false)); assert_eq!(super::valid(src.chars()), src.len());
} }
#[test] #[test]
fn valid_comment() { fn valid_comment() {
let src = "{%comment%}"; let src = "{%comment%}";
assert_eq!(super::valid(src.chars()), (src.len(), false)); assert_eq!(super::valid(src.chars()), src.len());
} }
#[test] #[test]
@ -545,15 +543,15 @@ mod test {
let src = "{.class}"; let src = "{.class}";
assert_eq!( assert_eq!(
super::valid(src.chars().chain("{.ignore}".chars())), super::valid(src.chars().chain("{.ignore}".chars())),
(src.len(), true), src.len(),
); );
} }
#[test] #[test]
fn valid_invalid() { fn valid_invalid() {
assert_eq!(super::valid(" {.valid}".chars()), (0, false)); assert_eq!(super::valid(" {.valid}".chars()), 0);
assert_eq!(super::valid("{.class invalid}".chars()), (0, false)); assert_eq!(super::valid("{.class invalid}".chars()), 0);
assert_eq!(super::valid("abc".chars()), (0, false)); assert_eq!(super::valid("abc".chars()), 0);
assert_eq!(super::valid("{.abc.}".chars()), (0, false)); assert_eq!(super::valid("{.abc.}".chars()), 0);
} }
} }

View file

@ -836,7 +836,7 @@ impl<'s> IdentifiedBlock<'s> {
None None
} }
} }
'{' => (attr::valid(line.chars()).0 == lt) '{' => (attr::valid(line.chars()) == lt)
.then(|| (Kind::Atom(Attributes), Span::by_len(indent_bytes, l))), .then(|| (Kind::Atom(Attributes), Span::by_len(indent_bytes, l))),
'|' => { '|' => {
if lt >= 2 && line_t.ends_with('|') && !line_t.ends_with("\\|") { if lt >= 2 && line_t.ends_with('|') && !line_t.ends_with("\\|") {