Skip to content

Commit

Permalink
fix: Fixes missing destinations crashing (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman committed Apr 7, 2024
1 parent 6c07673 commit d115716
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 127 deletions.
190 changes: 95 additions & 95 deletions Projects/Server.Tests/Tests/Utility/StringHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,133 +2,133 @@
using System.Collections.Generic;
using Xunit;

namespace Server.Tests
namespace Server.Tests;

[Collection("Sequential Tests")]
public class TestStringHelpers
{
public class TestStringHelpers
[Theory]
[InlineData(null, "default value", "default value")]
[InlineData("", "default value", "default value")]
[InlineData("this is a valid string", "default value", "this is a valid string")]
public void TestIsNullOrDefault(string value, string defaultValue, string expected)
{
[Theory]
[InlineData(null, "default value", "default value")]
[InlineData("", "default value", "default value")]
[InlineData("this is a valid string", "default value", "this is a valid string")]
public void TestIsNullOrDefault(string value, string defaultValue, string expected)
{
var actual = value.DefaultIfNullOrEmpty(defaultValue);
var actual = value.DefaultIfNullOrEmpty(defaultValue);

Assert.Equal(expected, actual);
}
Assert.Equal(expected, actual);
}

[Theory]
[InlineData("this is not capitalized", "This Is Not Capitalized")]
[InlineData("", "")]
[InlineData(null, null)]
[InlineData("nospaceshere", "Nospaceshere")]
[InlineData("harry the fireman", "Harry the Fireman")]
public void TestCapitalize(string original, string capitalized)
{
var actual = original.Capitalize();
[Theory]
[InlineData("this is not capitalized", "This Is Not Capitalized")]
[InlineData("", "")]
[InlineData(null, null)]
[InlineData("nospaceshere", "Nospaceshere")]
[InlineData("harry the fireman", "Harry the Fireman")]
public void TestCapitalize(string original, string capitalized)
{
var actual = original.Capitalize();

Assert.Equal(capitalized, actual);
}
Assert.Equal(capitalized, actual);
}

[Theory]
[InlineData("we are testing removing spaces", " ", "wearetestingremovingspaces", StringComparison.Ordinal)]
[InlineData("", " ", "", StringComparison.Ordinal)]
[InlineData(null, null, null, StringComparison.Ordinal)]
public void TestRemove(string original, string separator, string removed, StringComparison comparison)
{
var actual = original.AsSpan().Remove(separator, comparison);
[Theory]
[InlineData("we are testing removing spaces", " ", "wearetestingremovingspaces", StringComparison.Ordinal)]
[InlineData("", " ", "", StringComparison.Ordinal)]
[InlineData(null, null, null, StringComparison.Ordinal)]
public void TestRemove(string original, string separator, string removed, StringComparison comparison)
{
var actual = original.AsSpan().Remove(separator, comparison);

Assert.Equal(removed, actual);
}
Assert.Equal(removed, actual);
}

[Theory]
[InlineData("this is a sentence that will probably wrap around a few times because it is long", 10, 6)]
[InlineData("An Unnamed House", 10, 6)]
[InlineData("Batville", 10, 6)]
[InlineData("Bald's Shop", 10, 6)]
[InlineData(
"Something ThatIsVeryLongAndShouldBe broken up",
10, 6,
"Something", "ThatIsVery", "LongAndSho", "uldBe", "broken up"
)]
public void TestWrap(string sentence, int perLine, int maxLines, params string[] customExpected)
{
var expected = customExpected.Length > 0
? customExpected
: OldWrap(sentence, perLine, maxLines).ToArray();
var actual = sentence.Wrap(perLine, maxLines).ToArray();
[Theory]
[InlineData("this is a sentence that will probably wrap around a few times because it is long", 10, 6)]
[InlineData("An Unnamed House", 10, 6)]
[InlineData("Batville", 10, 6)]
[InlineData("Bald's Shop", 10, 6)]
[InlineData(
"Something ThatIsVeryLongAndShouldBe broken up",
10, 6,
"Something", "ThatIsVery", "LongAndSho", "uldBe", "broken up"
)]
public void TestWrap(string sentence, int perLine, int maxLines, params string[] customExpected)
{
var expected = customExpected.Length > 0
? customExpected
: OldWrap(sentence, perLine, maxLines).ToArray();
var actual = sentence.Wrap(perLine, maxLines).ToArray();

Assert.Equal(expected, actual);
}

Assert.Equal(expected, actual);
// The old wrap function from HouseGump/HouseGumpAOS
private static List<string> OldWrap(string value, int startIndex, int maxLines)
{
if (value == null || (value = value.Trim()).Length <= 0)
{
return null;
}

// The old wrap function from HouseGump/HouseGumpAOS
private static List<string> OldWrap(string value, int startIndex, int maxLines)
var values = value.Split(' ');
var list = new List<string>();
var current = "";

for (var i = 0; i < values.Length; ++i)
{
if (value == null || (value = value.Trim()).Length <= 0)
{
return null;
}
var val = values[i];

var values = value.Split(' ');
var list = new List<string>();
var current = "";
var v = current.Length == 0 ? val : $"{current} {val}";

for (var i = 0; i < values.Length; ++i)
if (v.Length < startIndex)
{
var val = values[i];

var v = current.Length == 0 ? val : $"{current} {val}";
current = v;
}
else if (v.Length == startIndex)
{
list.Add(v);

if (v.Length < startIndex)
if (list.Count == maxLines)
{
current = v;
return list;
}
else if (v.Length == startIndex)
{
list.Add(v);

if (list.Count == maxLines)
{
return list;
}
current = "";
}
else if (val.Length <= startIndex)
{
list.Add(current);

current = "";
if (list.Count == maxLines)
{
return list;
}
else if (val.Length <= startIndex)

current = val;
}
else
{
while (v.Length >= startIndex)
{
list.Add(current);
list.Add(v[..startIndex]);

if (list.Count == maxLines)
{
return list;
}

current = val;
}
else
{
while (v.Length >= startIndex)
{
list.Add(v[..startIndex]);

if (list.Count == maxLines)
{
return list;
}

v = v[startIndex..];
}

current = v;
v = v[startIndex..];
}
}

if (current.Length > 0)
{
list.Add(current);
current = v;
}
}

return list;
if (current.Length > 0)
{
list.Add(current);
}

return list;
}
}

0 comments on commit d115716

Please sign in to comment.