2021-02-19 16:18:02 -08:00
|
|
|
use serde_git_config::parser::{parse_from_str, Event, ParsedSectionHeader};
|
2021-02-18 21:12:59 -08:00
|
|
|
use serde_git_config::values::Value;
|
|
|
|
|
|
|
|
fn fully_consumed<T>(t: T) -> (&'static str, T) {
|
|
|
|
("", t)
|
|
|
|
}
|
|
|
|
|
2021-02-19 16:18:02 -08:00
|
|
|
fn gen_section_header(
|
|
|
|
name: &str,
|
|
|
|
subsection: impl Into<Option<(&'static str, &'static str)>>,
|
|
|
|
) -> Event<'_> {
|
|
|
|
Event::SectionHeader(
|
|
|
|
if let Some((separator, subsection_name)) = subsection.into() {
|
|
|
|
ParsedSectionHeader {
|
|
|
|
name,
|
|
|
|
separator: Some(separator),
|
|
|
|
subsection_name: Some(subsection_name),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ParsedSectionHeader {
|
|
|
|
name,
|
|
|
|
separator: None,
|
|
|
|
subsection_name: None,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2021-02-18 21:12:59 -08:00
|
|
|
}
|
|
|
|
fn name(name: &'static str) -> Event<'static> {
|
|
|
|
Event::Key(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn value(value: &'static str) -> Event<'static> {
|
|
|
|
Event::Value(Value::from_str(value))
|
|
|
|
}
|
|
|
|
|
2021-02-19 16:18:02 -08:00
|
|
|
fn newline() -> Event<'static> {
|
|
|
|
Event::Newline("\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn whitespace(value: &'static str) -> Event<'static> {
|
|
|
|
Event::Whitespace(value)
|
|
|
|
}
|
|
|
|
|
2021-02-18 21:12:59 -08:00
|
|
|
#[test]
|
2021-02-19 16:18:02 -08:00
|
|
|
#[rustfmt::skip]
|
2021-02-18 21:12:59 -08:00
|
|
|
fn personal_config() {
|
|
|
|
let config = r#"[user]
|
|
|
|
email = code@eddie.sh
|
|
|
|
name = Edward Shen
|
|
|
|
[core]
|
|
|
|
autocrlf = input
|
|
|
|
[push]
|
|
|
|
default = simple
|
|
|
|
[commit]
|
|
|
|
gpgsign = true
|
|
|
|
[gpg]
|
|
|
|
program = gpg
|
|
|
|
[url "ssh://git@github.com/"]
|
|
|
|
insteadOf = "github://"
|
|
|
|
[url "ssh://git@git.eddie.sh/edward/"]
|
|
|
|
insteadOf = "gitea://"
|
|
|
|
[pull]
|
|
|
|
ff = only
|
|
|
|
[init]
|
|
|
|
defaultBranch = master"#;
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
parse_from_str(config)
|
|
|
|
.unwrap()
|
|
|
|
.into_iter()
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
vec![
|
2021-02-19 16:18:02 -08:00
|
|
|
gen_section_header("user", None),
|
|
|
|
newline(),
|
|
|
|
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
name("email"),
|
2021-02-19 16:18:02 -08:00
|
|
|
whitespace(" "),
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
value("code@eddie.sh"),
|
2021-02-19 16:18:02 -08:00
|
|
|
newline(),
|
|
|
|
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
name("name"),
|
2021-02-19 16:18:02 -08:00
|
|
|
whitespace(" "),
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
value("Edward Shen"),
|
2021-02-19 16:18:02 -08:00
|
|
|
newline(),
|
|
|
|
|
|
|
|
gen_section_header("core", None),
|
|
|
|
newline(),
|
|
|
|
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
name("autocrlf"),
|
2021-02-19 16:18:02 -08:00
|
|
|
whitespace(" "),
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
value("input"),
|
2021-02-19 16:18:02 -08:00
|
|
|
newline(),
|
|
|
|
|
|
|
|
gen_section_header("push", None),
|
|
|
|
newline(),
|
|
|
|
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
name("default"),
|
2021-02-19 16:18:02 -08:00
|
|
|
whitespace(" "),
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
value("simple"),
|
2021-02-19 16:18:02 -08:00
|
|
|
newline(),
|
|
|
|
|
|
|
|
gen_section_header("commit", None),
|
|
|
|
newline(),
|
|
|
|
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
name("gpgsign"),
|
2021-02-19 16:18:02 -08:00
|
|
|
whitespace(" "),
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
value("true"),
|
2021-02-19 16:18:02 -08:00
|
|
|
newline(),
|
|
|
|
|
|
|
|
gen_section_header("gpg", None),
|
|
|
|
newline(),
|
|
|
|
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
name("program"),
|
2021-02-19 16:18:02 -08:00
|
|
|
whitespace(" "),
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
value("gpg"),
|
2021-02-19 16:18:02 -08:00
|
|
|
newline(),
|
|
|
|
|
|
|
|
gen_section_header("url", (" ", "ssh://git@github.com/")),
|
|
|
|
newline(),
|
|
|
|
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
name("insteadOf"),
|
2021-02-19 16:18:02 -08:00
|
|
|
whitespace(" "),
|
|
|
|
whitespace(" "),
|
2021-02-19 09:08:42 -08:00
|
|
|
value("\"github://\""),
|
2021-02-19 16:18:02 -08:00
|
|
|
newline(),
|
|
|
|
|
|
|
|
gen_section_header("url", (" ", "ssh://git@git.eddie.sh/edward/")),
|
|
|
|
newline(),
|
|
|
|
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
name("insteadOf"),
|
2021-02-19 16:18:02 -08:00
|
|
|
whitespace(" "),
|
|
|
|
whitespace(" "),
|
2021-02-19 09:08:42 -08:00
|
|
|
value("\"gitea://\""),
|
2021-02-19 16:18:02 -08:00
|
|
|
newline(),
|
|
|
|
|
|
|
|
gen_section_header("pull", None),
|
|
|
|
newline(),
|
|
|
|
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
name("ff"),
|
2021-02-19 16:18:02 -08:00
|
|
|
whitespace(" "),
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
value("only"),
|
2021-02-19 16:18:02 -08:00
|
|
|
newline(),
|
|
|
|
|
|
|
|
gen_section_header("init", None),
|
|
|
|
newline(),
|
|
|
|
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
name("defaultBranch"),
|
2021-02-19 16:18:02 -08:00
|
|
|
whitespace(" "),
|
|
|
|
whitespace(" "),
|
2021-02-18 21:12:59 -08:00
|
|
|
value("master"),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|