49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using FluentResults;
|
|
using pgLabII.PgUtils.ConnectionStrings;
|
|
using pgLabII.PgUtils.Tests.ConnectionStrings.Util;
|
|
|
|
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)
|
|
.AddEof();
|
|
}
|
|
|
|
[Fact]
|
|
public void Success()
|
|
{
|
|
var parser = new PqConnectionStringParser(tokenizer);
|
|
Result<IDictionary<string, string>> output = parser.Parse();
|
|
ResultAssert.Success(output, v =>
|
|
{
|
|
Assert.Single(v);
|
|
Assert.True(v.TryGetValue(kw, out string? result));
|
|
Assert.Equal(val, result);
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void StaticParse()
|
|
{
|
|
Result<IDictionary<string, string>> output = PqConnectionStringParser.Parse("foo=bar");
|
|
ResultAssert.Success(output, v =>
|
|
{
|
|
Assert.Single(v);
|
|
Assert.True(v.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
|
|
}
|