Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Sep 25, 2022
1 parent b27b720 commit a3a352e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 88 deletions.
107 changes: 20 additions & 87 deletions src/Verify/Verifier/InnerVerifier_Inner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,112 +4,45 @@ Task<VerifyResult> VerifyInner(object? root, Func<Task>? cleanup, IEnumerable<Ta
{
var targetList = new List<Target>();

if (TryGetTargetBuilder(root, out var builder))
{
var received = builder.ToString();
targetList.Add(new(VerifierSettings.TxtOrJson, received));
}

targetList.AddRange(GetTargetList(fileTargets));
return RunEngine(root, cleanup, targetList);
}

bool TryGetTargetBuilder(object? target, [NotNullWhen(true)] out StringBuilder? builder)
{
var appends = VerifierSettings.GetJsonAppenders(settings);

var hasAppends = appends.Any();

if (target is null)
if (root is null)
{
if (!hasAppends)
if (hasAppends)
{
builder = null;
return false;
var builder = JsonFormatter.AsJson(null, appends, settings, counter);
var received = builder.ToString();
targetList.Add(new(VerifierSettings.TxtOrJson, received));
}

builder = JsonFormatter.AsJson(null, appends, settings, counter);
return true;
}

builder = JsonFormatter.AsJson(target, appends, settings, counter);

return true;
}

Task<VerifyResult> VerifyInnerString(string root)
{
var target = root;
StringBuilder builder;
var appends = VerifierSettings.GetJsonAppenders(settings);

var hasAppends = appends.Any();

target = target.TrimPreamble();

var extension = VerifierSettings.TxtOrJson;
if (hasAppends)
{
builder = JsonFormatter.AsJson(target, appends, settings, counter);
}
else
{
builder = new(target);
extension = "txt";
ApplyScrubbers.ApplyForExtension("txt", builder, settings);
}

var targetList = new List<Target>
else if (root is string stringRoot)
{
new(extension, builder.ToString())
};

return RunEngine(root, null, targetList);
}

bool TryGetTargetWithAppends(object? target, [NotNullWhen(true)] out object? result)
{
var appends = VerifierSettings.GetJsonAppenders(settings);
stringRoot = stringRoot.TrimPreamble();

var hasAppends = appends.Any();

if (target is null)
{
if (!hasAppends)
if (hasAppends)
{
result = null;
return false;
var builder = JsonFormatter.AsJson(stringRoot, appends, settings, counter);
targetList.Add(new(VerifierSettings.TxtOrJson, builder.ToString()));
}

var infoBuilder = new InfoBuilder();

foreach (var append in appends)
else
{
infoBuilder.Add(append.Name, append.Data);
StringBuilder builder = new(stringRoot);
ApplyScrubbers.ApplyForExtension("txt", builder, settings);
targetList.Add(new("txt", builder.ToString()));
}

result = infoBuilder;
return true;
}
else
{
if (!hasAppends)
{
result = target;
return true;
}

var infoBuilder = new InfoBuilder();
infoBuilder.Add("target", target);

foreach (var append in appends)
{
infoBuilder.Add(append.Name, append.Data);
}
var builder = JsonFormatter.AsJson(root, appends, settings, counter);

result = infoBuilder;
return true;
var received = builder.ToString();
targetList.Add(new(VerifierSettings.TxtOrJson, received));
}

targetList.AddRange(GetTargetList(fileTargets));
return RunEngine(root, cleanup, targetList);
}

IEnumerable<Target> GetTargetList(IEnumerable<Target> targets)
Expand Down
2 changes: 1 addition & 1 deletion src/Verify/Verifier/InnerVerifier_String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public async Task<VerifyResult> VerifyString(Task<string> task)
public Task<VerifyResult> VerifyString(string? value)
{
value = OrEmptyOrNull(value);
return VerifyInnerString(value);
return VerifyInner(value, null, Enumerable.Empty<Target>());
}

public async Task<VerifyResult> VerifyString(Task<string> task, string extension)
Expand Down

0 comments on commit a3a352e

Please sign in to comment.