pq connection string parsing from other project
This commit is contained in:
parent
9a5feb9d54
commit
d803cd8003
10 changed files with 529 additions and 0 deletions
|
|
@ -0,0 +1,41 @@
|
|||
using pgLabII.PgUtils.ConnectionStrings;
|
||||
|
||||
namespace pgLabII.PgUtils.Tests.ConnectionStrings;
|
||||
|
||||
public class PqConnectionStringParserTests
|
||||
{
|
||||
private readonly UnitTestTokenizer tokenizer = new();
|
||||
|
||||
private const string kw = "ab";
|
||||
private const string val = "cd";
|
||||
|
||||
public PqConnectionStringParserTests()
|
||||
{
|
||||
tokenizer
|
||||
.AddString(kw)
|
||||
.AddEquals()
|
||||
.AddString(val);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Success()
|
||||
{
|
||||
var parser = new PqConnectionStringParser(tokenizer);
|
||||
IDictionary<string, string> output = parser.Parse();
|
||||
|
||||
Assert.Single(output);
|
||||
Assert.True(output.TryGetValue(kw, out string? result));
|
||||
Assert.Equal(val, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StaticParse()
|
||||
{
|
||||
var output = PqConnectionStringParser.Parse("foo=bar");
|
||||
Assert.Single(output);
|
||||
Assert.True(output.TryGetValue("foo", out string? result));
|
||||
Assert.Equal("bar", result);
|
||||
}
|
||||
// There are few tests here as this is a predictive parser and all error handling is done
|
||||
// in the tokenizer
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue