Compare commits

..

No commits in common. "5574ec326770a7b555d98955b1e285c375c72ecb" and "cd2f58c920a7845bd54ba887bcbf8e1dade924ce" have entirely different histories.

5 changed files with 25 additions and 86 deletions

View file

@ -97,7 +97,8 @@ impl MutableValue<'_, '_, '_> {
/// the Value event(s) are replaced with a single new event containing the /// the Value event(s) are replaced with a single new event containing the
/// new value. /// new value.
pub fn set_bytes(&mut self, input: Vec<u8>) { pub fn set_bytes(&mut self, input: Vec<u8>) {
self.section.drain(self.index..self.index + self.size); self.section.drain(self.index..self.size);
self.size = 1; self.size = 1;
self.section self.section
.insert(self.index, Event::Value(Cow::Owned(input))); .insert(self.index, Event::Value(Cow::Owned(input)));

View file

@ -111,7 +111,7 @@ pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
} }
} }
owned.extend(&input[last_index..]); owned.extend(dbg!(&input[last_index..]));
if owned.is_empty() { if owned.is_empty() {
input input
} else { } else {
@ -431,8 +431,8 @@ impl Serialize for TrueVariant<'_> {
/// [`bitwise_offset`]: IntegerSuffix::bitwise_offset /// [`bitwise_offset`]: IntegerSuffix::bitwise_offset
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct Integer { pub struct Integer {
pub value: i64, value: i64,
pub suffix: Option<IntegerSuffix>, suffix: Option<IntegerSuffix>,
} }
impl Display for Integer { impl Display for Integer {
@ -599,9 +599,26 @@ impl TryFrom<Vec<u8>> for IntegerSuffix {
/// foreground or background color. /// foreground or background color.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)] #[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct Color { pub struct Color {
pub foreground: Option<ColorValue>, foreground: Option<ColorValue>,
pub background: Option<ColorValue>, background: Option<ColorValue>,
pub attributes: Vec<ColorAttribute>, attributes: Vec<ColorAttribute>,
}
impl Color {
/// Returns the foreground color, if any.
pub const fn foreground(&self) -> Option<ColorValue> {
self.foreground
}
/// Returns the background color, if any.
pub const fn background(&self) -> Option<ColorValue> {
self.background
}
/// Returns the list of text modifiers, if any.
pub fn attributes(&self) -> &[ColorAttribute] {
&self.attributes
}
} }
impl Display for Color { impl Display for Color {

View file

@ -1,71 +0,0 @@
use git_config::file::GitConfig;
use git_config::values::*;
use std::borrow::Cow;
use std::convert::TryFrom;
/// Asserts we can cast into all variants of our type
#[test]
fn get_value_for_all_provided_values() -> Result<(), Box<dyn std::error::Error>> {
let config = r#"
[core]
bool-explicit = false
bool-implicit
integer-no-prefix = 10
integer-prefix = 10g
color = brightgreen red \
bold
other = hello world
"#;
let file = GitConfig::try_from(config)?;
assert_eq!(
file.get_value::<Boolean>("core", None, "bool-explicit")?,
Boolean::False(Cow::Borrowed("false"))
);
assert_eq!(
file.get_value::<Boolean>("core", None, "bool-implicit")?,
Boolean::True(TrueVariant::Implicit)
);
assert_eq!(
file.get_value::<Integer>("core", None, "integer-no-prefix")?,
Integer {
value: 10,
suffix: None
}
);
assert_eq!(
file.get_value::<Integer>("core", None, "integer-no-prefix")?,
Integer {
value: 10,
suffix: None
}
);
assert_eq!(
file.get_value::<Integer>("core", None, "integer-prefix")?,
Integer {
value: 10,
suffix: Some(IntegerSuffix::Gibi),
}
);
assert_eq!(
file.get_value::<Color>("core", None, "color")?,
Color {
foreground: Some(ColorValue::BrightGreen),
background: Some(ColorValue::Red),
attributes: vec![ColorAttribute::Bold]
}
);
assert_eq!(
file.get_value::<Value>("core", None, "other")?,
Value::Other(Cow::Borrowed(b"hello world"))
);
Ok(())
}

View file

@ -1,8 +0,0 @@
// See https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html
// for an explanation of why the integration tests are laid out like this.
//
// TL;DR single mod makes integration tests faster to compile, test, and with
// less build artifacts.
mod file_integeration_test;
mod parser_integration_tests;