This repository has been archived on 2021-03-14. You can view files and clone it, but cannot push or open issues or pull requests.
git-config/tests/parser_integration_tests.rs

83 lines
2.1 KiB
Rust
Raw Normal View History

2021-02-18 21:12:59 -08:00
use serde_git_config::parser::{parse_from_str, Event, ParsedSectionHeader, Parser};
use serde_git_config::values::Value;
fn fully_consumed<T>(t: T) -> (&'static str, T) {
("", t)
}
fn section_header(name: &'static str, subname: impl Into<Option<&'static str>>) -> Event<'static> {
Event::SectionHeader(ParsedSectionHeader {
name,
subsection_name: subname.into(),
})
}
fn name(name: &'static str) -> Event<'static> {
Event::Key(name)
}
fn value(value: &'static str) -> Event<'static> {
Event::Value(Value::from_str(value))
}
#[test]
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![
section_header("user", None),
name("email"),
value("code@eddie.sh"),
name("name"),
value("Edward Shen"),
section_header("core", None),
name("autocrlf"),
value("input"),
section_header("push", None),
name("default"),
value("simple"),
section_header("commit", None),
name("gpgsign"),
value("true"),
section_header("gpg", None),
name("program"),
value("gpg"),
section_header("url", "ssh://git@github.com/"),
name("insteadOf"),
2021-02-19 09:08:42 -08:00
value("\"github://\""),
2021-02-18 21:12:59 -08:00
section_header("url", "ssh://git@git.eddie.sh/edward/"),
name("insteadOf"),
2021-02-19 09:08:42 -08:00
value("\"gitea://\""),
2021-02-18 21:12:59 -08:00
section_header("pull", None),
name("ff"),
value("only"),
section_header("init", None),
name("defaultBranch"),
value("master"),
]
);
}