Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Oct 1, 2024
1 parent af1fa7d commit d84a718
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@ namespace RouteLink.Generators.Tests
public static string Edit(string id)
{
string?[] segments = ["client", id];

var length = 0;
for (int i = 0; i < segments.Length; i++)
{
var segment = segments[i];
length += segment != null ? segment.Length + 1 : 0;
}

return string.Create(length, segments, CreateLink);

static void CreateLink(global::System.Span<char> buffer, string?[] segments)
static void CreateLink(global::System.Span<char> buffer, string?[] parts)
{
var position = 0;
for (int i = 0; i < segments.Length; i++)
for (int i = 0; i < parts.Length; i++)
{
if (segments[i] == null)
if (parts[i] == null)
continue;

buffer[position++] = '/';

var span = global::System.MemoryExtensions.AsSpan(segments[i]);
var span = global::System.MemoryExtensions.AsSpan(parts[i]);
span.CopyTo(buffer[position..]);

position += span.Length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,32 @@ namespace RouteLink.Generators.Tests
public static string FacilityEdit(int clientId, int facilityId)
{
string?[] segments = ["client", clientId.ToString(), "facilities", facilityId.ToString()];
var length = RouteLink.Generators.Tests.Routes.ComputeLength(segments);
return string.Create(length, segments, RouteLink.Generators.Tests.Routes.CreateLink);

var length = 0;
for (int i = 0; i < segments.Length; i++)
{
var segment = segments[i];
length += segment != null ? segment.Length + 1 : 0;
}

return string.Create(length, segments, CreateLink);

static void CreateLink(global::System.Span<char> buffer, string?[] parts)
{
var position = 0;
for (int i = 0; i < parts.Length; i++)
{
if (parts[i] == null)
continue;

buffer[position++] = '/';

var span = global::System.MemoryExtensions.AsSpan(parts[i]);
span.CopyTo(buffer[position..]);

position += span.Length;
}
}
}
}
}
Expand Down

0 comments on commit d84a718

Please sign in to comment.