-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathLinuxConfigParserTests.cs
57 lines (51 loc) · 2.27 KB
/
LinuxConfigParserTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Collections.Generic;
using GitCredentialManager.Interop.Linux;
using GitCredentialManager.Tests.Objects;
using Xunit;
namespace GitCredentialManager.Tests.Interop.Linux;
public class LinuxConfigParserTests
{
[Fact]
public void LinuxConfigParser_Parse()
{
const string contents =
"""
#
# This is a config file complete with comments
# and empty..
# lines, as well as lines with..
#
# only whitespace (like above ^), and..
invalid lines like this one, not a comment
# Here's the first real properties:
core.overrideMe=This is the first config value
baz.specialChars=I contain special chars like = in my value # this is a comment
# and let's have with a comment that also contains a = in side
#
core.overrideMe=This is the second config value
bar.scope.foo=123456
core.overrideMe=This is the correct value
###### comments that start ## with whitespace and extra ## inside
strings.one="here we have a dq string"
strings.two='here we have a sq string'
strings.three= 'here we have another sq string' # have another sq string
strings.four="this has 'nested quotes' inside"
strings.five='mixed "quotes" the other way around'
strings.six='this has an \'escaped\' set of quotes'
""";
var expected = new Dictionary<string, string>
{
["core.overrideMe"] = "This is the correct value",
["bar.scope.foo"] = "123456",
["baz.specialChars"] = "I contain special chars like = in my value",
["strings.one"] = "here we have a dq string",
["strings.two"] = "here we have a sq string",
["strings.three"] = "here we have another sq string",
["strings.four"] = "this has 'nested quotes' inside",
["strings.five"] = "mixed \"quotes\" the other way around",
["strings.six"] = "this has an \\'escaped\\' set of quotes",
};
var parser = new LinuxConfigParser(new NullTrace());
Assert.Equal(expected, parser.Parse(contents));
}
}