History

Add a test for multiple sections

Casper Beyer committed 5 years ago

Commit 0ad64381 parent d743ef81 file · +26 −2Browse files

Unified · Split

git-config/src/file/git_config.rs+26−2
@@ -1523,17 +1523,41 @@ mod from_env { · 1522 unmodified lines
15231523 }
15241524
15251525 #[test]
1526− fn one_key_value_pair() {
1526+ fn single_key_value_pair() {
15271527 env::set_var("GIT_CONFIG_COUNT", "1");
15281528 env::set_var("GIT_CONFIG_KEY_0", "core.key");
15291529 env::set_var("GIT_CONFIG_VALUE_0", "value");
15301530
15311531 let config = GitConfig::from_env().unwrap().unwrap();
1532− assert_eq!(config.len(), 1);
15331532 assert_eq!(
15341533 config.get_raw_value("core", None, "key"),
15351534 Ok(Cow::<[u8]>::Borrowed(b"value"))
15361535 );
1536+
1537+ assert_eq!(config.len(), 1);
1538+ }
1539+
1540+ #[test]
1541+ fn multiple_key_value_pairs() {
1542+ env::set_var("GIT_CONFIG_COUNT", "3");
1543+ env::set_var("GIT_CONFIG_KEY_0", "core.a");
1544+ env::set_var("GIT_CONFIG_VALUE_0", "a");
1545+
1546+ env::set_var("GIT_CONFIG_KEY_1", "core.b");
1547+ env::set_var("GIT_CONFIG_VALUE_1", "b");
1548+
1549+ env::set_var("GIT_CONFIG_KEY_2", "core.c");
1550+ env::set_var("GIT_CONFIG_VALUE_2", "c");
1551+
1552+ let config = GitConfig::from_env().unwrap().unwrap();
1553+
1554+ assert_eq!(config.get_raw_value("core", None, "a"), Ok(Cow::<[u8]>::Borrowed(b"a")));
1555+
1556+ assert_eq!(config.get_raw_value("core", None, "b"), Ok(Cow::<[u8]>::Borrowed(b"b")));
1557+
1558+ assert_eq!(config.get_raw_value("core", None, "c"), Ok(Cow::<[u8]>::Borrowed(b"c")));
1559+
1560+ assert_eq!(config.len(), 3);
15371561 }
15381562 }
15391563