Compare commits
2 commits
cd2f58c920
...
5574ec3267
Author | SHA1 | Date | |
---|---|---|---|
5574ec3267 | |||
e9598831cc |
5 changed files with 86 additions and 25 deletions
|
@ -97,8 +97,7 @@ impl MutableValue<'_, '_, '_> {
|
|||
/// the Value event(s) are replaced with a single new event containing the
|
||||
/// new value.
|
||||
pub fn set_bytes(&mut self, input: Vec<u8>) {
|
||||
self.section.drain(self.index..self.size);
|
||||
|
||||
self.section.drain(self.index..self.index + self.size);
|
||||
self.size = 1;
|
||||
self.section
|
||||
.insert(self.index, Event::Value(Cow::Owned(input)));
|
||||
|
|
|
@ -111,7 +111,7 @@ pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
|
|||
}
|
||||
}
|
||||
|
||||
owned.extend(dbg!(&input[last_index..]));
|
||||
owned.extend(&input[last_index..]);
|
||||
if owned.is_empty() {
|
||||
input
|
||||
} else {
|
||||
|
@ -431,8 +431,8 @@ impl Serialize for TrueVariant<'_> {
|
|||
/// [`bitwise_offset`]: IntegerSuffix::bitwise_offset
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
|
||||
pub struct Integer {
|
||||
value: i64,
|
||||
suffix: Option<IntegerSuffix>,
|
||||
pub value: i64,
|
||||
pub suffix: Option<IntegerSuffix>,
|
||||
}
|
||||
|
||||
impl Display for Integer {
|
||||
|
@ -599,26 +599,9 @@ impl TryFrom<Vec<u8>> for IntegerSuffix {
|
|||
/// foreground or background color.
|
||||
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
|
||||
pub struct Color {
|
||||
foreground: Option<ColorValue>,
|
||||
background: Option<ColorValue>,
|
||||
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
|
||||
}
|
||||
pub foreground: Option<ColorValue>,
|
||||
pub background: Option<ColorValue>,
|
||||
pub attributes: Vec<ColorAttribute>,
|
||||
}
|
||||
|
||||
impl Display for Color {
|
||||
|
|
71
tests/integration_tests/file_integeration_test.rs
Normal file
71
tests/integration_tests/file_integeration_test.rs
Normal file
|
@ -0,0 +1,71 @@
|
|||
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(())
|
||||
}
|
8
tests/integration_tests/main.rs
Normal file
8
tests/integration_tests/main.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
// 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;
|
Reference in a new issue