integration tests for value extraction
This commit is contained in:
parent
e9598831cc
commit
5574ec3267
4 changed files with 85 additions and 23 deletions
|
@ -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() {
|
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 {
|
||||||
value: i64,
|
pub value: i64,
|
||||||
suffix: Option<IntegerSuffix>,
|
pub suffix: Option<IntegerSuffix>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Integer {
|
impl Display for Integer {
|
||||||
|
@ -599,26 +599,9 @@ 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 {
|
||||||
foreground: Option<ColorValue>,
|
pub foreground: Option<ColorValue>,
|
||||||
background: Option<ColorValue>,
|
pub background: Option<ColorValue>,
|
||||||
attributes: Vec<ColorAttribute>,
|
pub 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 {
|
||||||
|
|
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