Compare commits

..

No commits in common. "a53a056cea89e35c75096b105aaccdc0363b1c18" and "ea0f76d528e3218267b78c93e4256e6521071807" have entirely different histories.

2 changed files with 5 additions and 99 deletions

View file

@ -23,7 +23,7 @@ use std::fmt::Display;
use std::iter::FusedIterator; use std::iter::FusedIterator;
/// Syntactic events that occurs in the config. Despite all these variants /// Syntactic events that occurs in the config. Despite all these variants
/// holding a [`Cow`] instead over a simple reference, the parser will only emit /// holding a [`Cow`] instead over a [`&str`], the parser will only emit
/// borrowed `Cow` variants. /// borrowed `Cow` variants.
/// ///
/// The `Cow` smart pointer is used here for ease of inserting events in a /// The `Cow` smart pointer is used here for ease of inserting events in a
@ -31,6 +31,7 @@ use std::iter::FusedIterator;
/// struct when adding values. /// struct when adding values.
/// ///
/// [`Cow`]: std::borrow::Cow /// [`Cow`]: std::borrow::Cow
/// [`&str`]: std::str
/// [`GitConfig`]: crate::config::GitConfig /// [`GitConfig`]: crate::config::GitConfig
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] #[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub enum Event<'a> { pub enum Event<'a> {

View file

@ -529,15 +529,10 @@ impl FromStr for ColorAttribute {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let inverted = s.starts_with("no"); let inverted = s.starts_with("no");
let mut parsed = s; let mut parsed = &s[2..];
if inverted {
parsed = &parsed[2..];
if parsed.starts_with("-") { if parsed.starts_with("-") {
parsed = &parsed[1..]; parsed = &parsed[1..];
} }
}
match parsed { match parsed {
"bold" if !inverted => Ok(Self::Bold), "bold" if !inverted => Ok(Self::Bold),
@ -620,93 +615,3 @@ mod integer {
assert!(Integer::from_str("gg").is_err()); assert!(Integer::from_str("gg").is_err());
} }
} }
#[cfg(test)]
mod color_attribute {
use super::ColorAttribute;
use std::str::FromStr;
#[test]
fn non_inverted() {
assert_eq!(ColorAttribute::from_str("bold"), Ok(ColorAttribute::Bold));
assert_eq!(ColorAttribute::from_str("dim"), Ok(ColorAttribute::Dim));
assert_eq!(ColorAttribute::from_str("ul"), Ok(ColorAttribute::Ul));
assert_eq!(ColorAttribute::from_str("blink"), Ok(ColorAttribute::Blink));
assert_eq!(
ColorAttribute::from_str("reverse"),
Ok(ColorAttribute::Reverse)
);
assert_eq!(
ColorAttribute::from_str("italic"),
Ok(ColorAttribute::Italic)
);
assert_eq!(
ColorAttribute::from_str("strike"),
Ok(ColorAttribute::Strike)
);
}
#[test]
fn inverted_no_dash() {
assert_eq!(
ColorAttribute::from_str("nobold"),
Ok(ColorAttribute::NoBold)
);
assert_eq!(ColorAttribute::from_str("nodim"), Ok(ColorAttribute::NoDim));
assert_eq!(ColorAttribute::from_str("noul"), Ok(ColorAttribute::NoUl));
assert_eq!(
ColorAttribute::from_str("noblink"),
Ok(ColorAttribute::NoBlink)
);
assert_eq!(
ColorAttribute::from_str("noreverse"),
Ok(ColorAttribute::NoReverse)
);
assert_eq!(
ColorAttribute::from_str("noitalic"),
Ok(ColorAttribute::NoItalic)
);
assert_eq!(
ColorAttribute::from_str("nostrike"),
Ok(ColorAttribute::NoStrike)
);
}
#[test]
fn inverted_dashed() {
assert_eq!(
ColorAttribute::from_str("no-bold"),
Ok(ColorAttribute::NoBold)
);
assert_eq!(
ColorAttribute::from_str("no-dim"),
Ok(ColorAttribute::NoDim)
);
assert_eq!(ColorAttribute::from_str("no-ul"), Ok(ColorAttribute::NoUl));
assert_eq!(
ColorAttribute::from_str("no-blink"),
Ok(ColorAttribute::NoBlink)
);
assert_eq!(
ColorAttribute::from_str("no-reverse"),
Ok(ColorAttribute::NoReverse)
);
assert_eq!(
ColorAttribute::from_str("no-italic"),
Ok(ColorAttribute::NoItalic)
);
assert_eq!(
ColorAttribute::from_str("no-strike"),
Ok(ColorAttribute::NoStrike)
);
}
#[test]
fn invalid() {
assert!(ColorAttribute::from_str("a").is_err());
assert!(ColorAttribute::from_str("no bold").is_err());
assert!(ColorAttribute::from_str("").is_err());
assert!(ColorAttribute::from_str("no").is_err());
assert!(ColorAttribute::from_str("no-").is_err());
}
}